Solved

Change cursor over a form

Posted on 2001-06-07
14
868 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 50

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 50

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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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
 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

773 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