Solved

tooltip problem

Posted on 2000-02-16
5
776 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

728 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