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.
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 :)