Code Repo    |     RSS
MD's Technical Sharing



Saturday, July 12, 2008

Display a dialog box retrieved from resource

To display a dialog created via Visual Studio Resource editor, use the DialogBox function. Assuming the dialog box resource name is IDD_DIALOG1:

int dlgResult = DialogBox(g_hinstModule, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, (DLGPROC) DlgCallbackProc);

When an event occurs in a dialog box control, the control sends a WM_COMMAND message to the dialog box procedure. The high-order word of the wParam parameter is a notification code, indicating the type of event that occurred. The low-order word of wParam is a constant identifying the control. The lParam parameter is the window handle for the control.

To close the dialog box, call EndDialog. The second parameter of EndDialog will be the return value of the blocking call to DialogBoxW, which is dlgResult in the above code.

BOOL CALLBACK DlgCallbackProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
//occurs when dialog box was initialized

case WM_COMMAND:
//when a control receives action
switch (LOWORD(wParam)) //ID of the control
{
case IDR_MENUITEM1:
//a menu item was pressed. Pass IDR_MENUITEM1 to indicate that the ACCEPT menu has been clicked
EndDialog(hwndDlg, IDR_MENUITEM1);
break;
}

break;
}
return FALSE;
}

g_hinstModule is the handle to the executable containing the resource.

Reference:
http://win32.freetechsecrets.com/WIN32Processing_the_WMCOMMAND_Message.htm

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.