Click here to Skip to main content
12,630,455 members (30,091 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Windows MFC VisualC++
I try to draw the texts in memory at first. Then copy the DC in memory to the window with BitBlt function. But this is not effective. What is the fault?
Such these codes:
DCD *pDC = GetDC();
CDC dcMem;
dcMem.CreateCompatibleDC(pDC);
dcMem.SelectObject(&font);
dcMem.SetTextColor(RGB(255, 0, 0));
dcMem.SetBkMode(TRANSPARENT);
dcMem.DrawText(strText, rcWnd, DT_VCENTER | DT_SINGLELINE);
pDC->BitBlt(0, 0, rcWnd.Width(), rcWnd.Height(), &dcMem, 0, 0, SRCCOPY);
dcMem.DeleteDC();

Thanks...
Posted 29-Jan-13 2:35am
Joneeky620
Updated 29-Jan-13 2:37am
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You must select a bitmap into your memory DC. See, for instance MSDN[^]: "Before an application can begin drawing, it must select a bitmap with the appropriate width and height into the DC by calling the SelectObject function".
Try
DCD *pDC = GetDC();
CDC dcMem;
Bitmap bmp; // added
dcMem.CreateCompatibleDC(pDC);
bmp.CreateCompatibleBitmap(pDC, rcWnd.Width(), rcWnd.Height()); // added: you must use pDC here
dcMem.SelectObject(&bmp); // added
dcMem.SelectObject(&font);
dcMem.SetTextColor(RGB(255, 0, 0));
dcMem.SetBkMode(TRANSPARENT);
dcMem.DrawText(strText, rcWnd, DT_VCENTER | DT_SINGLELINE);
pDC->BitBlt(0, 0, rcWnd.Width(), rcWnd.Height(), &dcMem, 0, 0, SRCCOPY);
dcMem.DeleteDC();
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161205.3 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2016
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