Link to home
Start Free TrialLog in
Avatar of sachelis
sachelis

asked on

Not receiving WM_KILLFOCUS in modeless dialog

My MFC app has a modeless dialog. I'd like to know when the user clicks outside of the dialog (at which time I'll hide, but not destroy, the dialog). I'm not receiving the WM_KILLFOCUS message.

I used the ClassWizard to handle the WM_KILLFOCUS message. It correctly added the ON_WM_KILLFOCUS() message map and handler function. However, when I click outside the dialog (and the dialog shading clearly changes to show that it no longer has the focus), OnKillFocus() isn't called. When I click an OK button in the dialog (which calls CDialog::OnOK();), OnKillFocus() is called.
Avatar of jkr
jkr
Flag of Germany image

Can you try Spy++ (http://msdn.microsoft.com/en-us/library/dd460756.aspx) to verify that the message is actually being sent?
Avatar of sachelis
sachelis

ASKER

Using Spy++, I only receive the Set/Kill focus messages when OnOK() and OnCancel() are called, not when the dialog simply gains/loses the focus via mouse clicks. I haven't drilled into OnOK/Cancel to see what actually results in the message being sent.
ASKER CERTIFIED SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Truely outstanding. Zoppo didn't bog down into "why do you want to do that?" which often occurs, but instead explained why my approach wasn't working and provided an easy to implement solution. Thanks!
:o)

thanks, nice to get such a feedback ...