Click here to Skip to main content
11,715,165 members (62,727 online)
Rate this: bad
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);
void CustomToolTipPlain::DrawTip(CDC *pDC)
	if (pDC)
		BITMAP	bm;
		CDC		dcMem;
		CBitmap *oldBitmap = dcMem.SelectObject(m_tipImage);
		pDC->BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, SRCCOPY);

There is also another function

void CustomToolTip::OnTimer(UINT)
    if (!MouseInTipArea())

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 6:44am
Rate this: bad
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.
amarasat at 21-Apr-11 14:24pm
But it is working always, only in this case its not working. This code is grabbed from

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:
amarasat at 26-Apr-11 10:13am
Thanks a lot the answer was solved, my bitmap is having bad dimensions
Rate this: bad
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?
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 Sergey Alexandrovich Kryukov 495
1 Richard MacCutchan 275
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 125
0 Sergey Alexandrovich Kryukov 775
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320

Advertise | Privacy | Mobile
Web03 | 2.8.150901.1 | Last Updated 21 Apr 2011
Copyright © CodeProject, 1999-2015
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