Sign in to follow this  
Followers 0
matwachich

SS_NOTIFY and mouse event on Control

8 posts in this topic

Hi all!

Simple question:

Why is the mouse click not detected on the Pic control, event WITH the SS_NOTIFY style, while it's detected on free parts of the gui???

Thanks!

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

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 386, 218)
Global $Pic1 = GUICtrlCreatePic("", 8, 8, 184, 200, BitOR($GUI_SS_DEFAULT_PIC,$WS_BORDER,$SS_NOTIFY))
GUIRegisterMsg($WM_LBUTTONDOWN, "WM_LBUTTONDOWN")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func WM_LBUTTONDOWN($hWnd, $iMsg, $iwParam, $ilParam)
    $iX = BitAND($ilParam, 0xFFFF) - 160
    $iY = BitShift($ilParam, 16) - 8
    ConsoleWrite($iX & "," & $iY & @CRLF)
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I suspect because the window is receiving the message, not the control, which is basically a child window .

I don't know if GUICtrlRecvMsg is applicable here, I would start with something along the lines of.

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Pic1
            _func_to_determine_control_coordinates()

    EndSwitch
WEnd
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

A Static(Pic) control send STN_CLICKED through WM_COMMAND 

Reference

Have a look

#include-once
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Global Const $STN_CLICKED = 0
Global Const $STN_DBLCLK = 1


Global $Form1 = GUICreate("Form1", 386, 218)
GUICtrlCreatePic("", 8, 8, 184, 200, BitOR($GUI_SS_DEFAULT_PIC, $WS_BORDER, $SS_NOTIFY))
Global $Pic1 = GUICtrlGetHandle(-1)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)

    If $ilParam = $Pic1 Then

        Switch _WinAPI_HiWord($iwParam)

            Case $STN_CLICKED

                ConsoleWrite("Clicked")

            Case $STN_DBLCLK

                ConsoleWrite("Double Clicked")

        EndSwitch

        ConsoleWrite(" at (" & _WinAPI_GetMousePosX(True, $Form1) & "," & _WinAPI_GetMousePosY(True, $Form1) & ")" & @CRLF)

    EndIf

EndFunc   ;==>WM_COMMAND

Regards :)


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Thanks for the answers!

But neither are good for me, because I also need to handle WM_LBUTTONUP, WM_RBUTTONDOWN and WM_RBUTTONUP

I'm able to make some non-optimised code with _IsPressed, MouseGetPosX ... but I want (if possible) a solution as elegant than handling window messages in my first post.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

If you don't want to handle WM_COMMAND

here is a work-around

#include-once
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


Global $Form1 = GUICreate("Form1", 386, 218)
Global $Pic1 = GUICtrlCreatePic("", 8, 8, 184, 200, BitOR($GUI_SS_DEFAULT_PIC, $WS_BORDER, $SS_NOTIFY))

GUISetState(@SW_SHOW)


Do
    $nMsg = GUIGetMsg()

    Switch $nMsg

        Case $GUI_EVENT_PRIMARYDOWN

            $aInfo = GUIGetCursorInfo()
            If $aInfo[4] = $Pic1 Then ConsoleWrite("Pic Clicked" & @CRLF)

    EndSwitch


Until $nMsg = $GUI_EVENT_CLOSE

Yet another

#include-once
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Global $Form1 = GUICreate("Form1", 386, 218)
Global $Pic1 = GUICtrlCreatePic("", 8, 8, 184, 200, BitOR($GUI_SS_DEFAULT_PIC, $WS_BORDER, $SS_NOTIFY))

GUISetState(@SW_SHOW)


Do
    $nMsg = GUIGetMsg()

    Switch $nMsg

        Case $GUI_EVENT_PRIMARYDOWN

            WM_LBUTTONDOWN($Form1)

    EndSwitch


Until $nMsg = $GUI_EVENT_CLOSE

Func WM_LBUTTONDOWN($hWnd)

    $iX = _WinAPI_GetMousePosX(True, $hWnd)
    $iY = _WinAPI_GetMousePosY(True, $hWnd)

    $aInfo = GUIGetCursorInfo()
    If $aInfo[4] = $Pic1 Then ConsoleWrite("Clk")

    ConsoleWrite(@TAB & $iX & "," & $iY & @CRLF)

