PreTranslateMessage and WM_SETFOCUS
-
I have an MFC app and I'd like to get notified whenever a any of several possible child windows recv focus. I thought I could just override the main window's PreTranslateMessage() function and simply check the pMsg->message value and if it's a WM_SETFOCUS and the pMsg->hWnd is one of the windows I care about then react accordingly. However I never get ANY WM_SETFOCUS messages! Am I misunderstanding how PreTranslateMessage is supposed to be used or is there an alternate approach? I'd prefer not to have to subclass each of the controls, but I will if I have to.
¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!
-
I have an MFC app and I'd like to get notified whenever a any of several possible child windows recv focus. I thought I could just override the main window's PreTranslateMessage() function and simply check the pMsg->message value and if it's a WM_SETFOCUS and the pMsg->hWnd is one of the windows I care about then react accordingly. However I never get ANY WM_SETFOCUS messages! Am I misunderstanding how PreTranslateMessage is supposed to be used or is there an alternate approach? I'd prefer not to have to subclass each of the controls, but I will if I have to.
¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!
AFAIK the WM_* messages are sent to the pMsg->hWnd window. If that window does not handle the message then it is sent to the parent of that window and on up the parent chain until one of the windows actually handles the message (returns TRUE), or the there are no more parent windows. So the only way the main window will get the WM_SETFOCUS message is if none of the child windows handle it, or they return false if they do. See CWnd::WalkPretranslateTree() and AfxInternalPreTranslateMessage() in the MFC sources for more details (Set a breakpoint in your PreTranslateMessage() function and use the call stack)
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
-
I have an MFC app and I'd like to get notified whenever a any of several possible child windows recv focus. I thought I could just override the main window's PreTranslateMessage() function and simply check the pMsg->message value and if it's a WM_SETFOCUS and the pMsg->hWnd is one of the windows I care about then react accordingly. However I never get ANY WM_SETFOCUS messages! Am I misunderstanding how PreTranslateMessage is supposed to be used or is there an alternate approach? I'd prefer not to have to subclass each of the controls, but I will if I have to.
¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!
the problem is not from the way u try to catch the message, but from the message u want to catch, WM_SETFOCUS cound't be caught, I tried to catch it in the simplest window's program. catch this message before TranslateMessage calls, but still, couldn't get it. somebody knows why?
life is like a box of chocolate,you never know what you r going to get.
-
I have an MFC app and I'd like to get notified whenever a any of several possible child windows recv focus. I thought I could just override the main window's PreTranslateMessage() function and simply check the pMsg->message value and if it's a WM_SETFOCUS and the pMsg->hWnd is one of the windows I care about then react accordingly. However I never get ANY WM_SETFOCUS messages! Am I misunderstanding how PreTranslateMessage is supposed to be used or is there an alternate approach? I'd prefer not to have to subclass each of the controls, but I will if I have to.
¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!
Jim, did you get a solution for this without rewriting all your child controls? You may find that setting up a WH_CALLWNDPROC hook is the easiest way to be notified when a window in your app recieves the WM_SETFOCUS message.
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
-
Jim, did you get a solution for this without rewriting all your child controls? You may find that setting up a WH_CALLWNDPROC hook is the easiest way to be notified when a window in your app recieves the WM_SETFOCUS message.
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
No, in the end I just added the OnSetFocus() methods to the various controls. :) Wasn't that big of a deal, just annoying. But then that pretty much sums up MFC development, for me at least :)
¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!