case statement in DLGPROC [SOLVED]
-
LRESULT CALLBACK DlgProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
case WM_INITDIALOG:
return FALSE;
case WM_COMMAND:
return FALSE;
case WM_CLOSE:
return FALSE;
}LRESULT CALLBACK DlgProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
return TRUE;
case WM_CLOSE:
return TRUE;
}LRESULT CALLBACK DlgProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
case WM_INITDIALOG:
break;
case WM_COMMAND:
break;
case WM_CLOSE:
break;
}LRESULT CALLBACK DlgProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
case WM_INITDIALOG:
return 0;
case WM_COMMAND:
return 0;
case WM_CLOSE:
return 0;
}out of these four examples, which one is correct and more accurate, and why.
Some Day I Will Prove MySelf :: GOLD
modified on Sunday, March 6, 2011 12:19 PM
-
LRESULT CALLBACK DlgProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
case WM_INITDIALOG:
return FALSE;
case WM_COMMAND:
return FALSE;
case WM_CLOSE:
return FALSE;
}LRESULT CALLBACK DlgProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
return TRUE;
case WM_CLOSE:
return TRUE;
}LRESULT CALLBACK DlgProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
case WM_INITDIALOG:
break;
case WM_COMMAND:
break;
case WM_CLOSE:
break;
}LRESULT CALLBACK DlgProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
case WM_INITDIALOG:
return 0;
case WM_COMMAND:
return 0;
case WM_CLOSE:
return 0;
}out of these four examples, which one is correct and more accurate, and why.
Some Day I Will Prove MySelf :: GOLD
modified on Sunday, March 6, 2011 12:19 PM
None of them are correct. The message determines what you must do. At the bottom of the
DlgProc
function there would be a call toDefWndProc()
or the original window procedure. Read the MSDN pages for what the return should be. WM_INITDIALOG[^]: "The dialog box procedure should return TRUE to direct the system to set the keyboard focus to the control specified by wParam. Otherwise, it should return FALSE to prevent the system from setting the default keyboard focus." Generally you would break and let the default procedure take care of this, but you can return eitherTRUE
orFALSE
. WM_COMMAND[^]: "If an application processes this message, it should return zero." implies that you should break the switch and call the original procedure if you don't handle it. WM_CLOSE[^]: "If an application processes this message, it should return zero."LRESULT CALLBACK DlgProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
switch (Msg) {
case WM_INITDIALOG:
break; //You can do whatever herecase WM\_COMMAND: switch (LOWORD(wParam)) { case IDC\_MYBUTTON: return 0; //something happened to MYBUTTON } break; //We havn't handled it, use default handler case WM\_CLOSE: //cleanup return 0; } return pOriginalProcedure(hwnd, Msg, wParam, lParam); //This is set as GetWindowLong(GWL\_MSGPROC) before changing the procedure.
}