Page 209 - DCAP408_WEB_PROGRAMMING
P. 209
Unit 12: Dialog Boxes (II)
window procedure obtains a WM_COMMAND message having the IDM_GOTO menu identifier, Notes
but only if the global variable does not already enclose a valid handle. The second part of the
example is the application’s main message loop. The loop involves the IsDialogMessage function
to make sure that the user can utilize the dialog box keyboard interface in this modeless dialog
box. The third part of the the dialog box procedure. The procedure obtains the contents of the
edit control and check box when the user clicks the OK button. The procedure demolishes the
dialog box when the user clicks the Cancel button.
HWND hwndGoto = NULL; // Window handle of dialog box
...
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDM_GOTO:
if (!IsWindow(hwndGoto))
{
hwndGoto = CreateDialog(hinst,
MAKEINTRESOURCE(DLG_GOTO),
hwnd,
(DLGPROC)GoToProc);
ShowWindow(hwndGoto, SW_SHOW);
}
break;
}
return 0L;
In the former statements, CreateDialog is called only if hwndGoto does not enclose a valid
window handle. This makes sure that the application does not exhibit two dialog boxes at the
same time. To support this method of checking, the dialog procedure must set to NULL when it
demolishes the dialog box.
The message loop for an application includes the following statements:
BOOL bRet;
while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
{
if (bRet == -1)
{
// Handle the error and possibly exit
}
else if (!IsWindow(hwndGoto) || !IsDialogMessage(hwndGoto, &msg))
{
LOVELY PROFESSIONAL UNIVERSITY 203