This article was previously published under Q160041
This article has been archived. It is offered "as is" and will no longer be updated.
The MousePointer property in Visual Basic (which applies to Form, MDIForm,and a set of selected controls) allows you to modify the cursor's shape fora Visual Basic application. However, if the cursor is moved away from theVisual Basic application, its shape is determined by other applications orby the Desktop.
This article describes how to modify the cursor's default settings so thatthese changes are reflected throughout the Desktop.
NOTE: Due to a bug in Windows NT, this article only applies to Windows 95and Windows 98. Microsoft is researching this issue and will post newinformation here in the Microsoft Knowledge Base as it becomes available.
On Windows 2000, this program works but not as expected. In the code that follows, in Command1_Click toggles the pointer between an arrow and an arrow/hourglass icon. And the code in Command2_Click has no affect.
At times, you may want to design an application in Visual Basicthat allows the user to run other applications or tasks within the sameapplication while a task is running.
A simple way to inform the user that this particular state exists is tomodify the cursor to be both an arrow and an hourglass until the first taskis completed. You can accomplished this easily with the SetSystemCursorAPI.
The following example simulates starting a task with the firstCommandButton and halting it with the second CommandButton:.
Start a new project in Visual Basic. Form1 is created by default.
Add the following code to the General Declarations section of Form1:
Private Const IDC_APPSTARTING = 32650& Private Const IDC_ARROW = 32512& Private Const OCR_NORMAL = 32512& Private Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long Private Declare Function SetSystemCursor Lib "user32" (ByVal hcur As Long, ByVal id As Long) As Boolean
Add two CommandButtons, Command1 and Command2, to Form1.
Add the following code to the Click event of Command1:
Private Sub Command1_Click() Dim hcursor As Long, ret_val As Long hcursor = LoadCursor(0, IDC_APPSTARTING) ret_val = SetSystemCursor(hcursor, OCR_NORMAL) End Sub
Add the following code to the Click event of Command2:
Private Sub Command2_Click() Dim hcursor As Long, ret_val As Long hcursor = LoadCursor(0, IDC_ARROW) ret_val = SetSystemCursor(hcursor, OCR_NORMAL) End Sub
Run the project by pressing the F5 key. Click on Command1 to modify the cursor. Move the cursor around over other applications and click on them for activation. Finally, click on Command2 to restore the cursor to its original shape.
Microsoft Visual Basic 5.0 Learning Edition, Microsoft Visual Basic 6.0 Learning Edition, Microsoft Visual Basic 5.0 Professional Edition, Microsoft Visual Basic 6.0 Professional Edition, Microsoft Visual Basic 5.0 Enterprise Edition, Microsoft Visual Basic 6.0 Enterprise Edition, Microsoft Visual Basic 4.0 Standard Edition, Microsoft Visual Basic 4.0 Professional Edition, Microsoft Visual Basic 4.0 32-Bit Enterprise Edition