Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WM_SETFOCUS message

Status
Not open for further replies.

noodles1

Programmer
Oct 31, 2001
58
0
0
I have a simple dialog-based application using MFC.

I have the need to perform some specific actions when the application gains focus. I expect that the logical way to do this would be to override the OnSetFocus method that is called when a WM_SETFOCUS message is sent to the app.

I'm using VC++ 6.0 SP3.

I'm a little puzzled as to why the WM_SETFOCUS message does not appear in ClassWizard for my dialog class. To get around this, I can manually add the necessary defintions to the MESSAGE_MAP for WM_SETFOCUS and my dialog-class specific implementation of OnSetFocus.

This appears to work satisifactorily, meaning that my override method is called when the dialog gains focus from a Minimised state. However, when the dialog gains focus, either through Alt-Tab or when brought to the foreground from a non-Minimised state, the override OnSetFocus method does appear to be called. I'm guessing here that a different message is sent in these circumstances.

Can anyone provide any suggestions, firstly as to why the WM_SETFOCUS message does not appear in ClassWizard, and what message is being sent?


 
It appears as though the WM_SETFOCUS message only applies to the Window and not the Dialog.

A handler for this message can be added to the class via the Context Menu in ClassView, provided that the filter is changed from the Dialog to Window.
 
I had the same problem and used the same work-around. This could be a Microsoft bug.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top