I'm having a problem with a program that I've been working on. There is a tab control on the main window, with all of the controls on the various tabs grouped on groupboxes. All the controls within each groupbox are created via a call to CreateWindowEx with the handle to it's groupbox as the hHwndParent. This is just so that I could quickly (quickly meaning less code) show or hide all of those controls by showing or hiding the groupbox. The problem is that the buttons wouldn't respond to WM_COMMAND filtering in the main message loop. So I subclassed one of the buttons and it still won't fire a WM_COMMAND when pressed.

The tab control and groupbox controls use the main window handle as their hHwndParent. Only the controls within each groupbox use anything other than the main window handle for that.

If I change the hHwndParent of one of the buttons to the main window handle it fires a WM_COMMAND in the main msg loop. Keeping the hWndParent as the main window handle, and then subclassing the button it won't fire a WM_COMMAND. So this leads me to believe that subclassed buttons won't get this message. If I trap for WM_LBUTTONUP in the subclass msg loop instead it works fine.

So long story short, am I right to assume that subclassed buttons won't receive WM_COMMAND messages?
Posted on 2003-04-01 17:31:05 by Will
The parent of the buttons is I assume the Tab control so all the button messages are going to the Tab control and not your main window, subclass the Tab control and relay all WM_COMMAND messages to the main window. This is just a guess but it might be the solution.

The WM_COMMAND message is sent by the button to it's parent so it can never recieve it unless it has a button or menu as a child which is unlikely.
The WM_COMMAND message is sent when the user selects a command item from a menu, when a control sends a notification message to its parent window, or when an accelerator keystroke is translated.
Posted on 2003-04-01 17:40:33 by donkey
The parents of the buttons are the groupboxes that they are grouped in, so that I can hide/show them with a single line of code as the tab selection changes. The button is subclassed and works fine with the exception that the WM_COMMAND filter in the sublcassed wndproc never fires when that button is pressed. If I change the WM_COMMAND filter to trap WM_LBUTTONUP messages instead it works fine. That tells me that the subclassing is done properly, and it also tells me that the WM_COMMAND message is not sent to the subclassed wndproc. I was just looking for clarification on that (the WM_COMMAND message). I suppose I could've subclassed the groupbox instead and then process the child control messages in one wndproc instead of subclassing each button individually. Hell, I've only typed the code to subclass one button so far just to test my theories so I may just do that instead. I don't know why I didn't think of that before.

I apologize if my terminology wasn't accurate as far as the button not receiving the WM_COMMAND. What I had meant was that the subclassed wndproc didn't receive the message. At this point I don't really need clarification as to the WM_COMMAND message not being sent to subclassed buttons' wndproc. I'll just accept it on good faith.

thanks for your help,
Posted on 2003-04-01 17:54:29 by Will
I'm sorry I thought that the buttons were children of the Tab control. IMO you will have to subclass the groupbox in order to see the WM_COMMAND message.
Posted on 2003-04-01 18:00:18 by donkey
You're absolutely right. I just tested that and came back to post the results, but you beat me to it. :)

By subclassing the groupbox, the child buttons do send a WM_COMMAND to the groupbox's subclassed wndproc. That works great, and I can have one wndproc for the groupbox and all of its child controls.

thanks again,

edit: I still think it's strange that subclassed buttons don't send a WM_COMMAND though. Yeah microsoft.
Posted on 2003-04-01 18:20:08 by Will