Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom cursor control...

Status
Not open for further replies.

corchard

Programmer
Jul 3, 2002
23
0
0
CA
I seem to remember in VB being able to affect the cursor property from code.

In Access 97, can you change the cursor's source to a custom *.cur ?

(The docmd.hourglass method does not suit my needs.)

Thanks in advance

Chris

"Illegitimis non carborundum"
(don't let the b@st@rds get you down)
 
Hi corchard ,

this is one that usually goes down well with clients because you can display really good colour animations while executing a lenghthy procedure.

Paste this into the Declarations section of a Module:

Declare Function LoadCursorFromFile Lib "user32.dll" Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As Long
Declare Function SetCursor Lib "user32.dll" (ByVal hCursor As Long) As Long
Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)

Paste this into the On Click event of a button to see how it works:

Dim hCursor As Long, holdcursor As Long, retval As Long
hCursor = LoadCursorFromFile("C:\windows\cursors\M_busy.ani")
If hCursor = 0 Then End
holdcursor = SetCursor(hCursor)
Sleep 5000 'delete Sleep 5000 and run your procedure here
retval = SetCursor(holdcursor)

Replace the red text with the location and name of your cursor.

Bill
 
Thanks Bill,

I have modified your suggestions to the following:

In the Declarations of a public module
[tt]
Declare Function LoadCursorFromFile Lib "user32.dll" Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As Long
Declare Function SetCursor Lib "user32.dll" (ByVal hCursor As Long) As Long
Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Public hCursor As Long, holdcursor As Long, retval As Long
[/tt]


and using a public function:

[tt]
Public Function busy(status As Boolean)
If status = True Then
hCursor = LoadCursorFromFile("C:\Winnt\Cursors\hourgla3.ani")
If hCursor = 0 Then End
holdcursor = SetCursor(hCursor)
Else
retval = SetCursor(holdcursor)
End If
End Function
[/tt]


Trouble is, the cursor is set correctly but seems to return to the default as soon as the if statement ends.

Any Ideas?

"Illegitimis non carborundum"
(don't let the b@st@rds get you down)
 
Hi corchard,

Don't know why my previous post no longer works. Here is an update that I've tested on Windows 98 and WinNT:

Public Declare Function CopyIcon Lib "user32" (ByVal hIcon As Long) As Long
Public Declare Function LoadCursorFromFile Lib "user32" Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As Long
Public Declare Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long
Public Declare Function SetSystemCursor Lib "user32" (ByVal hcur As Long, ByVal id As Long) As Long
Public Declare Function GetCursor Lib "user32" () As Long
Public Const IDC_ARROW = 32512
Public hCursor As Long, hcCursor As Long, holdcursor As Long, retval

Public Function busy(Status As Boolean)
If Status = True Then
hcCursor = GetCursor()
hCursor = CopyIcon(hcCursor)
holdcursor = LoadCursorFromFile("C:\Winnt\Cursors\hourgla3.ani")
retval = SetSystemCursor(holdcursor, IDC_ARROW)
Else
retval = SetSystemCursor(hCursor, IDC_ARROW)
End If
End Function

Bill

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top