J'essaie d'utiliser TTM_GETTEXT
via SendMessage
en utilisant pywin32. le problème est que la structure du lparam
, où le texte doit être stocké, doit être TOOLINFO
, ce qui est bien documenté dans MSDN, mais n'a pas d'équivalent dans pywin32. est-il un moyen de créer la même structure en utilisant python et pywin32?convertir des structures en c en pywin32?
Editer: Voici le code que j'ai trouvé en utilisant ctypes
. J'ai fait un Structure
pour TOOLINFO
, créé un tampon de lui pour passer à SendMessage
de pywin32, puis l'ai converti en TOOLINFO
ctypes
Structure
. Le seul problème est, il ne fonctionne pas:
# 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
texte ne sont pas en cours d'impression, mais je suppose qu'il doit contenir le texte de l'info-bulle que je veux extraire. Y at-il quelque chose qui ne va pas avec comment j'ai utilisé le ctypes
? Je suis tout à fait sûr que mes valeurs pour wnd
et w_wnd
sont correctes, donc je dois faire quelque chose de mal.
'ctypes' fière allure, mais je suis trop profond avec pywin32 déjà pour basculer. mais le module struct semble bon aussi. Je pourrais aller avec l'approche 'struct'. Merci! – maranas