Описание функции


WinGetHandle

Разделяет строку и создаёт массив из элементов.

hwnd = WinGetHandle(hwnd, text.s [, instance = 1 [, type = 0 [, match = 0 ]]])

Параметры

hwnd Дескриптор родительского окна, или 0 если любое окно, а родитель рабочий стол
text.s Строка, заголовок или класс окна.
instance Номер экземпляра, например если две кнопки с одинаковым именем или классом, то 2 подразумевает 2-ю кнопку. Отсчёт от 1
type 0 - Заголовок окна / текст элемента
1 - Класс окна/элемента
match 0 - точное совпадение
1 - совпадение от начала
2 - текст встречается в названии

Возвращаемое значение

Возвращает дескриптор или 0, если ничего не найдено.

Пример

; AZJIO
; https://www.purebasic.fr/english/viewtopic.php?t=80897

EnableExplicit

Structure ResStr
    s.s
    r.s
    slen.i
    rlen.i
    hwnd.l
    match.l
    type.l
    instance.l
EndStructure

Enumeration
    #Title
    #Class
EndEnumeration

; Finding Window
Procedure.l enumChildren(hwnd.l, *s.ResStr)
    Static n.l = 0
    If hwnd
        Select *s\type
            Case 0
                GetWindowText_(hwnd, @*s\r, *s\rlen)
            Case 1
                GetClassName_(hwnd, @*s\r, *s\rlen)
        EndSelect
        Select *s\match
            Case 0
                If *s\r = *s\s
                    n + 1
                    If n = *s\instance
                        n = 0
                        Debug *s\r
                        *s\hwnd = hwnd
                        ProcedureReturn 0
                    EndIf
                EndIf
            Case 1
                If Left(*s\r, *s\slen) = *s\s
                    n + 1
                    If n = *s\instance
                        n = 0
                        Debug *s\r
                        *s\hwnd = hwnd
                        ProcedureReturn 0
                    EndIf
                EndIf
            Case 2
                If FindString(*s\r, *s\s, 1, #PB_String_NoCase)
                    n + 1
                    If n = *s\instance
                        n = 0
                        Debug *s\r
                        *s\hwnd = hwnd
                        ProcedureReturn 0
                    EndIf
                EndIf
        EndSelect
        ProcedureReturn 1
    EndIf
    n = 0
    ProcedureReturn 0
EndProcedure

; type
;     0 - Title
;     1 - Class
; match
;     0 - exact match
;     1 - match from start
;     2 - the word occurs in the title
Procedure.l WinGetHandle(hwnd, text.s, instance = 1, type = 0, match = 0)
    Protected s.ResStr
    s\rlen = 256
    s\r = Space(s\rlen)
    s\s = text
    s\slen = Len(text)
    s\match = match
    s\type = type
    s\instance = instance
    EnumChildWindows_(hwnd, @enumChildren(), @s)
    ProcedureReturn s\hwnd
EndProcedure

Define hwnd
; Debug WinGetHandle(0, "PureBasic", 1, #Title)
; Debug WinGetHandle(0, "LTS", 1, #Title, 2)

; hwnd = WinGetHandle(0, "WindowClass_2", 1, #Class, 0) ; PureBasic
; Debug Hex(hwnd)
; If hwnd
;     hwnd = WinGetHandle(hwnd, "Scintilla", 1, #Class, 0) ; PureBasic -> Scintilla
;     Debug Hex(hwnd)
; EndIf

; hwnd = WinGetHandle(0, "Properties", 1, #Title, 1) ; Properties
hwnd = WinGetHandle(0, "#32770", 1, #Class, 0) ; #32770
Debug Hex(hwnd)
If hwnd
    hwnd = WinGetHandle(hwnd, "Button", 4, #Class, 0) ; Properties -> Others
    Debug Hex(hwnd)
EndIf
; SendMessage_(hwnd, #BM_CLICK, 0, 0)

; Add a size check
; Define win.RECT
; GetWindowRect_(hwnd, win)
; If class = "#32770" And (win\bottom - win\top) = 111 And (win\right - win\left) = 333
; EndIf