Solved

Change cursor over a form

Posted on 2001-06-07
14
864 Views
Last Modified: 2013-11-14
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.
0
Comment
Question by:boomshanker
  • 4
  • 3
  • 3
  • +3
14 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 6166648
Hi, try to save the icon's file to 16 bit.
0
 
LVL 1

Author Comment

by:boomshanker
ID: 6166661
How do I do that?
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 6166683
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
 
LVL 1

Author Comment

by:boomshanker
ID: 6166744
I tried creating a new 16 bit cursor, but it is still showing in black with no colours.
0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6166768
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
 
LVL 6

Expert Comment

by:sharmon
ID: 6166836
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
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6166996
sharmon,

that is interesting.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 8

Expert Comment

by:glass_cookie
ID: 6167201
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
 
LVL 6

Accepted Solution

by:
sharmon earned 50 total points
ID: 6168057
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6168710
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
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6168920
Oops...

Hi Sharmon : ) My mistake ; )
0
 
LVL 1

Author Comment

by:boomshanker
ID: 6169414
Thanks sharmon.

I had no idea about resource files.  Much appreciated.
0
 
LVL 6

Expert Comment

by:sharmon
ID: 6169467
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
 
LVL 6

Expert Comment

by:sharmon
ID: 6169472
Of course I mean cursor not icon in my previous comment:)  Not enough sleep....
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

One of the most frequently asked questions on EE in the "Windows Installer" zone is how to eliminate self-triggered installation of some product.  The problem occurs when, suddenly, whenever a certain application is launched, or even when a folder i…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now