Jump to content
Sign in to follow this  
matwachich

SS_NOTIFY and mouse event on Control

Recommended Posts

matwachich

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
JohnOne

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
PhoenixXL

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
matwachich

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
PhoenixXL

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
matwachich

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
PhoenixXL

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
matwachich

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  

  • Similar Content

    • ur
      By ur
      An application is there which is created using vc++,mostly mfc.
       
      DOn't know the details completely.
       
      WHen I try to automate the control clicks for testing the UI.
      THe below control is not detected.
      As you can see, during UI operations I can click the elements one by one.
      But all the elements is selected as a whole set, when I use the Windowinfo tool.

       
      How to click this using AutoIT.?
       
      Please suggest.
    • bbProg
      By bbProg
      Hi,
       
      how can I wait activate for windows with information as in the photos attached?
      Class is not being recognized by the script.
       
      thanks in advanced.



    • Xandy
      By Xandy
      I'm listing the error message strings, and roughly matching the error code
      Is this how to do error reporting?  Is there a more simple way I don't know about?
      I realise I might not need to trap @error inside $error.  I like it this way b/c I have no fear of overwriting @error now; I don't even use it.
      Func Send_Connect($address, $port)     $socket = TCPConnect($address, $port)     $error = @error     If $error <> 0 Then         Local $aError[4] = ["-2 not connected.", _                             "1 IPAddr is incorrect.", _                             "2 port is incorrect."]         $aError[3] = "10060 Connection timed out."         If $error < 0 Then $error = 0         If $error > 2 Then $error = 3         MsgBox(0, "TCP Connect Error", $aError[$error], 0)         $socket = 0     EndIf     Return $socket EndFunc
    • nacerbaaziz
      By nacerbaaziz

      Hi dear
      This is the first include file I designed
      This work is especially directed to NVDA free screen reader users
      It contains a set of functions that enable you to control the program
      Such as forcing the program to read a custom text
      Force it to stop talking
      Find out if the program is running
      And show custom text in the Braille screen
      Available functions are
      _nvdaControllerClient_Load()
      to load the dll file
      _nvdaControllerClient_free()
      to UnLoad the dll file
      _nvdaControllerClient_SpeakText()
      to speak a custom text
      _nvdaControllerClient_brailleMessage()
      to show custom text in the Braille screen
      _nvdaControllerClient_cancelSpeech()
      to Force the NVDA  to stop talking
      _nvdaControllerClient_testIfRunning()
      to check if the NVDA is running
      important note :
      All of these functions depend on a nvdaControllerClient32.dll
      I've added it in the attachments, as well as a file for examples, and other files
      As the source and examples in other languages
      For those who wanted to download the free screen reader, this is the download link from the official website
      https://www.nvaccess.org/download/
      i hope you like this topic
      I hope you will try it and give me your opinions
      Thank you all members and administrators for their help
      now with the  Attachments
       
      nvdaControllerClient_UDF.zip
    • RHolmes
      By RHolmes
      I wrote a script a few months ago that was working at the time. When I tried it today it wouldn't retrieve any controls.  The application successfully launches, but I cannot figure out how to retrieve the control from the window that is launched. I'm on a windows 10 machine using AutoIt v3.3.14.2. The only thing I can think of that has changed is windows updates? Code is below, any help is greatly appreciated.    ; Notes: ; HandleError( handleToCheck, MsgToLogOnFailure, terminateAutoItOnFail ) : function that simply checks the handle and quits AutoIt if not present ; all of this works well FileChangeDir( $CLIENT_APPLICATION_DIR ); Run( "Client.exe" ) Local $hClient = WinWaitActive( $CLIENT_TITLE, "", 10 ) $terminateOnFail = 1 HandleError( $hClient, "LaunchClient::Error: Failed to launch client. Either timed-out or failed.", $terminateOnFail ) LogToFile( "Client launched, waiting for system to ready." ) Sleep( 5000 ) ; this part does not work ; $SYSTEM_INDICATOR is a global variable. I have tried these values: "SystemIndicatorWindow" (Text), "Qt5QWindowIcon101" (ClassNN), and ; "[CLASS:Qt5QWindowIcon; INSTANCE:101]" Local $hStatusIndicator = ControlGetHandle( $hClient, "", $SYSTEM_INDICATOR ) HandleError( $hStatusIndicator, "CheckStatus::Error: couldn't retrieve control: " & $SYSTEM_INDICATOR, $terminateOnFail ) This is what the spy reveals: 

       
      Edit: I just tried this code and it works for notepad++.
      FileChangeDir( "C:\Program Files\Notepad++\" ); Run( "notepad++.exe" ) Local $hNotePad = WinWaitActive( "new 1 - Notepad++", "", 10 ) If $hNotePad = 0 Or $hNotePad = -1 Then MsgBox( $MB_SYSTEMMODAL, "Error", "Error getting app handle." ) EndIf Sleep( 1000 ) Local $hNewFileBtn = ControlGetHandle( $hNotePad, "", "[CLASS:ToolbarWindow32; INSTANCE:1]" ) If $hNewFileBtn = 0 Or $hNewFileBtn = -1 Then MsgBox( $MB_SYSTEMMODAL, "Error", "Error getting button handle." ) EndIf MsgBox( $MB_SYSTEMMODAL, "Success", "Success." )  
×