dialog box problem keeps haunting me
hey all,
I am just experimenting as I seem to be having very bad luck with creating dialog boxes with the API.
well, I FINALLY got some code to work that actually displays the dialog box (usually the code will compile fine, but when I execute it there is no sign of the dialog box). :o
here it is:
Code:
#include <windows.h>
#include "resource.h"
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_INITDIALOG:
SetDlgItemText(hwndDlg, IDC_EDIT, "hello there");
return TRUE;
case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;
}
return FALSE;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
return DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG), NULL, (DLGPROC)DialogProc);
}
yes, indeed very simple code. IDC_EDIT is an edit box control on the dialog (obviously). as I said, I figured I'd go real simple with this one since I was having so many troubles with other controls. I was so happy to see that the dialog actually appeared for once.
now here goes my question. on the dialog, there is also an OK (IDOK) button and a Cancel (IDCANCEL) button (by default). now, watch how I handle these button messages:
Code:
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_INITDIALOG:
SetDlgItemText(hwndDlg, IDC_EDIT, "hello there");
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDOK:
EndDialog(hwndDlg, 0);
return TRUE;
case IDCANCEL:
EndDialog(hwndDlg, 0);
return TRUE;
}
case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;
}
return FALSE;
}
looks ok, right? thats what I thought. turns out that when I run this after this very small modification I get another one of those non appearing dialog boxes. lol
could anyone here please tell me what looks wrong with the way I am handling those button messages? I would really like to know what I am doing wrong to keep getting these non appearing dialog boxes (like what can cause behaviour like this? I am sure I'm not the only one here that has had this problem). the program appears to be completing execution, so maybe I am adding a return statement somewhere where I shouldn't be?
any help would be greatly appreciated, this same problem has been bugging me for a while now.
thanks in advance! :D