How to obtain textual contents from a window

强颜欢笑 提交于 2019-12-01 10:30:09

There is an autohotkey script that emulates most of the window spy logic. It is called AHK_Window_Info_v1.7.ahk. The nice thing is... you can run it to see if your second window text if visible to this script and if so... the logic needed to pull the information is available inside the script. Here is a link to the webpage and the script is available through SKANs dropbox link on that page. http://www.autohotkey.com/board/topic/8204-ahk-window-info-17/

This routine will do the job of getting and returning from the active window the following text sections: - EdtWindowTextFastVisible - EdtWindowTextSlowVisible - EdtWindowTextFastHidden - EdtWindowTextSlowHidden

MyGetWindowText(ByRef EdtWindowTextFastVisible, ByRef EdtWindowTextSlowVisible, ByRef EdtWindowTextFastHidden,ByRef EdtWindowTextSlowHidden)
{
; Source: https://code.google.com/p/autohotkey-cn/source/browse/trunk/Source/AHK_Window_Info/AHK_Window_Info_v1.7.ahk?r=6
EdtWindowTextFastVisible =
EdtWindowTextSlowVisible =
EdtWindowTextFastHidden =
EdtWindowTextSlowHidden =

WindowControlTextSize = 32767
VarSetCapacity(WindowControlText, WindowControlTextSize)
WinGet, WindowUniqueID, ID, A

;Suggested by Chris
WinGet, ListOfControlHandles, ControlListHwnd, ahk_id %WindowUniqueID% ; Requires v1.0.43.06+.
Loop, Parse, ListOfControlHandles, `n
{
    text_is_fast := true
    If not DllCall("GetWindowText", "uint", A_LoopField, "str", WindowControlText, "int", WindowControlTextSize)
    {
        text_is_fast := false
        SendMessage, 0xD, WindowControlTextSize, &WindowControlText,, ahk_id %A_LoopField% ; 0xD is WM_GETTEXT
    }
    If (WindowControlText <> ""){
        ControlGet, WindowControlStyle, Style,,, ahk_id %A_LoopField%
        If (WindowControlStyle & 0x10000000)
        { ; Control is visible vs. hidden (WS_VISIBLE).
            If text_is_fast
            EdtWindowTextFastVisible = %EdtWindowTextFastVisible%%WindowControlText%`r`n
            Else
            EdtWindowTextSlowVisible = %EdtWindowTextSlowVisible%%WindowControlText%`r`n
        } Else
        { ; Hidden text.
            If text_is_fast
            EdtWindowTextFastHidden = %EdtWindowTextFastHidden%%WindowControlText%`r`n
            Else
            EdtWindowTextSlowHidden = %EdtWindowTextSlowHidden%%WindowControlText%`r`n
        }
    }
}

;EdtWindowTextFastVisibleFull := ShowOnlyAPartInGui("EdtWindowTextFastVisible", EdtWindowTextFastVisible, 400)
;EdtWindowTextSlowVisibleFull := ShowOnlyAPartInGui("EdtWindowTextSlowVisible", EdtWindowTextSlowVisible, 400)
;EdtWindowTextFastHiddenFull := ShowOnlyAPartInGui("EdtWindowTextFastHidden", EdtWindowTextFastHidden, 400)
;EdtWindowTextSlowHiddenFull := ShowOnlyAPartInGui("EdtWindowTextSlowHidden", EdtWindowTextSlowHidden, 400)

Return
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!