|
-
Jan 10th, 2010, 01:25 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Can't get TTM_GETTEXT to work
I have successfully created a tooltip using TOOLINFO structure, and changed its time on, changed the title, changed the text, using SendMessage and the proper TTMs. However I want to be able to read the text back using TTM_GETTEXT but I cannot get it to work, anyone here have any experience with this message?
TTM_GETTEXTA = Wm_User + 11
Public Type
cbsize as long
uFlags as Long
hwnd as long
uID as long
rc as RECT
hInstance as Long
lpszText as String
lParam as long
End Type
Dim parentHwnd as long 'handle of the control I want the tooltip to trigger over
Dim tipHwnd as Long 'returned from CreateWindow(tooltip setup styles)
------------
Sub GetTipText()
Dim ti as TOOLINFO
Dim tipBuffer as String
tipBuffer = Space$(80)
With ti
.lpszText = StrPtr(tipBuffer)
.Uflags = TTF_SUBCLASS or TTF_IDISHWND
.hwnd = parentHwnd
.Uid = parentHwnd
.hInstance = App.hInstance
.lParam = 0
.cbSize = Len(ti)
end With
SendMessage tipHwnd, TTM_GETTEXTA, 0, ti
Me.Caption = tipBuffer
End Sub
it returns an empty string,well the spaces are in the buffer of course.
What am I doing wrong???
-
Jan 10th, 2010, 03:31 PM
#2
Re: Can't get TTM_GETTEXT to work
Read this MSDN documentation. The wParam must be zero on XP and below; on Vista and above?
Edited: Forgot to include the link: http://msdn.microsoft.com/en-us/libr...93(VS.85).aspx
Try modifying slightly
Code:
With ti
.lpszText = Space$(80)
.Uflags = 0
.hwnd = parentHwnd
.Uid = parentHwnd
.hInstance = App.hInstance
.lParam = 0
.cbSize = Len(ti)
End With
SendMessage tipHwnd, TTM_GETTEXTA, 0&, ti
' trim the ti.lpszText value, it may be padded if tip was < 80 chars.
Me.Caption = Trim(ti.lpszText)
Last edited by LaVolpe; Jan 10th, 2010 at 04:42 PM.
-
Jan 10th, 2010, 07:16 PM
#3
Thread Starter
Addicted Member
Re: Can't get TTM_GETTEXT to work
LaVolpe,
That did it.
I wasn't handling the buffer properly. Got rid of the variable tipBuffer and did the .lpszText = Space$(80)
uFlags = 0 or uFlags = TTF_SUBCLASS or TTF_IDISHWND apparently doesn't matter.
I am doing this on XP but of course I want it to work on other Windows platforms as well.
Thank you much
-
Jan 10th, 2010, 07:34 PM
#4
Re: [RESOLVED] Can't get TTM_GETTEXT to work
Kewl. The uflags doesn't matter because the type of message being sent doesn't need that member filled in. But why waste a cpu cycle or two filling in stuff never used?
-
Jan 11th, 2010, 02:16 PM
#5
Thread Starter
Addicted Member
Re: [RESOLVED] Can't get TTM_GETTEXT to work
Beware: Anyone using this message, as it only returns a maximum of 80 characters even though the actual tooltiptext maybe longer. As a result it is insufficient to simply use a Trim(.lpszText) because a null is used as an EOB character for text lengths less than 80, the null must be removed from the string as well when using comparison statements.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|