EndFunc   ;==>WM_LBUTTONDOWN 

Regards :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Solved for now, thanks! Gonna use GUI events for my current problem.

But I'm always looking for a way to fire a WM_LBUTTONDOWN from a static control.

PS: I will use something like this

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

Global $Form1 = GUICreate("Form1", 386, 218)
Global $Pic1 = GUICtrlCreatePic("", 8, 8, 184, 200, BitOR($GUI_SS_DEFAULT_PIC, $WS_BORDER, $SS_NOTIFY))

GUISetState(@SW_SHOW)


Do
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_PRIMARYDOWN
            MOUSE($Form1, 1)
        Case $GUI_EVENT_PRIMARYUP
            MOUSE($Form1, 0)
    EndSwitch
Until $nMsg = $GUI_EVENT_CLOSE

Func MOUSE($hWnd, $iCode)

    $aInfo = GUIGetCursorInfo()
    If $aInfo[4] = $Pic1 Then
        Switch $iCode
            Case 1
                ConsoleWrite("down @ " & $aInfo[0] - 8 & "," & $aInfo[1] - 8 & @CRLF)
            Case 0
                ConsoleWrite("up @ " & $aInfo[0] - 8 & "," & $aInfo[1] - 8 & @CRLF)
        EndSwitch
    EndIf

EndFunc   ;==>WM_LBUTTONDOWN
Edited by matwachich

Share this post


Link to post
Share on other sites

You register the message for the GUI, not the static control to receive the event of the static control through the Window Procedure of the main GUI, you would have to subclass the Static control and route the message received there to the parent GUI

Have a look in the following script

#include-once
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>

Global $Form1 = GUICreate("Form1", 386, 218)
GUICtrlCreatePic("", 8, 8, 184, 200, BitOR($GUI_SS_DEFAULT_PIC, $WS_BORDER, $SS_NOTIFY))
Global $Pic1 = GUICtrlGetHandle(-1) ;get the handle for identifies the static control.

DeclareGlobals()

;register the message
GUIRegisterMsg($WM_LBUTTONDOWN, "WM_LBUTTONDOWN")
GUISetState(@SW_SHOW)

Do
    Sleep(10)
Until GUIGetMsg() = $GUI_EVENT_CLOSE


Func DeclareGlobals()

    ;used this to declare the globals required for the subclass.
    ;only to make the script look good.


    ;the function to release the resources upon exit
    OnAutoItExitRegister("Cleanup")

    ;callback
    Global $hStub = DllCallbackRegister("_WndProc", "long", "hwnd;uint;wparam;lparam")
    ;old window procedure
    Global $lpOldWndProc = _WinAPI_SetWindowLong($Pic1, $GWL_WNDPROC, DllCallbackGetPtr($hStub))

EndFunc   ;==>DeclareGlobals


Func _WndProc($hWnd, $iMsg, $iwParam, $ilParam)

    ;proceed the message to the parent
    Switch $iMsg
        Case $WM_LBUTTONDOWN

            Local $hParent = _WinAPI_GetParent($hWnd)

            Local $tPoint = DllStructCreate($tagPOINT)
            DllStructSetData($tPoint, 1, _WinAPI_LoWord($ilParam))
            DllStructSetData($tPoint, 2, _WinAPI_HiWord($ilParam))

            ;convert the points of the picture with respect to that of the parent.
            _WinAPI_ClientToScreen($hWnd, $tPoint)
            _WinAPI_ScreenToClient($hParent, $tPoint)

            ;make the new ilParam.
            $ilParam = _WinAPI_MakeLong(DllStructGetData($tPoint, 1), DllStructGetData($tPoint, 2))

            ;send the message to the main GUI.
            _WinAPI_PostMessage($hParent, $WM_LBUTTONDOWN, $iwParam, $ilParam)

            Return 1 ;block the default processing
    EndSwitch

    Return _WinAPI_CallWindowProc($lpOldWndProc, $hWnd, $iMsg, $iwParam, $ilParam)

EndFunc   ;==>_WndProc

