🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #12813

Re: Hooking to Windows ToolTips

#12813
From: Remy Lebeau (TeamB)
Date: Tue, 18 Nov 2003 18:30
73 lines
4303 bytes
"Marc" <Remove_Bukwheat@axess.com> wrote in message
news:3fba41b8$1@newsgroups.borland.com...

> UINT nID = static_cast<UINT>( pNMHDR->idFrom );

The idFrom field is already a UINT, you do not need to cast it:

    UINT nID = pNMHDR->idFrom;

Also, did you verify that the ID is even valid?  I used Spy++ just now to
view all active windows on my machine, and all of the tooltip windows had an
ID of 0, which is pretty useless for identifying windows.

> HWND hWndTT = GetDlgItem(pPreMsg->hwnd, nID);

Did you verify that the HWND is being assigned a non-NULL value?  If it is,
then did you verify that it is really a tooltip window?  Have a look at the
GetClassName() function for that.  The class name of a tooltip is
"tooltips_class32".

> TOOLTIPTEXTW* pTTTW = reinterpret_cast<TOOLTIPTEXTW*>( pPreMsg->lParam );

There is no documentation that suggests the TOOLTIPTEXT structure is used
for the TTN_SHOW notification.  Where did you get that from?  The
TOOLTIPTEXT structure is used with TTN_GETDISPINFO/TTN_NEEDTEXT.  In fact, I
did find reference that says TTN_SHOW really does only use NMHDR itself, no
wrapper structures at all like most notifications use.  That means that
TTN_SHOW does not provide any information about the tooltip at all other
than its ID.

Just for the sake of discussion, had TOOLTIPTEXT really been used with
TTN_SHOW, then I would suggest you check the uFlags member before making
assumptions about the tooltip window handle that you are extracting.  For
example, there is a TTF_IDISHWND flag that indicates that the idFrom member
is already the actual HWND rather than an ID number, ie:

    if( pTTTW->uFlags & TTF_IDISHWND )
        hWndTT = reinterpret_cast<HWND>(pNMHDR->idFrom);

> char* stTestX = new char;
> stTestX = "1234567890";

That is a memory leak, and even if it weren't, it wouldn't do what you think
it does.  You are allocating memory for a single character, not a buffer of
characters.  Then you are immediately reassigning the pointer to point to a
different memory address, thus losing the original memory that you allocated
so you can't free it.  You probably meant to do this instead:

    char* stTestX = "1234567890";

> pTTTW->lpszText = (LPWSTR)stTestX;
>
> The tooltip text gets modified but it shows garbage.

Probably because you are trying to force the compiler to treat an ANSI
string as a Uncode string.  They are not the same thing at all, you can't
simply cast one to the other.  You have to physically convert the memory of
one to the other.  Look at the MultiByteToWideChar() function for that.
When you do that, I also suggest that you use the structure's szText member
instead of lpszText, which has a different purpose then you think it does.
For example:

    MultiByteToWideChar(CP_ACP, 0, "1234567890", -1, pTTTW->szText,
sizeof(pTTTW->szText)/sizeof(WCHAR));
    pTTTW->hinst = NULL;

Now, with all of that said, you might also want to have a look at the
TTM_UPDATETIPTEXT message, which is designed for updating the text of
tooltips.


Gambit
Technical Details
Message-ID: <3fba6474$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3fb3ef78$1@newsgroups.borland.com> <3fb3f737@newsgroups.borland.com> <3fb4ec69$1@newsgroups.borland.com> <3fb5015f$1@newsgroups.borland.com> <3fb514e5$1@newsgroups.borland.com> <3fb522c0$1@newsgroups.borland.com> <3fb8e5d5$1@newsgroups.borland.com> <3fb90c0a@newsgroups.borland.com> <3fba3491$2@newsgroups.borland.com> <3fba41b8$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,77f5c963a5b23dbd
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-11-18 10:39:53 PST
From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3fb3ef78$1@newsgroups.borland.com> <3fb3f737@newsgroups.borland.com> <3fb4ec69$1@newsgroups.borland.com> <3fb5015f$1@newsgroups.borland.com> <3fb514e5$1@newsgroups.borland.com> <3fb522c0$1@newsgroups.borland.com> <3fb8e5d5$1@newsgroups.borland.com> <3fb90c0a@newsgroups.borland.com> <3fba3491$2@newsgroups.borland.com> <3fba41b8$1@newsgroups.borland.com>
Subject: Re: Hooking to Windows ToolTips
Date: Tue, 18 Nov 2003 10:30:44 -0800
Lines: 75
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 67.22.137.149
Message-ID: <3fba6474$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1069180020 67.22.137.149 (18 Nov 2003 10:27:00 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail