Change cursor over a form

Hi.  I've set the Form1.MousePointer property to Custom, and the Form1.MouseIcon property to the location of a .cur file that I wish to use.  The shape of the cursor is showing correctly, but there is no colour to the cursor when the mouse is moved over the form.  

Any ideas would be greatly appreciated.  Thx.
LVL 1
boomshankerAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
sharmonConnect With a Mentor Commented:
Well glass cookie, here we go....

I did forget to tell him that the cursor has to be loaded from a resource file to work that way properly, but it won't show in color until you compile and run the exe.

MY PREFERRED WAY
Add a resource file to your project if you don't already have one.

Add your custom cursors, being aware of your id numbers...

Run code as below....remember to compile or it will be in b&w until you run the executable.

  Me.MousePointer = vbCustom
  Me.MouseIcon = LoadResPicture(101, vbResCursor)


ANOTHER WAY...USING FILES
If you want to load them from a file you can do something like this....

Copy this code into a module....

Option Explicit

Public Declare Function DestroyCursor Lib "user32" _
(ByVal hCursor As Any) As Long

Public Declare Function LoadCursorFromFile Lib "user32" _
Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As Long

Public Declare Function SetClassLong Lib "user32" Alias _
"SetClassLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Public Declare Function LoadCursor Lib "user32.dll" Alias _
"LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Any) As Long

Public Declare Function GetCursor Lib "user32.dll" () As Long

Public Const GCL_HCURSOR = -12

Public Function SetCursor(ByRef frm As Form, ByRef hCur As Long, ByVal strFile As String) As Long
  frm.MousePointer = 0
  hCur = LoadCursorFromFile(strFile)
  SetCursor = SetClassLong(frm.hwnd, GCL_HCURSOR, hCur)
End Function

Public Function ResetCursor(ByRef frm As Form, ByRef hCur As Long) As Long
  DestroyCursor hCur
  hCur = GetCursor()
  ResetCursor = SetClassLong(frm.hwnd, GCL_HCURSOR, hCur)
End Function


'Add this code to your form...change the path of my test cursor to your cursor....

Option Explicit

Dim hCur As Long

Private Sub Form_Load()
  SetCursor Me, hCur, "d:\test.cur"
End Sub

Private Sub Form_Unload(Cancel As Integer)
  'Run this or you will lose the memory the cursor is using.
  ResetCursor Me, hCur
End Sub



0
 
Ryan ChongCommented:
Hi, try to save the icon's file to 16 bit.
0
 
boomshankerAuthor Commented:
How do I do that?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Ryan ChongCommented:
I think the icon not show what its exactly bcos of it's bit size. Try to use some commercial graphic tool that can edit icon files, like Michaengelo, if not wrong.

I don't know if something goes wrong! :P
0
 
boomshankerAuthor Commented:
I tried creating a new 16 bit cursor, but it is still showing in black with no colours.
0
 
glass_cookieCommented:
Hi!

Please DO note that .cur files will ALWAYS appear black and white no matter what on your form.  If you want to have colour, you'll have to use an icon file.

But there's 1 problem with icon files.  The mouse pointer position on the icon file would be either in the middle of the icon file or at the top-left hand side of the icon.

Well, you may want to try downloading Microangelo and use a cirsor file and chhange the colour to invert.  It's an interesting colour as it would be the invert of whatever colour that's beneath it.

Downoad...
http://download.cnet.com/downloads/0-1476516-108-17056.html?bt.15897.10015..dl-17056

Description: The Microangelo 5.0 evaluation package is a self-extracting installation file created with InstallShield Professional and PackageForTheWeb. Download and save the EXE file to your computer. When the download completes, run the EXE file to install Microangelo.
 
Note that the file is 2.2 MB

That's it!

glass cookie : )
0
 
sharmonCommented:
Have you compiled the application and checked it, it should be color on run of the actual executable, it will always be B&W in the debugger.

Regards,
Shannon
0
 
Valliappan ANSenior Tech ConsultantCommented:
sharmon,

that is interesting.
0
 
glass_cookieCommented:
Hi Sharmon : )

Nothing against you, but I got this article from the help file:

Although Visual Basic does not create or support color cursor (.cur) files (such as those that ship with Windows NT), you can use the MouseIcon property to load either cursor or icon files. Color cursor files such as those shipped with Windows NT 3.51, are displayed in black and white. To display a color cursor, use a color icon file (.ico). The MouseIcon property provides your program with easy access to custom cursors of any size, with any desired hot spot location. Visual Basic does not load animated cursor (.ani) files, even though 32-bit versions of Windows support these cursors.

That's it!

glass cookie : )
0
 
Richie_SimonettiIT OperationsCommented:
sharmon, why to use that?
Changing the mouseicon property of form would be just enougth and we don't need a resource files or APIs or calls to loadres..., and so on.
0
 
glass_cookieCommented:
Oops...

Hi Sharmon : ) My mistake ; )
0
 
boomshankerAuthor Commented:
Thanks sharmon.

I had no idea about resource files.  Much appreciated.
0
 
sharmonCommented:
Richie,

I don't have the slightest clue what you mean.  Not to offend you, I just don't get what you are pointing at.  He can't just change the mouseicon on the form if that is what you mean, vb will show the icon as b&w only everytime.  I wouldn't load the icon with the api either but I guess in some situations it may be needed, so I gave him both ways to do it just incase.  Loading the icon from a resource file will allow it to show in color when compiled....

Boomshanker,

You are welcome, my pleasure.

Shannon

0
 
sharmonCommented:
Of course I mean cursor not icon in my previous comment:)  Not enough sleep....
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.