Since AutoCAD attempts to take focus away from all of its child windows, modeless dialogs have a special requirement. At regular intervals, the modeless dialog will get a WM_ACAD_KEEPFOCUS window message, which is defined in adscodes.h as 1001. When your dialog gets this message, it must return TRUE if it should keep focus. If the response to this message is FALSE (which is also the default), then your dialog box will lose focus as soon as the user moves the mouse pointer off the dialog box's window.
You can do this with the dialog box's message map, and an ON_MESSAGE() declaration such as
BEGIN_MESSAGE_MAP(HelloDlg, CDialog) ON_COMMAND(IDCLOSE, OnClose) ON_COMMAND(IDC_DRAW_CIRCLE, OnDrawCircle) ON_MESSAGE(WM_ACAD_KEEPFOCUS, onAcadKeepFocus) END_MESSAGE_MAP()
In this example, the application's dialog class is HelloDlg, which is derived from CDialog. When you add this entry to the message map, you must also write a handler function for the message. Assume you have written a function called keepTheFocus(), which returns TRUE if your dialog wants to keep the input focus and FALSE if the dialog is willing to yield the focus to AutoCAD. An example message handler is provided here:
afx_msg LONG HelloDlg::onAcadKeepFocus(UINT, LONG) { return keepTheFocus() ? TRUE : FALSE; }