Solved

tooltip problem

Posted on 2000-02-16
5
745 Views
Last Modified: 2013-12-03
I add tooltips to a child window like:
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_TRANSPARENT | TTF_CENTERTIP | TTF_SUBCLASS;
ti.hwnd = hParent; // is valid
ti.uId = iToolTipId;
ti.rect = rectToolTip;
ti.lpszText = pString; // allocated and saved
SendMessage(hToolTip,TTM_ADDTOOL,0,(LPARAM)&ti);

Before destroying the window (or before changing the tooltips) I do the following:
while (SendMessage(hToolTip,TTM_ENUMTOOLS,0,(LPARAM)&ti)) {
   SendMessage(hToolTip,TTM_DELTOOL,0,(LPARAM)&ti);
} // while look for tooltips to get rid of

There is no problem when I remove the tooltips in my display routine which updates the text of the tooltips.  But I get an access violation on the first SendMessage() when closing things down.  It is called when it's parent gets a WM_LBUTTONUP message on it's Finished button.  3 questions:
1)  Do I need to do this when exitting? (Are there resources, besides the text, that need to be freed)
2)  Does the text for ti.lpszText need to valid for the lifetime of the tooltip, or can it be a local string.
3)  If 'Yes' to question 1, what might be causing the access violation?
Thank You.
0
Comment
Question by:marvinm
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2527371
1) Have you called the Default() implementation of WM_LBUTTONUP first?

2) Sadly yes, the tooltip text must be static or allocated on the heap.

0
 
LVL 1

Author Comment

by:marvinm
ID: 2527463
I try to delete the tooltips at the end of the WM_LBUTTONUP case, right before "return 0;"  If I set ti.lpszText = NULL, I do not get the error.  I noticed that at the time of the error, all of the TOOLINFO is set, but the lpszText contains garbage.  This is if I set to an allocated pointer that has not yet been freed, or to static text such as "".
0
 
LVL 1

Accepted Solution

by:
ScottyDawg earned 200 total points
ID: 2527531
Ah, just noticed what's going on (I think).

When you send your message TTM_ENUMTOOLS, the tooltip fills in all the details of the tool as well as the test of the tool.

So, for the pszText, if you leave it null, it wont bother filling in the text - but if its not NULL it assumes its a pointer to a buffer big enough to contain the text. In this case, you haven't allocated any space for it and its overwrites memory elsewhere causing the problem :)






0
 
LVL 1

Author Comment

by:marvinm
ID: 2527845
With a quick test, it does seem to work ok if i allocate the lpszText pointer before sending the TTM_ENUMTOOLS message.  I am wondering why it does not just set this to the pointer that was set in the TTM_ADDTOOL message?
I will test some more and if all goes well I will grade.
Thank You, mm
0
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2527863
Marvin, in my experience most controls want you to allocate storage in some way when interrogating them for strings. Albeit, most actually provide an int somewhere in the structure for you to specify how big the string is - TOOLINFO seems to be the exception.

I guess the reason for this is that if they pass you backa pointer to the data you could do what you liked to the contents, perhaps they're just being careful. And of course, the string may not be stored in the way you expected i.e. UNICODE or DBCS or....

but its still a real pain to work with :)

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now