This might be a dumb question, but can you register multiple WndProc functions in Win32? e.g. a framework catches some messages and my app is interested in other ones - how do I catch them without modifying the framework code?
Asked
Active
Viewed 5,946 times
5
-
3read up on Windows API "window subclassing" – Cheers and hth. - Alf Sep 24 '11 at 12:32
-
you should make your question concrete enough that it can be answered. e.g. instead of "a framework", name what you're dealing with. intead of "interested in other ones", name them. so on. – Cheers and hth. - Alf Sep 24 '11 at 12:33
-
It is concrete. A framework implements the main message handler inside a black-box, but I want to catch additional messages. Which framework is irrelevant. – Mr. Boy Sep 24 '11 at 18:15
-
no, and no, ok, and no. that's the problem with the question, that you think you know the answers. i'm voting to close now, because you're clearly not going to fix it. – Cheers and hth. - Alf Sep 24 '11 at 21:05
-
2Luckily, SO isn't run my petty people who throw a strop when someone won't kowtow to their every suggestion. Someone was able to _give_ a good answer so your argument is provably wrong. Sometimes when you can't understand a question it means _you_ are not smart enough, not that the question is bad. I doubt _you'd_ ever be modest enough to admit such a point of view though. – Mr. Boy Sep 27 '11 at 11:05
-
yes, no, yes, and meaningless. – Cheers and hth. - Alf Sep 27 '11 at 11:39
-
1Many frameworks provide for this ability. For example, MFC has message maps. Check your framework documentation. – Raymond Chen Jan 12 '12 at 13:32
2 Answers
7
If I understand your intention correctly, you can do that by setting a hook. Assuming you know the thread whose message loop you'd like to hook, you can do something along these lines (unchecked):
SetWindowsHookEx(WH_CALLWNDPROC, yourHOOKPROC, NULL, theThreadId);

Eran
- 21,632
- 6
- 56
- 89
7
You can chain multiple message handling functions by using the function CallWindowProc
instead of DefWindowProc
.
Here is an example:
pfOriginalProc = SetWindowLong( hwnd, GWL_WNDPROC, (long) wndproc1 ); // First WNDPROC
pfOriginalProc2 = SetWindowLong( hwnd, GWL_WNDPROC, (long) wndproc2); // Second WNDPROC, WILL EXECUTE FIRST!!
LRESULT wndproc1( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch ( uMsg )
{
...
default:
return CallWindowProc( pfOriginalProc, hwnd, uMsg, wParam, lParam );
}
}
LRESULT wndproc2( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch ( uMsg )
{
...
default:
return CallWindowProc( pfOriginalProc2, hwnd, uMsg, wParam, lParam );
}
}