Re: How can I change CDC's color?
It really works exactly like an on-screen CDC. One thing that might confuse
you is that Windows sends a WM_ERASEBG (sp?) message to clear the
background. This is sent before WM_PAINT. So maybe you're used to the
background being cleared for you.
But it still works the same. If you override and disable painting the
background of your window, it will do the same thing, except the contents
will just be whatever they were before while a bitmap's memory may be
initialized to zeros (black).
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"Sam_2" <Sam2@discussions.microsoft.com> wrote in message
news:9AAD3930-8396-49B9-90A4-ECCC88ACEF20@microsoft.com...
Hi Jonathan,
Thanks for replying (again :) )
You are right, I shouldn't expect any color before I drawn onto it. I am
just little confuse because I am a newbie on CDC and bitmap stuff.
Sam_2
"Jonathan Wood" wrote:
What color do you expect a bitmap to be that you haven't drawn to? In
short,
the contents of an uninitialized bitmap is undefined until you draw it.
Why on Earth would it be an issue to draw a rectangle to fill the
background
before doing anything else?
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"Sam_2" <Sam2@discussions.microsoft.com> wrote in message
news:8B13B5F7-87E5-4F2E-B464-C9505B32CF59@microsoft.com...
After I created a Memory DC compatible with screen DC, I created a
color
DIB
bitmap and selected into the memory DC. However, before I draw anything
onto
the memory DC, everything is black in color? What's wrong with my code?
/****************************************************/
CWnd* pTestWnd = AfxGetApp()->GetMainWnd();
CClientDC dcScreen(pTestWnd);
pTestWnd->GetClientRect(&rect);
// Create Memory DC and Bitmap associate with the Memory DC
CDC MemDC.CreateCompatibleDC(&dcScreen);
// Create a 32-bit color Bitmap using DIB section.
// Code from CodeGuru
BITMAPINFO bmInfo;
ZeroMemory( &bmInfo.bmiHeader, sizeof(BITMAPINFOHEADER) );
bmInfo.bmiHeader.biWidth= rect.Width(); // Set size same as
Screen.Width
bmInfo.bmiHeader.biHeight=rect.Height(); // Set size same as
Screen.Height
bmInfo.bmiHeader.biPlanes=1;
bmInfo.bmiHeader.biBitCount=32; // Color depth 8, 16, 32 bpp
bmInfo.bmiHeader.biSizeImage=0;
bmInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
bmInfo.bmiHeader.biClrUsed= 0;
bmInfo.bmiHeader.biClrImportant= 0;
VOID *pvBits; // Not used
Bitmap bm; bmt.Attach(CreateDIBSection( m_MemDC,
&bmInfo, DIB_RGB_COLORS, &pvBits, NULL, 0 ));
// Select created bitmap as PrintOut bitmap
MemDC.SelectObject(bm);
// Set Map Mode to Default Logical Unit (Default is Twips)
m_MemDC.SetMapMode(DEFAULT_PAGE_UNIT);
m_MemDC.DPtoLP(&rect);
/* If I stop here and save the DC to a file, the bitmap file will be
completely black.
If I add the following line and draw an rectangle over the DC area,
then
the screen become white in color.
*/
MemDC.Rectangle(rect);