Solved

tooltip problem

Posted on 2000-02-16
5
741 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 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

22 Experts available now in Live!

Get 1:1 Help Now