This article is about MicroStation® Visual Basic for Applications (VBA). It's written for developers using Bentley Systems MicroStation. Questions similar to this appear on the Be Communities Forums. These problems appeared in the MicroStation Programming Forum.

It's courteous to your users to provide feedback when something is happening in your VBA code that he or she cannot control. For example, we're used to seeing an hour-glass appear on our computer screens when Windows is busy …

Image courtesy of Icon Archive
glossy 3d blue hourglass icon

Q  How do I set the mouse pointer (or cursor) using VBA?

A It's courteous to your users to provide feedback when something is happening in your code that he or she cannot control. For example, we're used to seeing an hour-glass appear on our computer screens when Windows is busy. MicroStation VBA doesn't currently include a way to set a custom mouse icon. However, there's indirect help. Introduced with MicroStation V8i V8.11.07 is MDL function mdlWindow_setSystemCursor.

You can use MDL functions from VBA if you follow some simple rules …

  1. Declare the MDL function at the beginning of one of your VBA code modules. You must write the declaration before any of your code
  2. Disguise the MDL function: wrap it in a VBA method so you only have to deal with the nasty stuff once

In the case of a Mouse Pointer, we need both the MDL function and an enumeration (VBA Enum) that defines the several possible cursor types. Here's its VBA wrapper …

Declare PtrSafe Function mdlWindow_setSystemCursor Lib "stdmdlbltin.dll" ( ByVal systemCursor As Long ) As Long

Here's the enumeration of cursor types …

Public Enum SYSTEMCURSOR
    CURSOR_APPSTARTING = 0       ' Standard arrow and small hourglass
    CURSOR_ARROW = 1             ' Standard arrow
    CURSOR_CROSS = 2             ' Crosshair 
    CURSOR_HAND = 3              ' Windows 98/Me, Windows 2000/XP: Hand
    CURSOR_HELP = 4              ' Arrow and question mark
    CURSOR_IBEAM = 5             ' I-beam
    CURSOR_NO = 6                ' Slashed circle
    CURSOR_SIZEALL = 7           ' Four-pointed arrow pointing north, south, east, and west
    CURSOR_SIZENESW = 8          ' Double-pointed arrow pointing northeast and southwest
    CURSOR_SIZENS = 9            ' Double-pointed arrow pointing north and south 
    CURSOR_SIZENWSE = 10         ' Double-pointed arrow pointing northwest and southeast
    CURSOR_SIZEWE = 11           ' Double-pointed arrow pointing west and east 
    CURSOR_UPARROW = 12          ' Vertical arrow
    CURSOR_WAIT = 13             ' Hourglass
End Enum

Here's how to set the mouse pointer in your code …

mdlWindow_setSystemCursor CURSOR_WAIT
 ... do some work
mdlWindow_setSystemCursor CURSOR_ARROW

Here's the wrapper I mentioned to make it more like VBA …

Public Sub SetMousePointer (ByVal pointerType As SYSTEMCURSOR)
  mdlWindow_setSystemCursor pointerType
End Sub

Putting it all together, here's a test procedure. It changes the mouse pointer in MicroStation (not the VBA IDE) for five seconds …

Public Sub Main()
    SetMousePointer CURSOR_NO
     '  Do nothing for a while so you can see the effect
    Dim start                               As Single
    Dim PauseTime                           As Single
    PauseTime = 5
    start = Timer     ' Set start time
    Do While Timer < start + PauseTime
        DoEvents     ' Yield to other processes
    Loop
    SetMousePointer CURSOR_APPSTARTING
End Sub

Back to the VBA article index.