case WM_KEYDOWN:
{
switch (wParam)
{
// If user hits escape on the keyboard, ask user if he/she really wants to quit. If so, exit.
case VK_ESCAPE:
{
if (MessageBox(NULL, "Are you sure you want to exit?", "Exiting Program...",
MB_YESNO | MB_ICONQUESTION) == IDYES)
{
PostQuitMessage(WM_QUIT);
}
else
{
SetFocus(hWndEdit);
return TRUE;
}
}
break;
}
}
break;
win32: hitting escape to exit while focused in a edit box
I can't seem to do the following code while my text editor program is focused on the edit box. There's no way to click outside of it so it doesn't do anything with VK_ESCAPE. I looked all over in a few books to answer this question but I can't find anything. Any help is appreciated.
The problem is that the edit box is processing the WM_KEYDOWN message before your app does.
You've only got one way round this. That is to superclass the edit box control by doing the following (in pseudocode)
Skizz
You've only got one way round this. That is to superclass the edit box control by doing the following (in pseudocode)
WM_INITDIALOG:eb = GetDlgItem (the_edit_box_id);old_proc = GetWindowLong (eb, GWL_WNDPROC);SetWindowLong (eb, GWL_WNDPROC, superclass_proc);WM_DESTROY:eb = GetDlgItem (the_edit_box_id);SetWindowLong (eb, GWL_WNDPROC, old_proc);superclass_proc:if (message == WM_KEYDOWN && key == the_escape_key){ result = pass message to parent window}else{ result = old_proc (proc parameters);}return result;
Skizz
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement