Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
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 21-Apr-11 7:44am
amarasat1.3K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
amarasat at 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 at 21-Apr-11 15:20pm
   
Take a look here: http://msdn.microsoft.com/en-us/library/bb760250%28VS.85%29.aspx
amarasat at 26-Apr-11 10:13am
   
Thanks a lot the answer was solved, my bitmap is having bad dimensions
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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?
  Permalink  
v2
Comments
amarasat at 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)

  Print Answers RSS
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,382


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 21 Apr 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100