Имя пользователя:
Пароль:
 

Показать сообщение отдельно

Аватара для Creat0R

Must AutoIt


Сообщения: 3054
Благодарности: 1009

Профиль | Сайт | Отправить PM | Цитировать


amel27,
Цитата:
видимо он используется для других нужд
Ладно, всё ровно спасибо, API для меня предпочтительнее объектов/WMI и т.п.




Самому как то давно (и кажется тут в ветке уже спрашивали про это), нужна была функция для получения текста с таба (SysTabControl321), поискал немного, не нашёл и разочаровался .
Но недавно кое кому тоже это понадобилось, и я сразу вспомнил про библиотеку A3LLibrary - Но ради одной функции включать такую тяжёлую артиллерию, мне показалось излишним ..

Собрав все нужные ресурсы с этой библиотеки, плюс немного с MSDN, плюс немного с головы (моей ), я написал рабочую функцию _ControlTab()!!! аж самому не верится, но всё прекрасно работает!

Вот функция с описаниями (на Английском, т.к на оф. форуме хочу предложить разработчикам для включения в стандартные библиотеки):

Код: Выделить весь код
;===============================================================================
; Function Name:   _ControlTab()
; Description:     Sends a command to a SysTab32 Control.
; Syntax:          _ControlTab ( $hWnd, $sText, $sCommand  [, $sParam1 [, $sParam2 [, $sParam3]]] )
;
; Parameter(s):    $hWnd       = Window Handle/Title.
;                  $sText      = Window Text.
;                  $sCommand   = Command to send to the control (See "Return Value(s)").
;                  $sParam1, $sParam2, $sParam3 = Additional parameters required by some commands.
;
; Requirement(s): None.
;
; Return Value(s): Depends on command as shown below. In case of an error (such as an invalid command or window/control), @error=1
;                       If $sCommand Equel...
;                          "GetItemState" - State of the tab item returned.
;                            ($sParam1 defines what tab item (zero-based) will be used - 0 is the default).
;
;                          "GetItemText" - Text of the tab item returned.
;                            ($sParam1 defines what tab item (zero-based) will be used - 0 is the default).
;
;                          "GetItemImage" - Image Index of the tab item returned.
;                            ($sParam1 defines what tab item (zero-based) will be used - 0 is the default).
;
;                          "CurrentTab" - Returns the current Tab shown of a SysTabControl32.
;
;                          "TabRight" - Moves to the next tab to the right of a SysTabControl32.
;
;                          "TabLeft" - Moves to the next tab to the left of a SysTabControl32.
;
;                          "GetTabsCount" - Returns the number of total tab items of a SysTabControl32.
;
;                          "FindTab" - Search For tab item with specific text..
;                          In this case used all three additional parameters:
;                               $sParam1 - defines what text to find.
;                               $sParam2 - defines from what tab item the search will start (zero-based).
;                               $sParam3 - defines search type...
;                               If $sParam3 = True Then will be performed a partial search of the string in the tab item text.
;
; Author(s):       G.Sandler a.k.a CreatoR
;
; Example(s):
;     $TabText = _ControlTab("Properties", "", "GetItemText", 1) ;Will return the text of second tab from the left side.
;===============================================================================
Func _ControlTab($hWnd, $sText, $sCommand, $sParam1="", $sParam2="", $sParam3="")
    Local Const $TCM_FIRST = 0x1300
    Local $hTab = ControlGetHandle($hWnd, $sText, "SysTabControl321")

    Switch $sCommand
        Case "GetItemState", "GetItemText", "GetItemImage"
            Local Const $TagTCITEM = "int Mask;int State;int StateMask;ptr Text;int TextMax;int Image;int Param"
            Local Const $TCIF_ALLDATA = 0x0000001B
            Local Const $TCM_GETITEM = $TCM_FIRST + 5

            Local $tBuffer  = DllStructCreate("char Text[4096]")
            Local $pBuffer  = DllStructGetPtr($tBuffer)
            Local $tItem    = DllStructCreate($tagTCITEM)
            Local $pItem    = DllStructGetPtr($tItem)

            DllStructSetData($tItem, "Mask", $TCIF_ALLDATA)
            DllStructSetData($tItem, "TextMax", 4096)
            DllStructSetData($tItem, "Text", $pBuffer)

            If $sParam1 = -1 Then $sParam1 = _ControlTab($hWnd, $sText, "CurrentTab")
            DllCall("user32.dll", "long", "SendMessage", "hwnd", $hTab, "int", $TCM_GETITEM, "int", $sParam1, "int", $pItem)

            If @error Then Return SetError(1, 0, "")
            If $sCommand = "GetItemState" Then Return DllStructGetData($tItem, "State")
            If $sCommand = "GetItemText" Then Return DllStructGetData($tBuffer, "Text")
            If $sCommand = "GetItemImage" Then Return DllStructGetData($tItem, "Image")
        Case "CurrentTab", "TabRight", "TabLeft"
            Local $iRet = ControlCommand($hWnd, $sText, "SysTabControl321", $sCommand, "")
            If @error Then Return SetError(1, 0, -1)
            Return $iRet - 1
        Case "GetTabsCount"
            Local Const $TCM_GETITEMCOUNT = $TCM_FIRST + 4
            Local $iRet = DllCall("user32.dll", "long", "SendMessage", "hwnd", $hTab, "int", $TCM_GETITEMCOUNT, "int", 0, "int", 0)
            If @error Then Return SetError(1, 0, -1)
            Return $iRet[0]
        Case "FindTab"
            If Not IsNumber($sParam2) Or $sParam2 < 0 Then $sParam2 = 0
            Local $sTabText

            For $i = $sParam2 To _ControlTab($hWnd, $sText, "GetTabsCount")
                $sTabText = _ControlTab($hWnd, $sText, "GetItemText", $i)
                If $sParam3 = True And StringInStr($sTabText, $sParam1) Then Return $i
                If $sTabText = $sParam1 Then Return $i
            Next
            Return -1
        Case Else
            Return SetError(1, 0, "")
    EndSwitch
EndFunc
Вот пример:

Код: Выделить весь код
$GUI = GUICreate("ControlTab Demo")

GUICtrlCreateTab(0, 20)
$Tab_1 = GUICtrlCreateTabItem("Tab 1")
$Tab_2 = GUICtrlCreateTabItem("Tab 2")
$Tab_3 = GUICtrlCreateTabItem("More Tab")

GUISetState()

For $i = 0 To _ControlTab($GUI, "", "GetTabsCount")-1
    MsgBox(0, "", "Zero-Based tab number [" & $i & "]: " & @LF & _ControlTab($GUI, "", "GetItemText", $i))
    _ControlTab($GUI, "", "TabRight")
Next

-------
“Сделай так просто, как возможно, но не проще этого.”... “Ты никогда не решишь проблему, если будешь думать так же, как те, кто её создал.”

Альберт Эйнштейн

P.S «Не оказываю техподдержку через ПМ/ICQ, и по email - для этого есть форум. ©»

http://creator-lab.ucoz.ru/Images/Icons/autoit_icon.png Русское сообщество AutoIt | http://creator-lab.ucoz.ru/Images/Ic...eator_icon.png CreatoR's Lab | http://creator-lab.ucoz.ru/Images/Icons/oac_icon.png Opera AC Community


Отправлено: 23:38, 15-11-2007 | #730