INT_PTR CALLBACK DialogProc(HWND hDlg,UINT msg,WPARAM wParam, LPARAM lParam)
{static HWND hList2;
char Buff[250];
char charID[50],charAuthor[50],charTitle[50],charGenre[50],charPublishing_House[50],charYear[50];
HWND hEditID=GetDlgItem(hDlg,IDC_EDIT1),
hEditAuthor=GetDlgItem(hDlg,IDC_EDIT2),
hEditTitle=GetDlgItem(hDlg,IDC_EDIT3),
hEditGenre=GetDlgItem(hDlg,IDC_EDIT4),
hEditPublishing_House=GetDlgItem(hDlg,IDC_EDIT5),
hEditYear=GetDlgItem(hDlg,IDC_EDIT6);
switch (msg)
{
case WM_INITDIALOG:
{
ShowWindow(hDlg,SW_SHOW);
UpdateWindow(hDlg);
return TRUE;
}
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BUTTON1:
{
BOOL Flag=TRUE;
LPSTR ERR = new CHAR[512];
ZeroMemory(ERR,sizeof(ERR));
GetWindowText(hEditID,LPTSTR(charID),50);
GetWindowText(hEditAuthor,LPTSTR(charAuthor),50);
GetWindowText(hEditTitle,LPTSTR(charTitle),50);
GetWindowText(hEditGenre,LPTSTR(charGenre),50);
GetWindowText(hEditPublishing_House,LPTSTR(charPublishing_House),50);
GetWindowText(hEditYear,LPTSTR(charYear),50);
if(stackPtr!=NULL && findEl(&stackPtr,atoi(charID),0,0,0,0,0)==1)
{
ZeroMemory(ERR,sizeof(ERR));
strcpy(LPTSTR(ERR),"Item: ");
strcat(LPTSTR(ERR),LPCTSTR(charID));
strcat(LPTSTR(ERR)," is already exist!");
MessageBox(hDlg,ERR,"Message",MB_OK|MB_ICONEXCLAMATION);
}
push(&stackPtr,atoi(charID),charAuthor,charTitle,charGenre,charPublishing_House,atoi(charYear));
ListView_DeleteAllItems(hList);
UpdateWindow(hList);
FillListFromStack(stackPtr);
ShowWindow(hList,SW_SHOW);
UpdateWindow(hList);
SetWindowText(hEditID,LPTSTR(""));
SetWindowText(hEditAuthor,LPTSTR(""));
SetWindowText(hEditTitle,LPTSTR(""));
SetWindowText(hEditGenre,LPTSTR(""));
SetWindowText(hEditPublishing_House,LPTSTR(""));
SetWindowText(hEditYear,LPTSTR(""));
UpdateWindow(hDlg);
}
break;
}
break;
case WM_CLOSE:
DestroyWindow(hDlg);
DialogWindow=NULL;
break;
case WM_DESTROY:
break;
default:
return FALSE;
}
return FALSE;
}
[Visual C++] Передача информации из стека в ListView
Прошу помочь, а то я скоро сойду с ума. Как мне предать информацию их стека в поля ListView? Я делаю это так, но что оно не получается, моежт я чего-то еще не дописала?
MERCI!
Это диалоговое окно которое появляется чтобы добавить элементы
Код:
Это мой стек
Код:
struct stackNode{
int pID;
char pAuthor[50];
char pTitle[50];
char pGenre[50];
char pPublishing_House[50];
int pYear;
struct stackNode *nextPtr;};
typedef struct stackNode STACKNODE;
typedef STACKNODE *STACKNODEPTR;
STACKNODEPTR stackPtr=NULL;
void push(STACKNODEPTR *topPtr,int ptrID, char ptrAuthor[50],char ptrTitle[50],char ptrGenre[50], char ptrPublishing_House[50], int ptrYear)
{
STACKNODEPTR newPtr;
newPtr=(STACKNODE *)malloc(sizeof(STACKNODE));
if(newPtr!=NULL)
{
newPtr->pID=ptrID;
strcpy(LPTSTR(newPtr->pAuthor),LPCTSTR(ptrAuthor));
strcpy(LPTSTR(newPtr->pTitle),LPCTSTR(ptrTitle));
strcpy(LPTSTR(newPtr->pGenre),LPCTSTR(ptrGenre));
strcpy(LPTSTR(newPtr->pPublishing_House),LPCTSTR(ptrPublishing_House));
newPtr->pYear=ptrYear;
newPtr->nextPtr=*topPtr;
*topPtr=newPtr;
}
else
{
MessageBox(NULL,"There are no free memory","Attention!",MB_OK|MB_ICONEXCLAMATION);
}
}
int pID;
char pAuthor[50];
char pTitle[50];
char pGenre[50];
char pPublishing_House[50];
int pYear;
struct stackNode *nextPtr;};
typedef struct stackNode STACKNODE;
typedef STACKNODE *STACKNODEPTR;
STACKNODEPTR stackPtr=NULL;
void push(STACKNODEPTR *topPtr,int ptrID, char ptrAuthor[50],char ptrTitle[50],char ptrGenre[50], char ptrPublishing_House[50], int ptrYear)
{
STACKNODEPTR newPtr;
newPtr=(STACKNODE *)malloc(sizeof(STACKNODE));
if(newPtr!=NULL)
{
newPtr->pID=ptrID;
strcpy(LPTSTR(newPtr->pAuthor),LPCTSTR(ptrAuthor));
strcpy(LPTSTR(newPtr->pTitle),LPCTSTR(ptrTitle));
strcpy(LPTSTR(newPtr->pGenre),LPCTSTR(ptrGenre));
strcpy(LPTSTR(newPtr->pPublishing_House),LPCTSTR(ptrPublishing_House));
newPtr->pYear=ptrYear;
newPtr->nextPtr=*topPtr;
*topPtr=newPtr;
}
else
{
MessageBox(NULL,"There are no free memory","Attention!",MB_OK|MB_ICONEXCLAMATION);
}
}
Это функции добавления записей в ListView
Код:
void AddToListItem(int lpID, char *lpAuthor, char *lpTitle, char *lpGenre, char *lpPublishing_House, int lpYear)
{
char Buff[50],Buff2[50];
LVITEM lvItem;
lvItem.mask=LVIF_TEXT ;
lvItem.iItem=0;
lvItem.iSubItem=0;
itoa(lpID,LPTSTR(Buff),10);
lvItem.pszText=LPTSTR(Buff);
lvItem.cchTextMax=strlen(Buff);
ListView_InsertItem(hList,&lvItem);
lvItem.iSubItem++;
lvItem.pszText=lpAuthor;
lvItem.cchTextMax=strlen(lpAuthor);
ListView_SetItem(hList,&lvItem);
lvItem.iSubItem++;
lvItem.pszText=lpTitle;
lvItem.cchTextMax=strlen(lpTitle);
ListView_SetItem(hList,&lvItem);
lvItem.iSubItem++;
lvItem.pszText=lpGenre;
lvItem.cchTextMax=strlen(lpGenre);
ListView_SetItem(hList,&lvItem);
lvItem.iSubItem++;
lvItem.pszText=lpPublishing_House;
lvItem.cchTextMax=strlen(lpPublishing_House);
ListView_SetItem(hList,&lvItem);
lvItem.iSubItem++;
itoa(lpYear,LPTSTR(Buff2),10);
lvItem.pszText=LPTSTR(Buff2);
lvItem.cchTextMax=strlen(Buff2);
ListView_SetItem(hList,&lvItem);
}
BOOL FillListFromStack(STACKNODEPTR currentPtr)
{
if (!isEmpty(currentPtr))
{
while(currentPtr!=NULL)
{
AddToListItem(currentPtr->pID, currentPtr->pAuthor, currentPtr->pTitle, currentPtr->pGenre, currentPtr->pPublishing_House, currentPtr->pYear);
currentPtr=currentPtr->nextPtr;
return TRUE;
}
}
else
MessageBox(NULL,"List is empty!", "Attention!",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}
{
char Buff[50],Buff2[50];
LVITEM lvItem;
lvItem.mask=LVIF_TEXT ;
lvItem.iItem=0;
lvItem.iSubItem=0;
itoa(lpID,LPTSTR(Buff),10);
lvItem.pszText=LPTSTR(Buff);
lvItem.cchTextMax=strlen(Buff);
ListView_InsertItem(hList,&lvItem);
lvItem.iSubItem++;
lvItem.pszText=lpAuthor;
lvItem.cchTextMax=strlen(lpAuthor);
ListView_SetItem(hList,&lvItem);
lvItem.iSubItem++;
lvItem.pszText=lpTitle;
lvItem.cchTextMax=strlen(lpTitle);
ListView_SetItem(hList,&lvItem);
lvItem.iSubItem++;
lvItem.pszText=lpGenre;
lvItem.cchTextMax=strlen(lpGenre);
ListView_SetItem(hList,&lvItem);
lvItem.iSubItem++;
lvItem.pszText=lpPublishing_House;
lvItem.cchTextMax=strlen(lpPublishing_House);
ListView_SetItem(hList,&lvItem);
lvItem.iSubItem++;
itoa(lpYear,LPTSTR(Buff2),10);
lvItem.pszText=LPTSTR(Buff2);
lvItem.cchTextMax=strlen(Buff2);
ListView_SetItem(hList,&lvItem);
}
BOOL FillListFromStack(STACKNODEPTR currentPtr)
{
if (!isEmpty(currentPtr))
{
while(currentPtr!=NULL)
{
AddToListItem(currentPtr->pID, currentPtr->pAuthor, currentPtr->pTitle, currentPtr->pGenre, currentPtr->pPublishing_House, currentPtr->pYear);
currentPtr=currentPtr->nextPtr;
return TRUE;
}
}
else
MessageBox(NULL,"List is empty!", "Attention!",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}