Catching activity outside dialog

I have a modeless dialog that I open up, and the user can then respond to a question by clicking somewhere inside the dialog.  If he clicks anywhere outside the dialog box, in any other window, I want the modeless dialog box to catch this and close down.  How do I do this?  I tried WM_KILLFOCUS but it doesn't seem to work.
Who is Participating?
NorbertConnect With a Mentor Commented:
I Did the same using WM_ACTIVATE:
YourDialogBasedClass::OnActivate(UINT nState, CWnd* pWndOther, BOOL Minimized)
          ShowWindow(SW_HIDE);//I did not close the dialog I only Hide it.
         //don't know your needs may be
and this works great for me
if there are any problems I am sorry to say:
I am going into vacation today so you can reach me today or only next year -
if Internet still works after the change of the milenium :)

but as I said it works great for me so
I don't think that there is a problem.

Normaly inside a dialog one of the controls laying on the dialog has the focus so the dialog does probably not get the killfocus message and if it got it you don't know is the focus killed because one of the dialog childs gets it or because you are clicking outside the dialog brobably with a lot of work it could be done checking each childs killfocus function and may be the position of the mouse or have a look wich window gets the focus now but WM_ACTIVATE is much more elegant and much less to do

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.