Jump to content

How to find tab by text and click it?


Recommended Posts

Try this

#include <GUIConstantsEx.au3>
#include <GuiTab.au3>

GUICreate("My GUI Tab") ; will create a dialog box that when displayed is centered

GUISetBkColor(0x00E0FFFF)
GUISetFont(9, 300)

Global $tabMainTab = GUICtrlCreateTab(10, 10, 200, 100)

GUICtrlCreateTabItem("tab0")
GUICtrlCreateLabel("label0", 30, 80, 50, 20)
GUICtrlCreateButton("OK0", 20, 50, 50, 20)
GUICtrlCreateInput("default", 80, 50, 70, 20)

GUICtrlCreateTabItem("tab----1")
GUICtrlCreateLabel("label1", 30, 80, 50, 20)
GUICtrlCreateCombo("", 20, 50, 60, 120)
GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo|guinness", "Jon") ; default Jon
GUICtrlCreateButton("OK1", 80, 50, 50, 20)

GUICtrlCreateTabItem("tab2")
GUICtrlSetState(-1, $GUI_SHOW) ; will be display first
GUICtrlCreateLabel("label2", 30, 80, 50, 20)
GUICtrlCreateButton("OK2", 140, 50, 50)

GUICtrlCreateTabItem("") ; end tabitem definition

Global $btnClick = GUICtrlCreateButton("Select tab 2", 10, 130, 100, 20)

GUISetState(@SW_SHOW)

Local $idMsg
; Loop until the user exits.
While 1
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE
            Exit 0
        Case $btnClick
            _GUICtrlTab_ActivateTabEx($tabMainTab, "tab0")
    EndSwitch
WEnd

Func _GUICtrlTab_ActivateTabEx($hWnd, $sText)
    Local $hTab = IsHWnd($hWnd) ? $hWnd : GUICtrlGetHandle($hWnd)
    For $i = 0 To _GUICtrlTab_GetItemCount($hTab)
        If (_GUICtrlTab_GetItemText($hTab, $i) = $sText) Then
            _GUICtrlTab_ActivateTab($hTab, $i)
            ExitLoop
        EndIf
    Next
EndFunc   ;==>_GUICtrlTab_ActivateTabEx

 

Link to comment
Share on other sites

9 minutes ago, Danp2 said:

First suggestion would be to do some error handling. Check the @error flag after the call to ControlGetHandle.

I checked. No error occurs after ControlGetHandle.

And this

ControlCommand ( $hTab, "", "", "TabRight")

is working with this handle, but I can't get text of current tab.

And ControlClick is still not working...

Link to comment
Share on other sites

3 minutes ago, InunoTaishou said:

Try this

#include <GUIConstantsEx.au3>
#include <GuiTab.au3>

GUICreate("My GUI Tab") ; will create a dialog box that when displayed is centered

GUISetBkColor(0x00E0FFFF)
GUISetFont(9, 300)

Global $tabMainTab = GUICtrlCreateTab(10, 10, 200, 100)

GUICtrlCreateTabItem("tab0")
GUICtrlCreateLabel("label0", 30, 80, 50, 20)
GUICtrlCreateButton("OK0", 20, 50, 50, 20)
GUICtrlCreateInput("default", 80, 50, 70, 20)

GUICtrlCreateTabItem("tab----1")
GUICtrlCreateLabel("label1", 30, 80, 50, 20)
GUICtrlCreateCombo("", 20, 50, 60, 120)
GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo|guinness", "Jon") ; default Jon
GUICtrlCreateButton("OK1", 80, 50, 50, 20)

GUICtrlCreateTabItem("tab2")
GUICtrlSetState(-1, $GUI_SHOW) ; will be display first
GUICtrlCreateLabel("label2", 30, 80, 50, 20)
GUICtrlCreateButton("OK2", 140, 50, 50)

GUICtrlCreateTabItem("") ; end tabitem definition

Global $btnClick = GUICtrlCreateButton("Select tab 2", 10, 130, 100, 20)

GUISetState(@SW_SHOW)

Local $idMsg
; Loop until the user exits.
While 1
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE
            Exit 0
        Case $btnClick
            _GUICtrlTab_ActivateTabEx($tabMainTab, "tab0")
    EndSwitch
WEnd

Func _GUICtrlTab_ActivateTabEx($hWnd, $sText)
    Local $hTab = IsHWnd($hWnd) ? $hWnd : GUICtrlGetHandle($hWnd)
    For $i = 0 To _GUICtrlTab_GetItemCount($hTab)
        If (_GUICtrlTab_GetItemText($hTab, $i) = $sText) Then
            _GUICtrlTab_ActivateTab($hTab, $i)
            ExitLoop
        EndIf
    Next
EndFunc   ;==>_GUICtrlTab_ActivateTabEx

 

Thank You for reply.

But window and controls are not created with AutoIt. GUI created by unknown developer with Delphi and .NET as I see

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...