Handling the Back Key for Dialog Boxes Without Edit Controls
In a dialog box without edit controls, when a user presses the Back key, the Back key sends a Windows CE WM_COMMAND message to the dialog box with the command ID IDCANCEL. The following code example illustrates how to handle the WM_COMMAND message.
BOOL rb;
int rc;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
// User chooses to close the dialog box by pressing the Back key.
case IDCANCEL: // Handles the Back key.
{
rb = EndDialog(hwnd, 0);
if (rb == FALSE) // EndDialog failed.
{
rc = MessageBox(NULL, _T("Could not destroy dialog box."),
_T("Error"), MB_OK);
if (rc == 0) // Not enough memory to create MessageBox.
return E_OUTOFMEMORY;
return E_FAIL; // Replace with specific error handling.
}
else // EndDialog succeeded.
return S_OK;
} // case IDCANCEL
} // switch
break; // from case WM_COMMAND
}
Send Feedback on this topic to the authors