whirlspoolscat

Help pls getting Handle of Control Button in App

7 posts in this topic

G'day, 

As the handle changes every time the app launches I am trying to get the current handle of a button on an app that I am trying to automatically hold in when a key is held on ( in this example when Ctrl is held down). Can someone pls assist me in using ControlGetHandle correctly? I have searched, read, tried but to no avail. Here is the Info of the button I am trying to hold down :

>>>> Control <<<<
Class:    WindowsForms10.BUTTON.app.0.3fbab22
Instance:    21
ClassnameNN:    WindowsForms10.BUTTON.app.0.3fbab2221
Name:    buttonTalk
Advanced (Class):    [NAME:buttonTalk]
ID:    197828
Text:    Push to Talk
Position:    616, 88
Size:    120, 70
ControlClick Coords:    61, 37
Style:    0x5601000B
ExStyle:    0x00000000
Handle:    0x00000000000304C4

>>>> Mouse <<<<
Position:    1353, 155
Cursor ID:    0
Color:    0x9D9D75

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
VU
Mic   Spk
Disconnect All
Background All
Foreground All
Fast Select
State Air Desk             Air Intel  CH 369
Off
 

 

 

When I set the variable Local $hWndControl to the handle of the button it works perfectly. Of course this changes so I need to update the handle automatically each time.

Here is the au3 that works if I enter the handle   (It is a bit of a mess as I have been chopping and changing bits to try and get the handle)

 


Local $hDLL = DllOpen("user32.dll")

#include <SendMessage.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <Misc.au3>
#include <AutoItConstants.au3>


Local $hWndControl = 0x00000000000304C4 ; Set to handle of the control
;MsgBox($MB_SYSTEMMODAL, "title", $hWndControl)
Local $x = 69 ; X coord for Mouse click
Local $y = 31 ; Y coord for Mouse click
Local $wParam = 0
Local $lParam = BitRotate($x,16,"D")
$lParam = BitXOR($lParam,$y)

HotKeySet("{F10}", "StartIPR") ;;;Sets F10 as a hotkey to start the macro
; Note - F12 will stop the macro


Call ("StartIPR")

 Func StartIPR()

While 1
   If _IsPressed("11", $hDLL) Then
      

_SendMessage($hWndControl, $WM_LBUTTONDOWN,$wParam,$lParam)

        While _IsPressed("11", $hDLL)
            Sleep(100)
         WEnd
_SendMessage($hWndControl, $WM_LBUTTONUP,$wParam,$lParam)

 EndIf


 If _IsPressed("7B", $hDLL) Then
    Exit 0

EndIf
    Sleep(250)
WEnd

EndFunc
 

 

 

 

I have tried using various methods to get the handle but get the result 0x000000 which I assume is an error code (reading the help files).


#include <MsgBoxConstants.au3>

    Local $hWnd = WinActivate("[CLASS:WindowsForms10.Window.8.app.0.3fbab22]", "")

                       ;  Local $hWnd = WinActivate("[CLASS:WindowsForms10.Window.8.app.0.3fbab2221]", "")

    Local $hControl = ControlGetHandle($hWnd, "", "buttonTalk")

                      ; Local $hControl = ControlGetHandle($hWnd, "", "197828")

                      ; Local $hControl = ControlGetHandle($hWnd, "", "[ClassnameNN:WindowsForms10.BUTTON.app.0.3fbab2221]")

 

    MsgBox($MB_SYSTEMMODAL, "", "The handle of the button is: " & $hControl)

      WinClose($hWnd)

 

 

I have tried getting to it with ControlFocus and a few other methods but my eyes are spinning and I think I need a fresh set to see the forest for the trees!!

 

 

I was hoping for something like : 

Local $hDLL = DllOpen("user32.dll")

#include <SendMessage.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <Misc.au3>
#include <AutoItConstants.au3>

Local $hWnd = WinWait("[CLASS:WindowsForms10.Window.8.app.0.3fbab22]", "", 10)

Local $hWindControl = ControlGetHandle($hWnd, "", "buttonTalk")


Local $x = 69 ; X coord for Mouse click
Local $y = 31 ; Y coord for Mouse click
Local $wParam = 0
Local $lParam = BitRotate($x,16,"D")
$lParam = BitXOR($lParam,$y)

HotKeySet("{F10}", "StartIPR") ;;;Sets F10 as a hotkey to start the macro - just there as a test in case the function doesn't start from the Call
; Note - F12 will stop the macro


Call ("StartIPR")

 Func StartIPR()


While 1
   If _IsPressed("11", $hDLL) Then
      

_SendMessage($hWndControl, $WM_LBUTTONDOWN,$wParam,$lParam)

        While _IsPressed("11", $hDLL)
            Sleep(100)
         WEnd
_SendMessage($hWndControl, $WM_LBUTTONUP,$wParam,$lParam)

 EndIf


 If _IsPressed("7B", $hDLL) Then
    Exit 0

EndIf
    Sleep(250)
WEnd

EndFunc
 

 

 

Thanks

Share this post


Link to post
Share on other sites



Not sure, but I think you need this:

WinGetHandle ( "title" [, "text"] )

Share this post


Link to post
Share on other sites

For a Control Button?

Share this post


Link to post
Share on other sites

Won't that just get the Handle of the Application Window not the Button? Or do you mean use the Application Window Title for "title" and the button text for "text"?

Share this post


Link to post
Share on other sites

 Using the Application Window Title for "title" and the button text for "text" with WinGetHandle the result is 0x005049C which is the handle of the actual application window, not the control button.

Share this post


Link to post
Share on other sites

SOLVED

  Local $hWnd = WinActivate("IPR", "") ; ;; USED THE TITLE OF THE MAIN APPLICATION AS THE TITLE 

   
    Local $hControl = ControlGetHandle($hWnd, "", "WindowsForms10.BUTTON.app.0.3fbab2221" ) ;;; USED THE CLASSNAMENN for the Button text.

 

Thanks all.

Share this post


Link to post
Share on other sites

Not sure how to change the title of this thread to add [SOLVED] to it in case it helps others....

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