;http://msdn.microsoft.com/en-us/library/windows/desktop/ms645607(v=vs.85).aspx
;Posted when the user presses the left mouse button while the cursor is in the client area of a window.
Func WM_LBUTTONDOWN($hWnd, $iMsg, $iwParam, $ilParam)

    $iX = BitAND($ilParam, 0xFFFF)
    $iY = BitShift($ilParam, 16)

    ConsoleWrite($iX & "," & $iY & @CRLF)

EndFunc   ;==>WM_LBUTTONDOWN

;release the resources
Func Cleanup()
    _WinAPI_SetWindowLong($Pic1, $GWL_WNDPROC, $lpOldWndProc)
    DllCallbackFree($hStub)
EndFunc   ;==>Cleanup

Regards :)


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Very interesting!

But too overhead for what I'm doing actualy. But I'm gonna study it, perhaps it will be usefull in the future.

Thank you!

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Friends i am new to autoit and i am stuck in middle of automation of flashing tool..
      my requirement is i have a window and i have to get the value present in that window (below is the picture)

      in the above window i need to get the value of the highlighted field.the value of this filed keeps on changing...ii need to get the current value present in the field..below are the details of the window and field..

       
      CAN it be done?
       
      thanks

    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Guys i am working on automating a flashing tool..When flashing is started if there is any error in connection it pops's up a error window...(as shown below)

       whenever this popup appears i need a msgbox to appear saying "error occured" how can i do this?
      Thanks

    • Tarakesh
      By Tarakesh
      I have a situation where the desktop is designed in java swings. The nodes JTree is not allowing me to do checkbox selection using "spacebar". I am able to navigate through the nodes using up, down arrow and a tab. When I reach to the desire node selection, mouse left click is not working due a flaw a JTree core. However since it is selected, if mouse cursor auto moved to the position of the selection and send a "click"  then it should be solved. Any ideas much appreciated. 
      the problem with having fixed coordinates are the main windows is divided to 2panels where right panel containing this JTree can be expanded or shrink-ed.

    • robcull
      By robcull
      Hello all! I have had some issues reading text from different types of windows, occasionally, specifically with controlgettext. 
      **Before I begin, I know there are better ways to do what I attempt in the example below. That's not the point of this post. The point is my issues with controlgettext. 
      I am about to cite an example with an application you may be familiar with called SpeedFan (v4.52). My problem is not specific to speedfan, it is simply the most recent and easily reproducible example I can think of. 
      So, the goal of the script below is to get a string of text containing the current fan RPMs from the highlighted control in the screenshot below (see "speedfan_control_details.png").

      Now, here's a simple script for grabbing the window handle and reading the text from that control: 
      $wintitle = "SpeedFan 4.52" $controlID = "197934" ;will be reformatted as "[ID:######]" $hwnd = wingethandle($wintitle) if @error<>0 then msgbox(0, "WinGetHandle", "FAILURE. @error="&@error) Exit EndIf $text = ControlGetText($hwnd, "", "[ID:"&$controlID&"]") if @error=1 then msgbox(0, "ControlGetText", "FAILURE. @error="&@error) ;failure returns "" and @error=1 Exit EndIf msgbox (0, "ControlGetText", "SUCCESS. @error="&@error &@CRLF& "$text="&$text) ;success returns string and @error=0 You'll see that the ControlGetText operation runs without error, however it does not capture any text from the control. If you explore the other controls in this one window, you'll find mixed results across the board. Neither the temps nor voltages can be read, while the log field and some other elements can be read. Even when you read the text from the whole window, those elements are not included in the visible nor hidden texts. 
       
      I have run into this issue many times in the past- inconsistencies in the ability of autoit to interact with certain controls. What is it which makes this text different than any other readable texts? Is there an alternate method of reading the text in the window/control which could work? Any and all info to help me solve this mystery and satisfy my curiosity would be greatly appreciated. 
      Thanks  -Rob C
      PS: Running Autoit v3.3.14.2 on Win7 Ultimate x64
    • Jibberish
      By Jibberish
      Hi,
      I am maybe an intermediate AutoIt script writer, but have no experience creating GUIs.
      I have a script with two functions. One for Checkboxes and another with radio buttons. Each function creates it's own window.
      I'd like to use one window with both checkboxes and radio buttons.
      I pulled samples from AutoIt Help and other places and worked it into this: (RadioCheck still uses the example Case and MsgBoxes. I will clean this up soon)
      Func CheckOptions() ; Create a GUI with various controls. Local $hGUI = GUICreate("SGX4CP Options", 275, 250) ; Create a checkbox control. Local $iLoopCheckbox = GUICtrlCreateCheckbox("Loop", 10, 10, 185, 25) Local $iFullScreenCheckbox = GUICtrlCreateCheckbox("Fullscreen", 10, 40, 185, 25) Local $iRestartPlaybackCheckbox = GUICtrlCreateCheckbox("Restart Playback from Sleep", 10, 70, 185, 25) GUICtrlSetState($iRestartPlaybackCheckbox, $GUI_CHECKED) Local $iDisableSleepCheckbox = GUICtrlCreateCheckbox("Disable Sleep", 10, 100, 185, 25) Local $iLogCheckbox = GUICtrlCreateCheckbox("Show Log", 10, 130, 185, 25) GUICtrlSetState($iLogCheckbox, $GUI_CHECKED) Local $idClose = GUICtrlCreateButton("Next", 110, 220, 85, 25) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop Case $iLoopCheckbox If _IsChecked($iLoopCheckbox) Then $bLoopChecked = True Else $bLoopChecked = False EndIf Case $iFullScreenCheckbox if _IsChecked($iFullScreenCheckbox) Then $bFullScreenChecked = True Else $bFullScreenChecked = False EndIf Case $iRestartPlaybackCheckbox if _IsChecked($iRestartPlaybackCheckbox) Then $bRestartPlaybackChecked = True Else $bRestartPlaybackChecked = False EndIf Case $iDisableSleepCheckbox if _IsChecked($iDisableSleepCheckbox) Then $bDisableSleepChecked = True Else $bDisableSleepChecked = False EndIf Case $iLogCheckbox if _IsChecked($iLogCheckbox) Then $bLogChecked = True Else $bLogChecked = False EndIf EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc Func RadioCheck() GUICreate("Select Test",300,180) ; will create a dialog box that when displayed is centered Local $idRadio1 = GUICtrlCreateRadio("Loop Forever", 10, 10) Local $idRadio2 = GUICtrlCreateRadio("Play each video 3 times", 10, 40) Local $idRadio3 = GUICtrlCreateRadio("Play each video separately", 10, 70) GUICtrlSetState($idRadio1, $GUI_CHECKED) Local $idClose = GUICtrlCreateButton("Start Test", 120,100) GUISetState(@SW_SHOW) Local $idMsg ; Loop until the user exits. While 1 $idMsg = GUIGetMsg() Select Case $idMsg = $GUI_EVENT_CLOSE ExitLoop Case $idMsg = $idRadio1 And BitAND(GUICtrlRead($idRadio1), $GUI_CHECKED) = $GUI_CHECKED MsgBox($MB_SYSTEMMODAL, 'Info:', 'The app will run forever, playing each video once, then looping back to the first video.') $bTestSelectForever = True Case $idMsg = $idRadio2 And BitAND(GUICtrlRead($idRadio2), $GUI_CHECKED) = $GUI_CHECKED MsgBox($MB_SYSTEMMODAL, 'Info:', 'Each video will loop 3 times then move to the next video.') $bTestSelect3Times = True Case $idMsg = $idRadio3 And BitAND(GUICtrlRead($idRadio2), $GUI_CHECKED) = $GUI_CHECKED MsgBox($MB_SYSTEMMODAL, 'Info:', 'Player opens, first video plays, player closes. Player opens, second video plays, player closes, etc.') $bTestSelectSingleVideo = True EndSelect WEnd EndFunc I would like to combine the checkbox "Loop" and the radio button $idRadio2. Radio2 requires Loop to be checked.
      I planned to remove the Loop checkbox and only enable it if Radio2 is selected.
      Can I combine these two functions into one with one window with both Checkboxes and Radio Buttons?
      Thanks
      Jibberish