ioa747 Posted Monday at 04:54 PM Posted Monday at 04:54 PM (edited) And an alternative because it was spinning in my mind (for more whimsical cases, like $id_CheckBox_Out2) expandcollapse popup; https://www.autoitscript.com/forum/topic/213665-how-can-i-detect-if-a-control-is-within-a-tab-control/#findComment-1552092 #AutoIt3Wrapper_UseX64=n #include <GuiTab.au3> #include <GUIConstantsEx.au3> #include <WinAPISysWin.au3> #include <Array.au3> ; initiate System DPI awareness DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -2) Example() Func Example() Local $hGUI_Main = GUICreate("My GUI Tab", 400, 180) GUISetBkColor(0x808080) GUISetFont(9, 300) Local $id_Tab_Main = GUICtrlCreateTab(10, 10, 200, 100) Local $id_Tab_0 = GUICtrlCreateTabItem("Tab 0") Local $id_CheckBox_0 = GUICtrlCreateCheckbox("Checkbox 0", 20, 50) Local $id_Tab_1 = GUICtrlCreateTabItem("Tab 1") GUICtrlSetState(-1, $GUI_SHOW) ; will be display first Local $id_CheckBox_1 = GUICtrlCreateCheckbox("Checkbox 1", 20, 50) Local $id_Tab_2 = GUICtrlCreateTabItem("Tab 2") Local $id_CheckBox_2 = GUICtrlCreateCheckbox("Checkbox 2", 20, 50) Local $id_CheckBox_Out2 = GUICtrlCreateCheckbox("Checkbox outside the TAB area", 0, 150) GUICtrlCreateTabItem("") ; end tabitem definition Local $id_CheckBox_Out = GUICtrlCreateCheckbox("Checkbox outside the TAB area", 20, 120) GUISetState(@SW_SHOW) Local $aTabCtrls = _GetTabControlsMap_Advanced($hGUI_Main, $id_Tab_Main) ;~ _ArrayDisplay($aTabCtrls) If Not @error Then For $i = 0 To UBound($aTabCtrls) - 1 Local $aCtrls = StringSplit($aTabCtrls[$i], "|") ConsoleWrite("Tab:" & $i & " -> ctrls: ") For $j = 1 To $aCtrls[0] ConsoleWrite($aCtrls[$j] & ($j < $aCtrls[0] ? ", " : "")) Next ConsoleWrite("" & @CRLF) Next EndIf Local $idMsg ; Loop until the user exits. While 1 $idMsg = GUIGetMsg() If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>Example Func _GetTabControlsMap_Advanced($hGUI, $idTab) Local $iTotalTabs = _GUICtrlTab_GetItemCount($idTab) ConsoleWrite("- $iTotalTabs=" & $iTotalTabs & @CRLF) If $iTotalTabs < 2 Then Return SetError(1, 0, 0) Local $aTabMap[$iTotalTabs] Local $iActiveTab = GUICtrlRead($idTab) ; Save current position ConsoleWrite("- $iActiveTab=" & $iActiveTab & @CRLF) Local $aHide, $aHide2 $aHide = _GetControlsByState($hGUI) For $i = 0 To UBound($aTabMap) - 1 If $i = $iActiveTab Then ContinueLoop _GUICtrlTab_ClickTab($idTab, $i) Sleep(10) $aHide2 = _GetControlsByState($hGUI) Local $sTabInh = "" For $j = 1 To $aHide[0][0] If $aHide2[$j][1] & $aHide[$j][1] = "10" Then $sTabInh &= $aHide[$j][0] & "|" Next If StringRight($sTabInh, 1) = "|" Then $sTabInh = StringTrimRight($sTabInh, 1) $aTabMap[$i] = $sTabInh Next _GUICtrlTab_ClickTab($idTab, $iActiveTab) $sTabInh = "" If Not IsArray($aHide2) Then Return SetError(2, 0, 0) For $j = 1 To $aHide[0][0] If $aHide[$j][1] & $aHide2[$j][1] = "10" Then $sTabInh &= $aHide[$j][0] & "|" Next If StringRight($sTabInh, 1) = "|" Then $sTabInh = StringTrimRight($sTabInh, 1) $aTabMap[$iActiveTab] = $sTabInh Return $aTabMap EndFunc ;==>_GetTabControlsMap_Advanced Func _GetControlsByState($hGUI) Local $aChildHandles = _WinAPI_EnumChildWindows($hGUI, False) If @error Then Return SetError(1, 0, 0) Local $aFound[$aChildHandles[0][0] + 1][2] $aFound[0][0] = $aChildHandles[0][0] For $i = 1 To $aChildHandles[0][0] Local $hCtrl = $aChildHandles[$i][0] ; convert the Handle to ID Local $idCtrl = _WinAPI_GetDlgCtrlID($hCtrl) Local $bVisible = ControlCommand($hGUI, "", $hCtrl, "IsVisible", "") $aFound[$i][0] = $idCtrl $aFound[$i][1] = $bVisible Next Return $aFound EndFunc Edited Monday at 05:27 PM by ioa747 update WildByDesign 1 I know that I know nothing
WildByDesign Posted Monday at 08:17 PM Author Posted Monday at 08:17 PM 3 hours ago, ioa747 said: And an alternative because it was spinning in my mind (for more whimsical cases, like $id_CheckBox_Out2) You very often have wonderful and creative ideas. I like the way that you think. Thanks for sharing. ioa747 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now