Jump to content

Control Clicking a button on another tab


Recommended Posts

Hello,

I would like to figure out a way to manipulate a control on one tab when inside another.

Let me break it down:

#include <GUIConstantsEx.au3>

$GUI = GUICreate("Title", 281, 316)
$MenuItem1 = GUICtrlCreateMenu("&File")
$MenuItem2 = GUICtrlCreateMenuItem("Exit"&@TAB&"F12", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenu("&Options")
$MenuItem5 = GUICtrlCreateMenu("&Help")
$MenuItem6 = GUICtrlCreateMenuItem("About", $MenuItem5)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Tab1 = GUICtrlCreateTab(0, 0, 280, 295)
GUICtrlCreateTabItem("Tab 1")
$Button1 = GUICtrlCreateButton("Start", 112, 144, 81, 33)
GUICtrlCreateTabItem("Tab 2")
GUICtrlCreateTabItem("Tab 3")
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

HotKeySet("{F1}", "Test")

While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case $MenuItem6
         MsgBox(64, "About", "Info.")
      Case $GUI_EVENT_CLOSE, $MenuItem2
         Exit
      Case $Button1
         If GUICtrlRead($Button1) = "Start" Then
            GUICtrlSetData($Button1, "Stop")
         Else
            GUICtrlSetData($Button1, "Start")
         EndIf
   EndSwitch
WEnd

Func Test() ;Call for button click
   ControlClick("Title", "Stop", 11)
EndFunc

The code above has 3 tabs and a button in the first. The button toggles between Start and Stop, nothing more. When pressing the F1 key it calls to Press the "Stop" button, which works flawless when Tab1 is shown, but does nothing when on Tab2 or Tab3. Is there a way to simulate this or call for the execution?

Link to post
Share on other sites

Here two ways to do this :

 

#include <GUIConstantsEx.au3>

$GUI = GUICreate("Title", 281, 316)
$MenuItem1 = GUICtrlCreateMenu("&File")
$MenuItem2 = GUICtrlCreateMenuItem("Exit" & @TAB & "F12", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenu("&Options")
$MenuItem5 = GUICtrlCreateMenu("&Help")
$MenuItem6 = GUICtrlCreateMenuItem("About", $MenuItem5)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Tab = GUICtrlCreateTab(0, 0, 280, 295)
$Tab1 = GUICtrlCreateTabItem("Tab 1")
$Button1 = GUICtrlCreateButton("Start", 112, 144, 81, 33)
$Tab2 = GUICtrlCreateTabItem("Tab 2")
$Tab3 = GUICtrlCreateTabItem("Tab 3")
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)

$idDummy = GUICtrlCreateDummy()

HotKeySet("{F1}", "Test")
HotKeySet("{F2}", "Test2")

While 1
  $nMsg = GUIGetMsg()
  Switch $nMsg
    Case $GUI_EVENT_CLOSE, $MenuItem2
      Exit
    Case $idDummy
      ContinueCase
    Case $Button1
      If GUICtrlRead($Button1) = "Start" Then
        GUICtrlSetData($Button1, "Stop")
      Else
        GUICtrlSetData($Button1, "Start")
      EndIf
  EndSwitch
WEnd

Func Test()
  Local $iTab = GUICtrlRead($Tab, $GUI_READ_EXTENDED)
  Local $idTab = @extended
  If $iTab <> 0 Then GUISwitch($GUI, $Tab1)
  ControlClick($GUI, "", 11)
  If $iTab <> 0 Then GUISwitch($GUI, $idTab)
EndFunc   ;==>Test

Func Test2()
  GUICtrlSendToDummy($idDummy)
EndFunc

 

Edited by Nine
Link to post
Share on other sites
#include <GUIConstantsEx.au3>

$GUI = GUICreate("Title", 281, 316)
$MenuItem1 = GUICtrlCreateMenu("&File")
$MenuItem2 = GUICtrlCreateMenuItem("Exit"&@TAB&"F12", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenu("&Options")
$MenuItem5 = GUICtrlCreateMenu("&Help")
$MenuItem6 = GUICtrlCreateMenuItem("About", $MenuItem5)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Tab1 = GUICtrlCreateTab(0, 0, 280, 295)
GUICtrlCreateTabItem("Tab 1")
$Button1 = GUICtrlCreateButton("Start", 112, 144, 81, 33)
GUICtrlCreateTabItem("Tab 2")
GUICtrlCreateTabItem("Tab 3")
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

HotKeySet("{F1}", "Test")

While 1
   $nMsg = GUIGetMsg()
   Switch $nMsg
      Case $MenuItem6
         MsgBox(64, "About", "Info.")
      Case $GUI_EVENT_CLOSE, $MenuItem2
         Exit
      Case $Button1
         DoButton1()
   EndSwitch
WEnd

Func Test() ;Call for button click
;~    ControlClick("Title", "Stop", 11)
;~    ControlClick($GUI, "", $Button1)
   DoButton1()
EndFunc

Func DoButton1()
    If GUICtrlRead($Button1) = "Start" Then
        GUICtrlSetData($Button1, "Stop")
    Else
        GUICtrlSetData($Button1, "Start")
    EndIf
EndFunc

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...