-
March 29th, 2011, 11:51 AM
#1
Getting focused window in OnActivate?
Hello all -
I have a dialog that handles the WM_ACTIVATE message to know when it's deactivated for another window. The 'pWndOther' parameter of OnActivate indicates the window being activated, however I have a need to know what window will receive the input focus at this time. This window could be a child control on the window being activated. Calling CWnd::GetFocus in my dialog's OnActivate handler returns the window with the current focus, but I want the window that is GOING to get the focus. Is there any way to do this? Thanks in advance!
-
March 31st, 2011, 03:20 AM
#2
Re: Getting focused window in OnActivate?
Hi,
did you check the pWndOther parameter in your OnActivate implementation?
MSDN says:
afx_msg void OnActivate( UINT nState, CWnd* pWndOther, BOOL bMinimized );
Parameters
...
pWndOther
Pointer to the CWnd being activated or deactivated. The pointer can be NULL, and it may be temporary.
With regards
Programartist
-
April 1st, 2011, 12:45 PM
#3
Re: Getting focused window in OnActivate?
Yes I did. Unfortunately that points to the window being activated, not necessarily the window getting the input focus.
For example, I have a CFormView-derived class in my frame. Clicking on a control will display a modeless dialog. I have a requirement that says the dialog should go away if it's deactivated except when focus is put into certain controls in my form view. So when my dialog gets the OnActivated message, the 'pWndOther' is pointing to my frame (because that's the window being activated), but I want to know what control in the view is getting the focus. If the dialog is up and the user clicks inside an edit control, then the dialog will be deactivated with the frame being the new active window. I don't see a way, however, to know what control is getting the focus.
I even tried to do a PeekMessage call on the window with the current focus looking for a WM_KILLFOCUS message (since in that message is the pointer to the new window receiving the focus). But at this point, the window with the current focus doesn't have this message in its queue.
-
April 1st, 2011, 01:05 PM
#4
Re: Getting focused window in OnActivate?
Originally Posted by sjc
Yes I did. Unfortunately that points to the window being activated, not necessarily the window getting the input focus.
Yes, it is by design! From MSDN:
The WM_ACTIVATE message is sent to both the window being activated and the window being deactivated. If the windows use the same input queue, the message is sent synchronously, first to the window procedure of the top-level window being deactivated, then to the window procedure of the top-level window being activated. If the windows use different input queues, the message is sent asynchronously, so the window is activated immediately.
...
Remarks
If the window is being activated and is not minimized, the DefWindowProc function sets the keyboard focus to the window...
Victor Nijegorodov
-
April 1st, 2011, 01:41 PM
#5
Re: Getting focused window in OnActivate?
I know it's by design, and I don't have an issue with that (I'm not suggesting that the window passed in the WM_ACTIVATE message is wrong). In my case however, I need to know what window will become focused after my dialog is deactivated. There doesn't appear to be a way to determine that though.
-
April 1st, 2011, 01:54 PM
#6
Re: Getting focused window in OnActivate?
Well, MSDN states it very clear:
f the window is being activated and is not minimized, the DefWindowProc function sets the keyboard focus to the window...
So, the window being activated gets the focus. Period.
Of course it can then set focus to some of its child windows (for example using SetFocus or in case of MFC dialog CDialog::GotoDlgCtrl), but it is up to this window itself.
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|