Microsoft KB Archive/74548

{|
 * width="100%"|

HOWTO: Handle WM_CANCELMODE in a Custom Control

 * }

Q74548

-

The information in this article applies to:


 * Microsoft Win32 Software Development Kit (SDK)
 * Microsoft Windows Software Development Kit (SDK) versions 3.0, 3.1

-

SUMMARY
In the Microsoft Windows graphical environment, the WM_CANCELMODE message informs a window that it should cancel any internal state. This message is sent to the window with the focus when a dialog box or a message box is displayed, giving the window the opportunity to cancel states such as mouse capture.

When a control has the focus, it receives a WM_CANCELMODE message when the EnableWindow function disables the control or when a dialog box or a message box is displayed. When a control receives this message, it should cancel modes, such as mouse capture, and delete any timers it has created. A control must cancel these modes because an application may use a notification from the control to display a dialog box or a message box.

The DefWindowProc function processes WM_CANCELMODE by calling the ReleaseCapture function, which cancels the mouse capture for whatever window has the capture. The DefWindowProc function does not cancel any other modes.

MORE INFORMATION
For example, consider a miniature scroll bar custom control that, when it receives a mouse click, sets the mouse capture, creates a timer to provide for repeated scrolling, and sends a WM_VSCROLL message to its parent application. The timer is used to send WM_VSCROLL messages periodically to the parent when the mouse button is held down and the mouse is over the control.

If the application displays a dialog box in response to the WM_VSCROLL message, the control receives a WM_CANCELMODE message, at which time it should kill its timer and release the mouse capture. If the WM_CANCELMODE message is simply passed to the DefWindowProc function, only the mouse capture is released; the timer remains active. When the dialog box is closed, the control immediately sends the parent another WM_VSCROLL message, causing it to display the dialog box again.

Additional query words:

Keywords : kbInput kbOSWinNT kbOSWin2000 kbSDKWin32 kbGrpDSUser kbOSWin kbWndw

Issue type : kbhowto

Technology : kbWin32SDKSearch kbAudDeveloper kbWin3xSearch kbSDKSearch kbWin32sSearch kbWinSDKSearch kbWinSDK300 kbWinSDK310