Downloaded this programe that you create animated mouse icons can anyone tell me how to asign it to a click event?
Cheers
Spud
Printable View
Downloaded this programe that you create animated mouse icons can anyone tell me how to asign it to a click event?
Cheers
Spud
What do you mean by assigning it to a click event?
If you mean displaying it when a button is clicked, you can use the following code.
Insert code in a Form with a CommonDialog and a CommandButton
Code:Private Declare Function LoadCursorFromFile Lib "User32" Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As Long
Private Declare Function SetClassLong Lib "User32" Alias "SetClassLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GCL_HCURSOR = (-12)
Dim prevCur As Long
Dim MyCursor As Long
Private Sub Command1_Click()
Dim OpenFile As String
CommonDialog1.Filter = "Animated Cursors (*.ani)|*.ani"
CommonDialog1.ShowOpen
OpenFile = CommonDialog1.filename
MyCursor = LoadCursorFromFile(OpenFile)
prevCur = SetClassLong(Me.hwnd, GCL_HCURSOR, MyCursor)
End Sub
Private Sub Form_Unload(Cancel As Integer)
prevCur = SetClassLong(Me.hwnd, GCL_HCURSOR, hOldCursor)
End Sub
Megatron I think Im doing somthing wrong with this part of the code can you help?
CommonDialog1.Filter = ("C:\My Documents\gdsm.ani")
Thanks again
Spud
The Filter is the type of files you want to open. Just leave it at CommonDialog1.Filter = "Animated Cursors (*.ani)|*.ani" and it should work fine.
If you do not want to load it from the CommonDialog, then
use this line instead. MyCursor = LoadCursorFromFile("C:\My Documents\gdsm.ani")
Thanks again Megatron thats it sorted now.
Cheers!
Spud
How would I alter the code so that an animated cursor is displayed when hovering over command1 only
This can do both Cursors and Icons:
VB Code:
Option Explicit Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Command1.DragIcon = LoadPicture("C:\Program Files\Microsoft Visual Studio\Vfp98\FFC\Graphics\H_point.cur") Command1.Drag vbBeginDrag End Sub Private Sub Command1_DragOver(Source As Control, X As Single, Y As Single, State As Integer) If State = vbLeave Then Command1.Drag vbEndDrag End If End Sub
Doesn't that code do the same as Properties-Form1 Icon
It doesn't appear to work with .ani files.
Nope, it won't do .ani (Only Cursors and Icons)
I posted it incase u were just after Cursors :)
How do I display an animated (.ani) cursor over such as a command1 button ? plz :cool:
Try:
VB Code:
Option Explicit Private Declare Function LoadCursorFromFile Lib "User32" Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As Long Private Declare Function SetClassLong Lib "User32" Alias "SetClassLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Const GCL_HCURSOR = (-12) Dim prevCur As Long Dim MyCursor As Long Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) MyCursor = LoadCursorFromFile("C:\Windows\Cursors\Hourglas.ani") prevCur = SetClassLong(Command1.hwnd, GCL_HCURSOR, MyCursor) End Sub Private Sub Form_Unload(Cancel As Integer) prevCur = SetClassLong(Me.hwnd, GCL_HCURSOR, hOldCursor) End Sub
The only problem at the moment is the error on unload.
I'm trying to fix it. The Cursor remains the HourGalss! (until u
close VB)
I removed the unload form bit of the code and it works perfect.
Thanks.:D
Good job :)
Seems to work well!
Does anyone see a problem with it?
VB Code:
Option Explicit Private Declare Function LoadCursorFromFile Lib "User32" Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As Long Private Declare Function SetClassLong Lib "User32" Alias "SetClassLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Const GCL_HCURSOR = (-12) Dim prevCur As Long Dim MyCursor As Long Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) MyCursor = LoadCursorFromFile("C:\Windows\Cursors\Hourglas.ani") prevCur = SetClassLong(Command1.hwnd, GCL_HCURSOR, MyCursor) End Sub
You were trying to set it to hOldCursor in form uload..which is never defined?