rev
rev

Reputation: 1861

Win32 API: process WM_* in tab control's wndproc instead of parent's

Currently I have a tab control attached to a main window on my program.

However, when I switch tabs, the WM_NOTIFY messages are sent to the parent of the tab control, not to the tab control itself.

Is there a way to make the tab control's WndProc receive and process those messages instead of the parent?

I'm using the raw win32 C API. No MFC or any kind of libraries

Upvotes: 0

Views: 600

Answers (1)

andlabs
andlabs

Reputation: 11588

You have two options.

1. Subclassing

You can subclass the tab control so you can handle messages there in the first place, then in your parent window have some code like

#define msgNOTIFY (WM_APP + 0x40)
// ...
case WM_NOTIFY:
    return SendMessageW(nm->hwndFrom, msgNOTIFY, wParam, lParam);

which will bounce the WM_NOTIFY back. Same for WM_COMMAND. I used a separate message ID for this redirected WM_NOTIFY/WM_COMMAND to be safe; you might not have to (I don't know for sure). If your controls move between windows, you'll also have to do this from all windows.

2. Use a Middleman

Instead of placing the tab control directly on your window, place it inside another control (preferably one of your own creation, which does nothing but be sized to fit the child) that you place on your window instead, and handle messages there. This has the advantage of avoiding the reparenting issue linked above, but costs a window handle, so I normally don't suggest doing so. It does work, though. And if you do this for your tab pages, switching pages is as easy as hiding one control and showing another! (In fact, this is what property sheets do with their child dialogs.)

Upvotes: 2

Related Questions