Click here to Skip to main content
15,896,414 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello everyone.

I have implemented a custom tooltip below is the code. Below is the function taht is called at last while drawing the tip.

CClientDC dc(this);
DrawTip(&dc);

void CustomToolTipPlain::DrawTip(CDC *pDC)
{
	if (pDC)
	{
		BITMAP	bm;
		m_tipImage->GetBitmap(&bm);
		CDC		dcMem;
		dcMem.CreateCompatibleDC(pDC);
		CBitmap *oldBitmap = dcMem.SelectObject(m_tipImage);
		pDC->BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, SRCCOPY);
		dcMem.SelectObject(oldBitmap);
	}
}


There is also another function

void CustomToolTip::OnTimer(UINT)
{
    if (!MouseInTipArea())
    {
        HideTip();
    }
    else
    {
        ShowWindow(SW_SHOW);
    }
}


Now in the situation where the Ontimer function is called before even calling the CClientDC dc(this); and finishing the drawing (DrawTip(&dc);
)

My tooltip is always blank in this situation and it doesn't draw anything. It just shows a blank window from the ShowWindow(SW_SHOW) function of the OnTimer.

From the debugging its clear that the call to CClientDC dc(this); is giving a blank dc value when the window is open. Is this true,do you guys think this is the reason? So my question is:

Does CClientDC dc(this); fails when the client windows is open?
Posted

From what you have posted above it looks like you are calling CClientDC dc(this); from outside of any class or function where this would have a valid value.
 
Share this answer
 
Comments
amarasat 21-Apr-11 14:24pm    
But it is working always, only in this case its not working. This code is grabbed from

http://www.codeproject.com/KB/miscctrl/CustomToolTips.aspx.

The only thing i changed is adding the OnTimer function i gave above
Richard MacCutchan 21-Apr-11 15:20pm    
Take a look here: http://msdn.microsoft.com/en-us/library/bb760250%28VS.85%29.aspx
amarasat 26-Apr-11 10:13am    
Thanks a lot the answer was solved, my bitmap is having bad dimensions
Usually a function like DrawTip() would be called from the OnPaint() handler. Where are you calling this function?

In any case, to answer your question, yes, it's ok to use CClientDC when the window is open. Have you checked the bitmap? Did you verify it was loaded? Did you check the bitmap dimensions?
 
Share this answer
 
v2
Comments
amarasat 26-Apr-11 10:13am    
Thanks, The bitmap is having bad dimensions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900