Die Funktion markiert _GUICtrlTab_SetCurSel wählt nur einen bestimmten Tab als aktiv, lässt jedoch nicht die Anzeige des Inhalts wechseln. Diese Funktion sendet alle nötigen Nachrichten, um beim Tabwechsel auch den Inhalt zu aktualisieren.
UDF + Beispiel
#include <GuiTab.au3>
[/autoit] [autoit][/autoit] [autoit]Global $hGUI = GUICreate("Testing tab switch", 400, 50, -1, -1)
Global $ctrlTab = GUICtrlCreateTab(2, 2, 396, 20)
Global $hTab = ControlGetHandle($hGUI, "", $ctrlTab)
For $n = 0 To 4
GUICtrlCreateTabItem("Tab" & $n)
GUICtrlCreateLabel("This is tab " & $n, 2, 24, 396, 20)
Next
GUICtrlCreateTabItem("")
GUIRegisterMsg(0x020A, "_TabSwitch"); WM_MOUSEWHEEL
GUISetState()
While 1
Switch GUIGetMsg()
Case - 3
Exit
EndSwitch
WEnd
Func _TabSwitch($hwnd, $msg, $l, $r)
Local $nCur = GUICtrlSendMsg($ctrlTab, $TCM_GETCURSEL, 0, 0)
ConsoleWrite("Debug: $nCur = " & $nCur & @LF)
If $l = 0xFF880000 Then
; Mouse wheel up
If $nCur = 0 Then
_GUICtrlTab_ActivateTab($hTab, _GUICtrlTab_GetItemCount($hTab) - 1)
Else
_GUICtrlTab_ActivateTab($hTab, $nCur - 1)
EndIf
Else
; Mouse wheel down
If $nCur = _GUICtrlTab_GetItemCount($hTab) - 1 Then
_GUICtrlTab_ActivateTab($hTab, 0)
Else
_GUICtrlTab_ActivateTab($hTab, $nCur + 1)
EndIf
EndIf
EndFunc ;==>_TabSwitch
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlTab_ActivateTab
; Description ...: Activates a tab by its index and sends all required messages
; Syntax.........: _GUICtrlTab_ActivateTab($hWnd, $iIndex)
; Parameters ....: $hWnd - Handle to control
; $iIndex - Specifies the zero based index of the item
; Return values .: Success - The index of the previously selected tab
; Failure - -1
; Author ........: Prog@ndy
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
; ===============================================================================================================================
Func _GUICtrlTab_ActivateTab($hWnd, $iIndex)
Local $nIndX, $hParent, $NMHDR, $iRet
; first, get Handle and CtrlID of TabControl
If $hWnd = -1 Then $hWnd = GUICtrlGetHandle(-1)
If IsHWnd($hWnd) Then
$nIndX = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hWnd)
$nIndX = $nIndX[0]
Else
$nIndX = $hWnd
$hWnd = GUICtrlGetHandle($hWnd)
EndIf
; then get Parent
Local $hParent = DllCall("user32.dll", "hwnd", "GetParent", "hwnd", $hWnd)
If @error Then Return SetError(1,0,-1)
$hParent = $hParent[0]
; create Struct for the Messages
$NMHDR = DllStructCreate("HWND hwndFrom; UINT_PTR idFrom; UINT code;")
DllStructSetData($NMHDR, 1, $hWnd)
DllStructSetData($NMHDR, 2, $nIndX)
DllStructSetData($NMHDR, 3, $TCN_SELCHANGING)
; send first message
_SendMessage($hParent, 0x4E, $nIndX, DllStructGetPtr($NMHDR))
; select TabItem
$iRet = _GUICtrlTab_SetCurSel($hWnd, $iIndex)
; send second message
DllStructSetData($NMHDR, 3, $TCN_SELCHANGE)
_SendMessage($hParent, 0x4E, $nIndX, DllStructGetPtr($NMHDR))
Return $iRet
EndFunc