Child button listening

Say I have a main window, a static control which is a child of the main window, and a button which is a child of the static control. How do I listen from the main window procedure to a WM_COMMAND that is sent when the child button is pressed?

Because
1
2
HWND hButton;
hButton=CreateWindow(WC_BUTTON,"Button",WS_CHILD|WS_VISIBLE,x,y,w,h,HandleOfStaticControl,(HMENU)BUTTON_ID,hInstance,NULL);

1
2
3
4
...
case WM_COMMAND:
switch(wParam){
case BUTTON_ID:
won't do anything.

Thank you!
Actually, the wParam is in two parts - see here:
http://msdn.microsoft.com/en-us/library/ms647591%28VS.85%29.aspx

Butt even if you decode it correctly, you still won't get what you want
because child windows send notifications to the parent window.
The common controls such as buttons, statics, edit boxes etc.. have their own window procedure
which is provided inside of windows and they only look after themselves.
So making one of these child windows a parent for other child windows won't work normally.

You can either subclass the static window and provide your own window procdure
or
don't make the button a child of the static - just make it a child of the main window (unless you
have a really good reason for making the button a child of the static window);
Last edited on
Well, I need to have a lot of controls grouped together which will appear and dissapear once the static window is shown/hided.
I think providing a separate window procedure for the static control would be easier than manually hiding/showing those child controls. Do I need to create a WNDCLASSEX to do that?
You can create you own window class, register it, and provide a window proecdure for it.
create a window from it (making it a child of the main window) and use it to hold the controls
instead of subclassing the static window.

See what I mean?
Yep. I'll try that. Thanks.
Topic archived. No new replies allowed.