Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Developers    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Destructive Custom Cursors
Clifford Jensen 
     
2 days ago
I have buttons on my custom form derived from CommandButtons.
In the MouseMove event of these buttons, I use custom cursors using the following code:
    Dim lHandle As LongPtr
lHandle = LoadCursorFromFile(strFilePath & "CURSOR_U.CUR")
    If (lHandle > 0) Then
        SetCursor lHandle
    End If
I use three different custom cursors, each loaded based on what will happen when the mouse is left-clicked.
All goes well for a random amount of time, usually less than 30 minutes, when suddenly the cursor becomes a CommandButton consumer, erasing every button I derived from the CommandButton object as the cursor passes over these objects.
The CommandButtons still function when clicked but their image is missing.
Research indicates that my code is conflicting with Window's code it uses to control cursors.  I am looking for a solution to this dilemma.
Cliff
Richard Rost  @Reply  
          
2 days ago
Excellent question.

The problem is that MouseMove fires constantly, and each time it fires you're calling LoadCursorFromFile and creating another cursor handle. After enough mouse movement, you're leaking Windows cursor/GDI resources. The disappearing button images are exactly the kind of strange UI behavior you can get once those resources start running low.

Don't load the cursor file inside MouseMove. Load each of your three cursors once, store their handles in module-level LongPtr variables, and then just call SetCursor with the already-loaded handle.

For example, load them in the form's Load event:

Private mCursorUp As LongPtr
Private mCursorDown As LongPtr
Private mCursorSomethingElse As LongPtr

Private Sub Form_Load()
    mCursorUp = LoadCursorFromFile(strFilePath & "CURSOR_U.CUR")
    mCursorDown = LoadCursorFromFile(strFilePath & "CURSOR_D.CUR")
    mCursorSomethingElse = LoadCursorFromFile(strFilePath & "CURSOR_X.CUR")
End Sub


Then your button MouseMove event becomes simply:

If mCursorUp <> 0 Then
    SetCursor mCursorUp
End If


When the form closes, release the cursor handles:

Private Sub Form_Unload(Cancel As Integer)
    If mCursorUp <> 0 Then DestroyCursor mCursorUp
    If mCursorDown <> 0 Then DestroyCursor mCursorDown
    If mCursorSomethingElse <> 0 Then DestroyCursor mCursorSomethingElse
End Sub


Also make sure you are not calling DestroyCursor immediately after SetCursor. Keep the handles alive for as long as the form needs them, then destroy them once in Form_Unload.

Loading three cursors once is trivial. Loading one every time the mouse twitches is like buying a new mouse every time you move it. Eventually Windows gets annoyed.

It's just like I always say: if you set it, you gotta forget it. Well, this doesn't use set, but it's the same concept.
Add a Reply Upload an Image
Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 8/28/2026 1:43:28 AM. PLT: 1s