Click here to Skip to main content
11,640,211 members (67,779 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Windows MFC VC++
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 1:35am
Joneeky620
Edited 29-Jan-13 1: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
0 Suvendu Shekhar Giri 225
1 CPallini 192
2 Mika Wendelius 188
3 F-ES Sitecore 150
4 Sergey Alexandrovich Kryukov 139


Advertise | Privacy | Mobile
Web02 | 2.8.150731.1 | Last Updated 29 Jan 2013
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