Closed hartacus closed 1 week ago
Hello.
I like this script very much but i found out the same problem in CorelDraw. Happens when closing individual documents or the whole program. If I click on the cross, nothing happens until I move the cursor elsewhere and the focus changes. It's not enough to move the mouse into the document window, I have to hover over another program control, for example, or click on a macro form.
PS: I apologize for posting here, even though it's not Excel related, but it seems like it might have the same core issue.
Martin.
Hi @hartacus
I did not experience this problem with the mouse hook before.
However, I know about a VBA bug that causes this behaviour. If one of your Userforms has any Object members then they need to be manually cleared. For example, let's say you have this at the top of your Userform code:
Private myClass As SomeClass
and you instantiate that object at some point (e.g. when a button is clicked), then you must Set myClass = Nothing
in the form's Terminate
event. This bug has nothing to do with the mouse scroll, it's just a VBA bug. If you don't write code to clear the objects then Excel (or another app) becomes unresponsive and clicking the X button does nothing or causes flickering.
Hi @Kenobi-cz
Please don't apologize. I am limited in the amount of machines or software I can test on. So, any feedback is super useful.
Can you please give a list of steps to reproduce this? For example: 1) Open a modal form with scroll enabled 2) Close the form 3) Close the application via the X button 4) Issue happens ...
I do not have CorelDraw but I might be able to install a trial. What version are you using?
Thank you!
Can you please give a list of steps to reproduce this?
I wasn't accurate in my description of the problem. I use the modeless form variants, working with multiple files at once in Corel and continuously opening and closing others as needed. If the form is closed, everything works OK but not with modeless form and MouseScroll enabled. Is there any chance to add a setting where MouseScroll would only activate when the form macro is active and not the application? Or only if I am actively using listboxes, textboxes, etc.?
I'm using CorelDraw 2018, we have the latest version on the virtual server and the problem occurs there as well. The steps to reproduce may not be needed if you reply that it cannot be resolved in modeless mode. Thank you for your reply.
Martin
@Kenobi-cz
The mouse should unhook if the forms are destroyed because it tracks the reference count for each form instance that was passed to EnableMouseScroll
. However, if you only hide the forms or if there is a memory leak that holds the instances 'live' then it's best to call DisableMouseScroll
when you hide/unload to make sure they get removed from the tracking. Then call EnableMouseScroll
again when you re-show.
Hi @cristianbuse, thanks for your reply. I tried to find any leftover instances of classes and address them as you suggested (big project that I inherited) but this didn't seem to fix the issue. In the end, what seemed to work best was to make UnHookMouse public and then explicitly call that function from the project's exit sub (runs when clicking a Quit button on a form). This seemed to resolve flickering and issues with Excel quitting. I'll continue testing and let you know if I can find a solution for my project without that step.
Hi @hartacus ,
I think the latest update I made should fix your issue and the Quit button should not freeze the app. Please re-test and let me know. Thanks!
Hi @hartacus ,
I think the latest update I made should fix your issue and the Quit button should not freeze the app. Please re-test and let me know. Thanks!
Hi @cristianbuse ,
This also seems to have solved the problem in CorelDraw, it now behaves seamlessly and the files and application can be closed even if the modeless variant form is open and MouseScroll is on. Many thanks for your work and continued development on this project.
Happy coding Martin.
Thank you for the feedback @Kenobi-cz
Hi Cristian, I am having further issues with the project where I have mouse scroll enabled. Sometimes, Excel will not be responsive when it gains focus - clicking does nothing. Other times, Excel will not be able to be closed- the "Close" function in the File menu can close a file, but the red X button at top right does nothing. Unfortunately, I haven't been able to determine the trigger states for these issues. Logging here to raise in case this has been observed elsewhere, but I'll report back if I find a way to reliably reproduce these.