Sign in to follow this  

win32: hitting escape to exit while focused in a edit box

This topic is 4858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.
		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;

Share this post


Link to post
Share on other sites
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)

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

Share this post


Link to post
Share on other sites

This topic is 4858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this