Reputation: 238
I have "n" dialogs which have the same base dialog. Each dialog has its own controls
In base dialog, how do I set focus messages of each control and,for example, give a Message box with
text("Hello I got focus, my ID is %d")?
Upvotes: 3
Views: 6057
Reputation: 15355
The easiest way is using the classical subclassing method. The problem is that WM_SETFOCUS
is not pumped through the message Loop, so PreTranslateMessage
will not help.
Thee are some nice classes that help to do additional subclassing without disturbing the MFC stuff.
Paul Di Lascia wrote CSubclassWnd
. PJ Naughter wrote CHookWnd
. And with the ATL has CWindowsImpl
.
All this classes allow easy additional subclassing even if a window is already subclassed by the MFC.
You can use "standard subclassing" GetWindowLong
/SetWindowLong
too.
Upvotes: 1
Reputation: 5132
According to this SO article, you can hook the WM_SETFOCUS
message.
You can get the Control ID by using GetDlgCtrlID
with the hwnd
returned by the hook.
But beware of popping up a MessageBox
, that will change the focus and trigger your hook proc, making it go into a loop!
Upvotes: 0
Reputation: 760
As Jerry already said make a hook, get parent window handler via GetParent() and SendMessage(hParentWND, WM_MESSAGE, lParam, wParam).
Of course, you should handle WM_MESSAGE in your parent window.
Btw, framework calls OnSetFocus function when window gained focus.
Upvotes: 0