私はpywin32TTM_GETTEXT
を使用して使用しようとしています。SendMessage
問題は、lparam
テキストを格納する場所である の構造が である必要があることですTOOLINFO
。これは、MSDN で十分に文書化されていますが、pywin32 には対応するものはありません。Python と pywin32 を使用して同じ構造を作成する方法はありますか?
編集:を使用して思いついたコードは次のとおりですctypes
。Structure
forをTOOLINFO
作成し、そこからバッファを作成して pywin32 の に渡しSendMessage
、それをTOOLINFO
ctypes
Structure
. 唯一の問題は、それが機能していないことです:
# My TOOLINFO struct:
class TOOLINFO(Structure):
_fields_ = [("cbSize", UINT),
("uFlags", UINT),
("hwnd", HWND),
("uId", POINTER(UINT)),
("rect", RECT),
("hinst", HINSTANCE),
("lpszText", LPWSTR),
("lpReserved", c_void_p)]
# send() definition from PythonInfo wiki FAQs
def send(self):
return buffer(self)[:]
ti = TOOLINFO()
text = ""
ti.cbSize = sizeof(ti)
ti.lpszText = text # buffer to store text in
ti.uId = pointer(UINT(wnd)) # wnd is the handle of the tooltip
ti.hwnd = w_wnd # w_wnd is the handle of the window containing the tooltip
ti.uFlags = commctrl.TTF_IDISHWND # specify that uId is the control handle
ti_buffer = send(ti) # convert to buffer for pywin32
del(ti)
win32gui.SendMessage(wnd, commctrl.TTM_GETTEXT, 256, ti_buffer)
ti = TOOLINFO() # create new TOOLINFO() to copy result to
# copy result (according to linked article from Jeremy)
memmove(addressof(ti), ti_buffer, sizeof(ti))
if ti.lpszText:
print ti.lpszText # print any text recovered from the tooltip
テキストは印刷されていませんが、抽出したいツールチップのテキストが含まれているはずだと思いました。の使用方法に何か問題がありctypes
ますか? wnd
と の値が正しいと確信しているw_wnd
ので、何か間違ったことをしているに違いありません。