Winapi 使用TWAPI获取RichEdit50W窗口的文本

Winapi 使用TWAPI获取RichEdit50W窗口的文本,winapi,tcl,Winapi,Tcl,我想检索特定窗口的文本。使用 twapi::get_window_text $handle 我得到窗口的标题。但是我怎样才能得到实际的内容呢?在C++中,我使用了 EM_GETLINE 如何使用来自TCL的这些原始Windows API函数?例如,对于EM_GETLINE,我必须定义要提取的行数以及它们存储的缓冲区 有人能告诉我如何使用TCL中的原始Windows API函数吗?或者给我指一个可以找到示例的站点?谢谢您可以使用Twapi的原始API发送消息。我不太了解这条信息的具体工作原理

我想检索特定窗口的文本。使用

twapi::get_window_text $handle 
我得到窗口的标题。但是我怎样才能得到实际的内容呢?在C++中,我使用了

EM_GETLINE
如何使用来自TCL的这些原始Windows API函数?例如,对于EM_GETLINE,我必须定义要提取的行数以及它们存储的缓冲区


有人能告诉我如何使用TCL中的原始Windows API函数吗?或者给我指一个可以找到示例的站点?谢谢

您可以使用Twapi的原始API发送消息。我不太了解这条信息的具体工作原理,但你们可能比我更清楚:

package require twapi
proc get_richedit_text {hwnd line} {
    set MAX_LEN 0x0100
    # You have to lookup this value in the header.
    set EM_GETLINE 0x00C4
    set bufsize [expr {2 * ($MAX_LEN + 1)}]
    # yes, twapi has malloc.
    set szbuf [twapi::malloc $bufsize]
    # catch everything, so we can free the buffer.
    catch {
        # set the first word to the size. Whatever a word is.
        # I assume it is an int (type 1), but if it is a int64, use type 5, wchar is 3.
        # arguments to Twapi_WriteMemory: type pointer(void*) offset bufferlen value 
        twapi::Twapi_WriteMemory 1 $szbuf 0 $bufsize $MAX_LEN
        # send the message. You don't have SendMessage, only SendMessageTimeout
        set ressize [twapi::SendMessageTimeout $hwnd $EM_GETLINE $line [twapi::pointer_to_address $szbuf] 0x0008 1000]
        return [twapi::Twapi_ReadMemory 3 $szbuf 0 [expr {$ressize * 2}]]
    } res opt
    # free the buffer.
    twapi::free $szbuf
    return -options $opt $res
}

我使用了一些内部/未记录的twapi,唯一的文档是twapi的源代码。

如果要获取richedit中的行数,请使用
::twapi::SendMessageTimeout$hwnd 0x00BA 0 0x0008 1000
。(EM_GETLINECOUNT)感谢您提供的详细示例。不幸的是,在尝试使用proc时,我得到了“无效的命令名”twapi::twapi_WriteMemory“”。我使用TWAPI 3.1.17。它在您的机器上工作吗?在TWAPI源代码中,我(和TCL)也找不到“::TWAPI::pointer_to_address”。你用的是哪个版本?我用的是4.0b22。这是一个测试版。我找到了命令
::twapi::twapi_WriteMemoryInt
::twapi::twapi_PtrToAddress
::twapi::twapi_ReadMemoryUnicode
。这是内部API的缺点。我注意到我在3.1.17中发现了这个命令。虽然我没有测试,但它们应该可以工作。另一种方法是编写自己的Tcl扩展。(twapi返回的句柄只是一个列表。第一个元素是地址,第二个元素是类型,例如
12345 HWND