| 1 | ; #FUNCTION# ==================================================================================================================== |
|---|
| 2 | ; Name...........: _GUICtrlTab_ActivateTab |
|---|
| 3 | ; Description ...: Activates a tab by its index and sends all required messages |
|---|
| 4 | ; Syntax.........: _GUICtrlTab_ActivateTab($hWnd, $iIndex) |
|---|
| 5 | ; Parameters ....: $hWnd - Handle to control |
|---|
| 6 | ; $iIndex - Specifies the zero based index of the item |
|---|
| 7 | ; Return values .: Success - The index of the previously selected tab |
|---|
| 8 | ; Failure - -1 |
|---|
| 9 | ; Author ........: Prog@ndy |
|---|
| 10 | ; Modified.......: |
|---|
| 11 | ; Remarks .......: |
|---|
| 12 | ; Related .......: |
|---|
| 13 | ; Link ..........; |
|---|
| 14 | ; Example .......; |
|---|
| 15 | ; =============================================================================================================================== |
|---|
| 16 | Func _GUICtrlTab_ActivateTab($hWnd, $iIndex) |
|---|
| 17 | Local $nIndX, $hParent, $NMHDR, $iRet |
|---|
| 18 | ; first, get Handle and CtrlID of TabControl |
|---|
| 19 | If $hWnd = -1 Then $hWnd = GUICtrlGetHandle(-1) |
|---|
| 20 | If IsHWnd($hWnd) Then |
|---|
| 21 | $nIndX = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hWnd) |
|---|
| 22 | $nIndX = $nIndX[0] |
|---|
| 23 | Else |
|---|
| 24 | $nIndX = $hWnd |
|---|
| 25 | $hWnd = GUICtrlGetHandle($hWnd) |
|---|
| 26 | EndIf |
|---|
| 27 | ; then get Parent |
|---|
| 28 | Local $hParent = DllCall("user32.dll", "hwnd", "GetParent", "hwnd", $hWnd) |
|---|
| 29 | If @error Then Return SetError(1,0,-1) |
|---|
| 30 | $hParent = $hParent[0] |
|---|
| 31 | ; create Struct for the Messages |
|---|
| 32 | $NMHDR = DllStructCreate("HWND hwndFrom; UINT_PTR idFrom; UINT code;") |
|---|
| 33 | DllStructSetData($NMHDR, 1, $hWnd) |
|---|
| 34 | DllStructSetData($NMHDR, 2, $nIndX) |
|---|
| 35 | DllStructSetData($NMHDR, 3, $TCN_SELCHANGING) |
|---|
| 36 | ; send first message |
|---|
| 37 | _SendMessage($hParent, 0x4E, $nIndX, DllStructGetPtr($NMHDR)) |
|---|
| 38 | ; select TabItem |
|---|
| 39 | $iRet = _GUICtrlTab_SetCurSel($hWnd, $iIndex) |
|---|
| 40 | ; send second message |
|---|
| 41 | DllStructSetData($NMHDR, 3, $TCN_SELCHANGE) |
|---|
| 42 | _SendMessage($hParent, 0x4E, $nIndX, DllStructGetPtr($NMHDR)) |
|---|
| 43 | Return $iRet |
|---|
| 44 | EndFunc |
|---|