Jump to content

[Solved] MouseWheel issue


Recommended Posts

Hi everybody :)

I got an issue with the mousewheel message : it stops working under certain conditions.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

HotKeySet("{ESC}", "_Wanna_Quit")

$hGUI = GUICreate("MouseWheel issue", 400, 300, 100, 100)

$idControl = GUICtrlCreateLabel("Label #0", _
    0, 0, 400, 300, BitOr($SS_CENTERIMAGE, $SS_CENTER))

GUISetState()
GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL")

$Inc = 0

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _Exit()

        Case $GUI_EVENT_PRIMARYDOWN
            $Inc += 1
            If GUICtrlDelete($idControl) = 0 Then ; 0 = failure, 1 = success
                MsgBox($MB_TOPMOST, "Error", "Control not deleted")
                _Exit()
            EndIf
            $idControl = GUICtrlCreateLabel("Label #" & $Inc, _
                0, 0, 400, 300, BitOr($SS_CENTERIMAGE, $SS_CENTER))
            ; WinActivate($hGUI)
    EndSwitch
WEnd

;====================================================
Func WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam)

    Local Static $iCount = 0
    $iCount +=1
    ConsoleWrite($iCount & @lf)

    Return $GUI_RUNDEFMSG

EndFunc ; WM_MOUSEWHEEL

;====================================================
Func _Wanna_Quit()

    HotKeySet("{ESC}")

    If MsgBox(BitOr($MB_TOPMOST, $MB_OKCANCEL), _
      "Esc was keyed", "Quit script ?") = $IDOK Then
        _Exit()
    EndIf

    HotKeySet("{ESC}", "_Wanna_Quit")

EndFunc ; _Wanna_Quit

;====================================================
Func _Exit()

    GUIDelete($hGUI)
    Exit

EndFunc ; _Exit

If you run this script and immediately turn the mouse wheel up or down, you will notice its counter correctly incremented in the Console. So far so good...

Now if you left click inside the GUI, it will delete the label control #0 and replace it with a new label control #1 ... and after that the mouse wheel doesn't respond at all.

Then if you key Escape (asking you to quit the script or not), choose not to quit... and the mouse wheel is reactivated !

Anyone noticed such a strange behavior ?

Edit: this is a "kind of" reproducer of the issue. In fact it happens in a more complicated script, with a parent gui + a child gui, the left click deleting the child gui (and the pic control inside it), before a new child gui is created with a new pic in it : now the mousewheel doesn't respond in the 2nd pic... unless I click Escape, choosing not to quit etc... exactly the same issue as described in the script above.

Thanks for any advice.

Edited by pixelsearch
[Solved] in topic title
Link to comment
Share on other sites

10 minutes ago, pixelsearch said:

Now if you left click inside the GUI, it will delete the label control #0 and replace it with a new label control #1 ... and after that the mouse wheel doesn't respond at all.

Nope, still works for me.  Number keeps incrementing in console after.

Edit : I was able to reproduce you issue. But by minimizing and restoring the GUI it starts working well.  So I suppose (without any testing) that it refers to some kind of focus lost....

Edited by Nine
Link to comment
Share on other sites

12 minutes ago, pixelsearch said:

Anyone noticed such a strange behavior ?

I do not have a solution, but I can reproduce the behaviour you describe.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

This also seems to work :

...
        Case $GUI_EVENT_PRIMARYDOWN
            ...
            
            $idControl = GUICtrlCreateLabel("Label #" & $Inc, _
                0, 0, 400, 300, BitOr($SS_CENTERIMAGE, $SS_CENTER))
                
            GUICtrlSetState($idControl, $GUI_FOCUS)
...

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Same as both of you, it works by minimizing and restoring the GUI but how could we improve this behavior ?
I felt for a long time that MsgBox in _Wanna_Quit() solved this issue because it gave back the focus to the GUI when we choose not to quit, but after that, even if we activate again the GUI in the script, it's not enough.

You'll never imagine how it happened to me the 1st time in my real script :
I use the mouse wheel to resize pics, with a dynamic tooltip displayed at the top of the GUI
As soon as I click on the ToolTip, the issue will start because clicking on the tooltip => GUI loses focus and I never found any AutoIt instruction to get the focus back and solve this mouse wheel issue.

Edit just read Nine's last answer, gonna see how to implement this solution in my real script, after the new child window is created :

ControlFocus ($hGUI,"", "")

It works in my real script, bravo Nine :thumbsup:

How did you find this ? Especially you didn't indicate any controlID in the command !

Thanks Musashi, you made it work too !

Edited by pixelsearch
Link to comment
Share on other sites

5 minutes ago, pixelsearch said:

How did you find this ?

Well, I have seem something similar in the past.  I suppose we can call it experience.  It is now one of my first test to minimize and restore to see if a strange behavior is still persiting.

Link to comment
Share on other sites

He did the same with me xD. Now I won the same reflex 😛 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...