set cursor with api

R

RB Smissaert

Need to set the cursor in Excel with the API, so tried this:

Option Explicit
Private Const IDC_ARROW As Long = 32512
Private Declare Function LoadCursor _
Lib "user32" _
Alias "LoadCursorA" _
(ByVal hInstance As Long, _
ByVal lpCursorName As Long) As Long
Private Declare Function SetCursor _
Lib "user32" (ByVal hCursor As Long) As Long

Sub test()

Application.Cursor = xlWait 'just to test it alters the cursor

SetCursor (LoadCursor(0, IDC_ARROW))

End Sub

However nil happens, although there is no error.
Any suggestions how this could be done?


RBS
 
R

RB Smissaert

Isn't that just the type definition for a long variable?
In any case I did it like that at one stage and just the same.
I think the trouble is that Excel or VB in general will keep setting the
cursor
back to the original.

RBS
 
G

Guest

All I can say is that the guy in the thread below (Paul Martin) implied that
it worked. His code is virtually identical to yours.
Good Luck,
Sincerely,
 
R

RB Smissaert

Have you tried this?

Option Explicit
Private Const IDC_ARROW = 32512&
Private Declare Function LoadCursor _
Lib "user32" Alias "LoadCursorA" _
(ByVal hInstance As Long, _
ByVal lpCursorName As Long) As Long
Private Declare Function SetCursor _
Lib "user32" (ByVal hCursor As Long) As Long

Sub test()

Application.Cursor = xlWait

SetCursor (LoadCursor(0, IDC_ARROW))

End Sub

As you can see (with me anyhow), the cursor stays hourglass.


RBS
 
G

Guest

No. Haven't tried it.
After looking at the google again, I did notice another difference in code.

Try...
SetCursor LoadCursor(0, lCursor)
instead of
SetCursor (LoadCursor(0, IDC_ARROW))

HTH,
 
R

RB Smissaert

Before suggesting things to try it might be worth it to try first and see if
it is any good ...

RBS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top