HOWTO: Remove Focus from a Control When Mouse Released OutsideID: Q66947
|
Under normal circumstances, when you move the mouse cursor into the client
area of a child-window control, click it, and then release the mouse
button, the child window sends a WM_COMMAND message to its parent and
retains the focus.
If you move the mouse into the client area of the child-window control,
press the mouse button, move the mouse cursor out of the client area of the
control, and then release the mouse button, the control does not send a
WM_COMMAND message. However, the control retains the focus.
If you do not want the control to retain the focus, you can remove it by
performing the following steps:
When the mouse cursor is in the client area of a control and you press the
mouse button, the parent window will receive a WM_PARENTNOTIFY message and
a WM_MOUSEACTIVATE message. A Boolean (BOOL) flag should be set when the
message is processed to indicate that this occurred.
The parent window will receive other messages, including a number of
WM_CTLCOLOR messages, when the mouse is moved around with the mouse button
down. When the mouse button is released, the parent window receives only
one of two messages:
BOOL FAR PASCAL AboutProc(HWND hDlg, unsigned iMessage,
WORD wParam, LONG lParam)
{
static BOOL fMousePress;
switch (iMessage)
{
case WM_INITDIALOG:
fMousePress = FALSE;
return TRUE;
case WM_PARENTNOTIFY: // or WM_MOUSEACTIVATE
fMousePress = TRUE;
break;
case WM_MOUSEMOVE:
if (fMousePress)
SetFocus(NULL);
fMousePress = FALSE;
break;
// Only command is the OK button.
case WM_COMMAND:
if (wParam == IDOK)
EndDialog(hDlg, TRUE);
break;
}
return FALSE;
}
Additional query words: win16sdk
Keywords : kbcode kbCtrl kbNTOS kbGrpUser kbWinOS
Version :
Platform :
Issue type : kbhowto
Last Reviewed: March 6, 1999