Get a WM_KEYPRESS message in the parent window

I have a followup question to http://cplusplus.com/forum/windows/78033/.

I have a WIN32 application with one button and a bunch of edit boxes. If I hit VK_RETURN while an edit-box is selected, I want to press the button (or just call the same function that the button calls).

I've stuck a breakpoint in the procedure of my parent window, but regardless of what I press in the edit-box, I don't get a WM_KEYPRESS message. Is there a way to have the default edit-box window relay any unused messages to the parent window?

Likewise, I was having a problem with tabbing from window to window because my Group-box windows wouldn't send unused messages to the parent (I wanted to tab from an edit-box in one group-box to an edit-box in another group-box). I eventually just had to put all of the edit boxes in my parent window, but I'd prefer another solution.

Sorry for two very similar posts. This one is just a little more specific now.
To sort of answer your previous question:
I've had similar issues with TABSTOP in the past. MFC has a simple shortcut of ctrl+d in the resource window which easily allows you to set the tab order. In regular win32, the TABSTOP is determined by the order which the controls are created. Remember that all controls must have a TABSTOP. To modify the z-order, the usual way is to use SetWindowPos like this:

SetWindowPos(NewCtrl, OldCtrl, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);

I'm a little sleepy now to answer the rest. Maybe tomorrow...


I have 1 question tho, when you say tabbing from window to window do you mean from dialog to dialog or from edit box to edit box ?

Last edited on
In the original thread, I had an edit box in one group-box and another edit box in another group box. I could go from one group-box to the other, but it wouldn't go through the edit boxes inside the group box.

Thanks for your response, I look forward to hearing what you have to say about the rest.
In the original thread, I had an edit box in one group-box and another edit box in another group box. I could go from one group-box to the other, but it wouldn't go through the edit boxes inside the group box.

This can all be handled with SetWindowPos since u can specify exactly which control gets focus however u want - including the editboxes within the group since these are also controls. Get a handle to the edit control then use SetWindowPos to change the z order. Windows OS is designed such that all controls must have a tabstop so that their msgs can be registered so those edit boxes r in there too.


I have a WIN32 application with one button and a bunch of edit boxes. If I hit VK_RETURN while an edit-box is selected, I want to press the button (or just call the same function that the button calls).

To clarify, you only have 1 window correct ? Then that window is the parent window and it doesn't make sense to talk about sending unused messages back to the parent window. Does ur parent window create other windows ?

As far as setting focus to a control where u can just press enter after filling edit boxes and what have ya, this should do the trick:
m_btnOK.SetButtonStyle(BS_DEFPUSHBUTTON);
Where m_btnOK is the standard 'OK button' control found in dialogs.
Last edited on
After another 3 days of working on this, I still had problems.

I switched over to Qt Creator and remade my program within 4 hours. It works SOOOOO much better now with TABSTOP working, default pushbuttons being hit when I have my cursor in an edit window and resizing.

The longest part of the endeavor was figuring out the difference between QString and std::string (I've never touched Qt before).

I chatted with a guy at work about porting my C-Win32 application to OOP C++. He said that there are guys working at microsoft that have been working on these problems for 20 years. Their solution is MFC. If I every went back to Win32, I think I'd have to look into MFC.
Last edited on
I find MFC much easier to work with than win32 but that's just me as I like having a solid framework underneath me so that I can focus on the main purpose of an app. I've never tried QT but it sounds like u'r having a similar undertaking I had with figuring out CString and CFile and all those other C's vs STL counterparts. UpdateData is an interesting one too...
GL with ur coding !
Last edited on
Topic archived. No new replies allowed.