您可以使用Twapi的原始API發送消息。我不是fammilar與具體細節此消息是如何工作的,但你知道,可能比我更好:
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 API,唯一的文檔twapi的源代碼。
如果你想獲得豐富的行數,使用':: twapi :: SendMessageTimeout $ hwnd 0x00BA 0 0 0x0008 1000'。 (EM_GETLINECOUNT) –
感謝您的詳細示例。不幸的是,當試圖使用proc時,我得到「無效的命令名」twapi :: Twapi_WriteMemory「」。我使用TWAPI 3.1.17。它在你的機器上工作嗎? – Lumpi
在TWAPI源代碼中,我(和TCL)無法找到「:: twapi :: pointer_to_address」。你使用了哪個版本? – Lumpi