Jump to content
  • Advertisement
Sign in to follow this  
phil05

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

This topic is 5141 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!