Article View: borland.public.cppbuilder.nativeapi
Article #12718Re: Hooking to Windows ToolTips
From: Marc
Date: Tue, 18 Nov 2003 17:52
Date: Tue, 18 Nov 2003 17:52
85 lines
4634 bytes
4634 bytes
Hi Thanks for all the info, its been extremely useful, now I'll go a digest all this and see if I can make this work. Thanks again Marc "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> wrote: > >"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:
<3fba6a88$2@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<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> <3fba6474$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 11:10:05 PST From: "Marc" <remove_bukwheat@axess.com> Sender: "Marc" <remove_bukwheat@axess.com> Reply-To: "Marc" <remove_bukwheat@axess.com> Subject: Re: Hooking to Windows ToolTips Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 138.11.254.204 X-Forwarded-For: unknown 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> <3fba6474$1@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <3fba6a88$2@newsgroups.borland.com> Date: 18 Nov 2003 10:52:56 -0700 X-Trace: newsgroups.borland.com 1069181576 207.105.83.66 (18 Nov 2003 10:52:56 -0700) Lines: 86 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail