Good morning, I would like to know how to use double linked lists in Winapi, more specifically, where to initialize the list? and within the CALLBACK, how to use the list? (or simply by declaring it in the right place can it be used without problems?) I currently use Visual Studio 2015.
In MsgDlgProc there are only buttons to go to the other windows.
In MsgDlg2Proc, there is 3 Listbox to show the data of the list and a button to return to the window 1. To show the information I intend to use if I can get direct "name" from the linked list
SendDlgItemMessage(hDlg, IDC_LIST1, LB_ADDSTRING, NULL, (LPARAM)nombre);
In MsgDlg3Proc, there are 2 EditControl to receive the data and a button to save them in the list and empty the Editbox and a button to cancel
Here the code:
HWND hDlg;
HINSTANCE ghDlg;
struct registro {
registro *sig;
int folio; //char en statictext ---> int en lista
char nombre[70];
int edad;//char en editcontrol ---> int en lista
registro *ant;
};
BOOL CALLBACK MsgDlgProc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK MsgDlg2Proc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK MsgDlg3Proc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK MsgDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG:
return true;
case WM_COMMAND: {
switch (LOWORD(wParam)) {
case IDC_BUTTON1: {
ShowWindow(hDlg, SW_HIDE);
DialogBox(ghDlg, MAKEINTRESOURCE(IDD_DIALOG3), 0, MsgDlg3Proc);
}
break;
case IDC_BUTTON2: {
ShowWindow(hDlg, SW_HIDE);
DialogBox(ghDlg, MAKEINTRESOURCE(IDD_DIALOG2), 0, MsgDlg2Proc);
}
break;
}
return false;
}
break;
case WM_CLOSE:
DestroyWindow(hDlg);
return true;
case WM_DESTROY:
PostQuitMessage(0);
return true;
}
return false;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR cmdLine, int showCmd) {
hDlg = CreateDialog(ghDlg, MAKEINTRESOURCE(IDD_DIALOG1), 0, MsgDlgProc);
ShowWindow(hDlg, showCmd);
MSG msg;
ZeroMemory(&msg, sizeof(MSG));
while (GetMessage(&msg, 0, 0, 0)) {
if (hDlg == 0 || !IsDialogMessage(hDlg, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int)msg.wParam;
}
BOOL CALLBACK MsgDlg2Proc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG:
return true;
case WM_COMMAND: {
switch (LOWORD(wParam)) {
case IDC_BUTTON1: {
ShowWindow(hDlg, SW_HIDE);
DialogBox(ghDlg, MAKEINTRESOURCE(IDD_DIALOG1), 0, MsgDlgProc);
}
break;
}
return false;
}
break;
case WM_CLOSE:
DestroyWindow(hDlg);
return true;
case WM_DESTROY:
PostQuitMessage(0);
return true;
}
return false;
}
BOOL CALLBACK MsgDlg3Proc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG:
return true;
case WM_COMMAND: {
switch (LOWORD(wParam)) {
case IDC_BUTTON1: {
}
break;
case IDC_BUTTON2: {
ShowWindow(hDlg, SW_HIDE);
DialogBox(ghDlg, MAKEINTRESOURCE(IDD_DIALOG1), 0, MsgDlgProc);
}
break;
}
return false;
}
break;
case WM_CLOSE:
DestroyWindow(hDlg);
return true;
case WM_DESTROY:
PostQuitMessage(0);
return true;
}
return false;
}
Thanks