Champak

Previous button click on different gui

4 posts in this topic

I have autoit gui app A and autoit app B. Is there a simple way for app B to detect the last button clicked on app A? My initial thought is to do a mailslot function, but hoping there is something else simpler like @GUI_CtrlID

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Create a dummy control(myabe a inputbox hidden). and use controlsettext to set something(maybe the id) of the last button pressed...

 

Edit: Example:

App-A:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("App-A", 302, 87, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 16, 24, 73, 33)
$Button2 = GUICtrlCreateButton("Button2", 104, 24, 73, 33)
$Button3 = GUICtrlCreateButton("Button3", 200, 24, 73, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $Button1 to $Button3
            ControlSetText("App-B","","Edit1",GUICtrlRead($nMsg)) ;here you can pass ID instead name
    EndSwitch
WEnd

 

App-B:

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("App-B", 302, 120, 192, 124)
$Button1 = GUICtrlCreateButton("Show Last Button Pressed", 64, 32, 169, 33)
$Dummy = GUICtrlCreateInput("", 72, 88, 153, 21)
GUICtrlSetState($Dummy,32)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            MsgBox(0,"last Pressed",GUICtrlRead($Dummy))
    EndSwitch
WEnd

Saludos

Edited by Danyfirex

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Are they two separate scripts? Are they compiled? If you're compiled there's a new trick you can do to have two exe's communicate using WM_COPYDATA

App A

#include <GUIConstants.au3>
#include <GUIEdit.au3>

Global $hGUI = GUICreate("App A", 400, 300)
Global $btnButton1 = GUICtrlCreateButton("Example1", 10, 10, 100, 30)
Global $btnButton2 = GUICtrlCreateButton("Example2", 130, 10, 100, 30)
Global $lblInfo = GUICtrlCreateLabel("Initiated", 240, 10, 50, 20)
Global $chkCheck = GUICtrlCreateCheckbox("Simple Check", 300, 10, 100, 20)
Global $edtEdit = GUICtrlCreateEdit("", 10, 40, 380, 350)

GUISetState(@SW_SHOW, $hGUI)

ShellExecute("App B.exe", $hGUI, @ScriptDir & "\")

While (True)
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE
            GUIDelete($hGUI)
            Exit 0
        Case $btnButton1
            UpdateB(WinGetHandle("App B"), GUICtrlGetHandle($btnButton1), $btnButton1)
            _GUICtrlEdit_AppendText($edtEdit, "Button: Example 1 was pressed" & @CRLF)
        Case $btnButton2
            UpdateB(WinGetHandle("App B"), GUICtrlGetHandle($btnButton2), $btnButton2)
            _GUICtrlEdit_AppendText($edtEdit, "Button: Example 2 was pressed" & @CRLF)
        Case $lblInfo
            UpdateB(WinGetHandle("App B"), GUICtrlGetHandle($lblInfo), $lblInfo)
            _GUICtrlEdit_AppendText($edtEdit, "Label: Initiated was pressed" & @CRLF)
        Case $chkCheck
            UpdateB(WinGetHandle("App B"), GUICtrlGetHandle($chkCheck), $chkCheck)
            _GUICtrlEdit_AppendText($edtEdit, "Checkbox: Simple Check was pressed" & @CRLF)
    EndSwitch
WEnd

Func UpdateB(Const ByRef $hWndTo, Const ByRef $ctrlHandle, Const ByRef $ctrlId)
    Local $hWndStruct = DllStructCreate("handle ctrlHandle;dword ctrlId;dword")
    DllStructSetData($hWndStruct, "ctrlHandle", $ctrlHandle)
    DllStructSetData($hWndStruct, "ctrlId", $ctrlId)
    _SendMessage($hWndTo, $WM_COPYDATA, Null, DllStructGetPtr($hWndStruct))
    If (@error) Then Return 0

    Return 1
EndFunc   ;==>UpdateB

App B

#include <GUIConstants.au3>
#include <Array.au3>
#include <Date.au3>

If ($CmdLine[0] <> 1) Then
    MsgBox("", "", "Invalid parmaters used to start App B")
    Exit 1
EndIf

Global $old_ctrl_handle = 0
Global $old_ctrl_id = 0
Global $hwnd_app_a = $CmdLine[1]
Global $hGUI = GUICreate("App B", 170, 70)
Global $lblOutput = GUICtrlCreateLabel("Control Handle:" & $old_ctrl_handle & @CRLF & _
        "Control ID: " & $old_ctrl_id, 10, 10, 150, 50)

GUIRegisterMsg($WM_COPYDATA, "WM_COPYDATA")
GUISetState(@SW_SHOW, $hGUI)

While (True)
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE
            GUIDelete($hGUI)
            Exit 0
    EndSwitch

    If (Not WinExists($hwnd_app_a)) Then Exit 0
WEnd

Func WM_COPYDATA($hWndFrom, $iMsg, $wParam, $lParam)
    Local $hWndStruct = DllStructCreate("handle ctrlHandle;dword ctrlId;dword", $lParam)
    Local $new_ctrl_handle = DllStructGetData($hWndStruct, "ctrlHandle")
    Local $new_ctrl_id = DllStructGetData($hWndStruct, "ctrlId")

    If ($new_ctrl_handle <> $old_ctrl_handle) Then $old_ctrl_handle = $new_ctrl_handle
    If ($new_ctrl_id <> $old_ctrl_id) Then $old_ctrl_id = $new_ctrl_id

    GUICtrlSetData($lblOutput, "Control Handle:" & $old_ctrl_handle & @CRLF & _
            "Control ID: " & $old_ctrl_id & @CRLF & _
            "Updated @ " & _NowTime(5))

    Return 0
EndFunc   ;==>WM_COPYDATA

There's also this post for creating a shared variable between two scripts (it's really just using Nomad Memory to use RPM and WPM but someone's already done the work!)

 

 

Edited by InunoTaishou

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks both of you.

I decided to do the initial processing based on which button was pressed in App A, which is a simple one liner, and then continue on to finish the rest of the function in App B with the mailslot the way it was already.

Originally I wanted to do everything in App B since the meat of the function is already there, but figured the one line isnt going to affect anything in App A as far as processing time.

danyfirex, funny thing I have that method implemented in my app for another function and forgot all about it.

Edited by Champak

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