Retrieve traytip text using TTM_GetText message

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
RijulAhuja
Posts: 44
Joined: 30 Sep 2013, 07:29

Retrieve traytip text using TTM_GetText message

25 Oct 2013, 08:15

I was looking at some old threads and found this TTM_GetText message which can be used to retrieve tooltip / traytip text.
I attempted to try and solve some of it, but I'm missing something, could anybody tell ?

Code: Select all

TrayTip, % Title:="Title", % Text:="Text"
DetectHiddenWindows, On
wParam:=StrLen(Text)+1
cbSize:=4+4+A_PtrSize+(A_Is64bitOS ? 8 : 4)+16+A_PtrSize+( wParam * (A_IsUnicode) ? 2 : 1 )
FileGetVersion, _WIN32_IE, %A_ProgramFiles%\Internet Explorer\iexplore.exe
If (floor(_WIN32_IE)>=3)
	cbSize+=A_Is64bitOS ? 8 : 4
VarSetCapacity(lParam,cbSize,0)
NumPut(cbSize,lParam,0,"UInt")
NumPut(uFlags:=0,lParam,4,"UInt")
NumPut(hwnd:=A_ScriptHwnd,lParam,8,"Ptr")
NumPut(uId:=0,lParam,8+A_PtrSize,A_Is64bitOS ? "UInt64" : "UInt")
NumPut(Rect_Left:=0,lParam,8+A_PtrSize+(A_Is64bitOS ? 8 : 4)+4,"Int")
NumPut(Rect_Top:=0,lParam,8+A_PtrSize+(A_Is64bitOS ? 8 : 4)+4+4,"Int")
NumPut(Rect_Right:=A_ScreenWidth,lParam,8+A_PtrSize+(A_Is64bitOS ? 8 : 4)+4+4+4,"Int")
NumPut(Rect_Bottom:=A_ScreenHeight,lParam,8+A_PtrSize+(A_Is64bitOS ? 8 : 4)+4+4+4+4,"Int")
NumPut(hInstance:=0,lParam,8+A_PtrSize+(A_Is64bitOS ? 8 : 4)+16,"Ptr")
NumPut(lpszText:=0,lParam,8+A_PtrSize+(A_Is64bitOS ? 8 : 4)+16+A_PtrSize,"UInt")
If (floor(_WIN32_IE)>=3)
	NumPut(lParam_struct:=0,lParam,8+A_PtrSize+(A_Is64bitOS ? 8 : 4)+16+A_PtrSize+(wParam * ( (A_IsUnicode) ? 2 : 1 )),A_Is64bitOS ? "UInt64" : "UInt")
SendMessage,TTM_GETTEXT:=0x0400+56,wParam,lParam, , ahk_id %A_ScriptHwnd%
Text2:=""
Loop, % wParam-1
	Text2.=NumGet(lParam,8+A_PtrSize+(A_Is64bitOS ? 8 : 4)+16+A_PtrSize+A_Index-1,"Char")
MsgBox % Text2
return
Last edited by RijulAhuja on 27 Oct 2013, 09:47, edited 1 time in total.
Leefme
Posts: 90
Joined: 30 Sep 2013, 22:13

Re: Retrieve traytip text

25 Oct 2013, 15:37

Please review my replies in the following thread,
http://www.autohotkey.com/board/topic/5 ... ip-window/
RijulAhuja
Posts: 44
Joined: 30 Sep 2013, 07:29

Re: Retrieve traytip text

25 Oct 2013, 15:55

Thank you, but I was merely using this to increase my understanding of APIs.
Would it be possible for you to take a look at the code above ?
EDIT : Oh, and sorry for not noticing earlier, but welcome to the forum.
Leefme
Posts: 90
Joined: 30 Sep 2013, 22:13

Re: Retrieve traytip text

26 Oct 2013, 14:54

Thanks for the welcome.
I don't understand your code, so I can't help with it.
RiseUp
Posts: 28
Joined: 01 Oct 2013, 21:27

Re: Retrieve traytip text

26 Oct 2013, 16:25

RijulAhuja wrote:I was looking at some old threads and found this TTM_GetText message which can be used to retrieve tooltip / traytip text.
I attempted to try and solve some of it, but I'm missing something, could anybody tell ?

<<code snipped>>
What kind of error do you get?
RijulAhuja
Posts: 44
Joined: 30 Sep 2013, 07:29

Re: Retrieve traytip text

27 Oct 2013, 06:03

The text, it's incorrect. No particular error. Just shows up as 0000
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Retrieve traytip text

27 Oct 2013, 08:34

  • Code: Select all

    typedef struct {                          x86      x64
      UINT      cbSize;        4                4        4
      UINT      uFlags;        4                4        4
      HWND      hwnd;          A_PtrSize        4        8
      UINT_PTR  uId;           A_PtrSize        4        8
      RECT      rect;          16              16       16
      HINSTANCE hinst;         A_PtrSize        4        8
      LPTSTR    lpszText;      A_PtrSize        4        8
      LPARAM    lParam;        A_PtrSize        4        8
      void      *lpReserved;   A_PtrSize        4        8
    } TOOLINFO, *PTOOLINFO, *LPTOOLINFO;      ---      ---
    
                                               48       72
    
  • lpszText is a pointer to a buffer that receives the text.
  • TTM_GETTEXT
    lparam
    Pointer to a TOOLINFO structure. Set the cbSize member of this structure to sizeof(TOOLINFO) before sending this message. Set the hwnd anduId members to identify the tool for which to retrieve information. Allocate a buffer of size specified by wParam. Set the lpszText member to point to the buffer to receive the tool text
RijulAhuja
Posts: 44
Joined: 30 Sep 2013, 07:29

Re: Retrieve traytip text

27 Oct 2013, 09:05

Some questions regarding this
Spoiler
Thank you for your help.

EDIT : I have create a table for this structure, if you could just identify the mistake(s) in it, that would be great.
Spoiler
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Retrieve traytip text using TTM_GetText message

28 Oct 2013, 11:54

  1. You need to check whether the application is 64-bit (i.e. A_PtrSize =8).
  2. lpszText is a pointer to a buffer, so its size is A_PtrSize.
  3. *lpReserved and lParam are pointers/pointer-sized, too.
  4. Alignment is not needed as far as the lenght is a multiple of the largest member.
  5. VarSetCapacity(Var, Lenght, 0) will initialize Var with binary zeroes.
Table: The offsets of lParam and *lpReserved do not depend on wParam.
RijulAhuja
Posts: 44
Joined: 30 Sep 2013, 07:29

Re: Retrieve traytip text using TTM_GetText message

29 Oct 2013, 11:44

I believe I understood what you mean, but the code still doesn't work. :?:
Spoiler

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Decar, doodles333, mikeyww and 222 guests