AHKV1:使用ControlGet,是否还可以获取列标题名称和项目?

问题描述 投票:0回答:1

我可以使用

SysListView321
获取
ControlGet
的项目:

ControlGet, OutputVar, List,, SysListView321, Options ahk_class #32770 ahk_exe Ditto.exe
Console(OutputVar)

Console()
输出:

    Apply Last Search
Alt + C Cancel Filter
Alt + ENTER Clip Properties
ESC Close Window
Ctrl + F2   Compare Selected Clips
Ctrl + C    Copy Selection
    Decrease Transparency %
    Delete all non used clips
    Delete Clip Data
Ctrl + E    Edit Clip
    EMail, Clip Export As Attachment
    EMail, Content As Attachment
    EMail, Content In Body
    Export To Google Translate
    Export To Image File
    Export To QR Code
    Export To Text File
    Filter On Selected Clip
Shift + ESC Force Close Window
    Global HotKeys
    Gmail
...

这很整洁。但是否也可以包含列标题的名称?

例如,在我正在使用的WINDOW中,标题是

Hot key
Command
。我四处寻找但没有找到任何东西。

也许这可以通过另一个命令来完成?即使它是外部库,我也愿意接受建议

谢谢你帮助我。

autohotkey
1个回答
0
投票

由于Alguimist的回答,我知道了如何做到这一点。在所有潜在的解决方案中,他们的解决方案是唯一可以让我远程完成此操作的解决方案,即无需激活控制窗口。

实现“远程”执行此操作的方法至关重要,因为我打算将其用于 PowerShell 模块,该模块获取 Windows 控件的值,例如组合框、按钮、编辑等。

Alguimist 的源代码:

    ;https://www.autohotkey.com/boards/viewtopic.php?p=231012#p231012
    ; Returns an object containing the text and width of each item of a remote SysHeader32 control
    CTRL_GetHeader(hHeader){
        Static MAX_TEXT_LENGTH := 260
            , MAX_TEXT_SIZE := MAX_TEXT_LENGTH * (A_IsUnicode ? 2 : 1)

        WinGet PID, PID, ahk_id %hHeader%

        ; Open the process for read/write and query info.
        ; PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION | PROCESS_QUERY_INFORMATION
        If !(hProc := DllCall("OpenProcess", "UInt", 0x438, "Int", False, "UInt", PID, "Ptr")) {
            Return
        }

        ; Should we use the 32-bit struct or the 64-bit struct?
        If (A_Is64bitOS) {
            Try DllCall("IsWow64Process", "Ptr", hProc, "int*", Is32bit := true)
        } Else {
            Is32bit := True
        }

        RPtrSize := Is32bit ? 4 : 8
        cbHDITEM := (4 * 6) + (RPtrSize * 6)

        ; Allocate a buffer in the (presumably) remote process.
        remote_item := DllCall("VirtualAllocEx", "Ptr", hProc, "Ptr", 0
                                    , "uPtr", cbHDITEM + MAX_TEXT_SIZE
                                    , "UInt", 0x1000, "UInt", 4, "Ptr") ; MEM_COMMIT, PAGE_READWRITE
        remote_text := remote_item + cbHDITEM

        ; Prepare the HDITEM structure locally.
        VarSetCapacity(HDITEM, cbHDITEM, 0)
        NumPut(0x3, HDITEM, 0, "UInt") ; mask (HDI_WIDTH | HDI_TEXT)
        NumPut(remote_text, HDITEM, 8, "Ptr") ; pszText
        NumPut(MAX_TEXT_LENGTH, HDITEM, 8 + RPtrSize * 2, "Int") ; cchTextMax

        ; Write the local structure into the remote buffer.
        DllCall("WriteProcessMemory", "Ptr", hProc, "Ptr", remote_item, "Ptr", &HDITEM, "uPtr", cbHDITEM, "Ptr", 0)

        HDInfo := {}
        VarSetCapacity(HDText, MAX_TEXT_SIZE)

        SendMessage 0x1200, 0, 0,, ahk_id %hHeader% ; HDM_GETITEMCOUNT
        Loop % (ErrorLevel != "FAIL") ? ErrorLevel : 0 {
            ; Retrieve the item text.
            SendMessage, % (A_IsUnicode) ? 0x120B : 0x1203, A_Index - 1, remote_item,, ahk_id %hHeader% ; HDM_GETITEMW
            If (ErrorLevel == 1) { ; Success
                DllCall("ReadProcessMemory", "Ptr", hProc, "Ptr", remote_item, "Ptr", &HDITEM, "uPtr", cbHDITEM, "Ptr", 0)
                DllCall("ReadProcessMemory", "Ptr", hProc, "Ptr", remote_text, "Ptr", &HDText, "uPtr", MAX_TEXT_SIZE, "Ptr", 0)
            } Else {
                HDText := ""
            }

            HDInfo.Push({"Width": NumGet(HDITEM, 4, "UInt"), "Text": HDText})
        }

        ; Release the remote memory and handle.
        DllCall("VirtualFreeEx", "Ptr", hProc, "Ptr", remote_item, "UPtr", 0, "UInt", 0x8000) ; MEM_RELEASE
        DllCall("CloseHandle", "Ptr", hProc)

        Return HDInfo
    }
© www.soinside.com 2019 - 2024. All rights reserved.