Results 1 to 5 of 5

Thread: [RESOLVED] Can't get TTM_GETTEXT to work

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    169

    Resolved [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???

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    169

    Resolved 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

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    169

    Arrow 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
  •  



Click Here to Expand Forum to Full Width