How to Make Mouse Pointer (Cursor) Maintain Hourglass Shape

Last reviewed: June 21, 1995
Article ID: Q110542
The information in this article applies to:

- Professional and Standard Editions of Microsoft Visual Basic

  Programming System for Windows, versions 2.0 and 3.0

SUMMARY

You can have a Visual Basic application program set the mouse pointer (cursor) to an hour glass shape and wait. However, if the user moves the mouse over another application's window, the cursor will return to a mouse pointer. To force the cursor to maintain the hourglass shape even while over other windows, make the window a system modal window by using the SetSysModalWindow Windows API function.

MORE INFORMATION

Step-by-Step Instructions for Making a System Modal Window

  1. Start Visual Basic, or if Visual Basic is already running, choose New Project from the File menu (ALT, F, N). Form1 is created by default.

  2. Add the following code to the General Declarations section of Form1:

       Declare Function SetSysModalWindow% Lib "User" (ByVal hwnd%)
       Const HourGlass = 11
    
    

  3. Add the following code to the Form_Load event of Form1:

       Sub Form1_Load ()
          Me.Show
          Screen.MousePointer = HourGlass
          ' Remove the following line to see how the mouse behaves without it
          result% = SetSysModalWindow%(form1.hWnd)
       End Sub
    
    

  4. Add the following code to the Form_Click event of Form1:

       Sub Form1_Click ()
          Unload Form1
       End Sub
    
    

  5. Run the program. Click the form to end it. Notice that the cursor remains an hourglass even when you move the mouse pointer over other windows.

For more information about the SetSysModalWindow Windows API function, see the Windows version 3.1 SDK help file that ships with the Professional Edition of Visual Basic for Windows.


Additional reference words: 2.00 3.00
KBCategory: kbui kbprg kbcode
KBSubcategory: APrgWindow



THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.