HOWTO: Limit Cursor Movement Inside a FormLast reviewed: January 13, 1998Article ID: Q179192 |
The information in this article applies to:
SUMMARYThe ClipCursor API function allows you to limit cursor movement to a predefined area, such as a form. This article includes instructions and sample code to create a project that uses the ClipCursor API function.
MORE INFORMATIONYou might want to limit the cursor movement area if you have drag-and-drop functionality within a form and you only want the user to drag an item inside a form. The ClipCursor function confines the cursor to a rectangular area on the screen. If a subsequent cursor position (set by the SetCursorPos function or the mouse) lies outside the rectangle, Windows automatically adjusts the position to keep the cursor inside the rectangular area. The form borders serve as the rectangular area for the ClipCursor function. To get the size of the form, use the GetClientRect function. This function retrieves the coordinates of a window's client area. The coordinates are relative to the upper-left corner of a window's client area; the coordinates of the upper-left corner are (0,0). This means you will have to convert the client coordinates to screen coordinates. The ClientToScreen function converts the client coordinates of a specified point to screen coordinates. The last function used is the OffsetRect function. The OffsetRect function moves the specified rectangle by the specified offsets. NOTE: If you unload the form after executing the ClipCursor function, the cursor will still be limited to the last coordinates of the now-unloaded form. To prevent this behavior, calling the ClipCursor function with a null argument in the Form_Unload event is recommended. The next section shows you how to create a sample project that uses these functions.
Steps to Create Project
Keywords : vb5all vb5howto VBKBGraphics VBKBWinAPI Version : WINDOWS:5.0 Platform : WINDOWS Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |