This topic is now archived and is closed to further replies.


CDC::BitBlt problem

Recommended Posts

Ive got a dialog box that when a particular button is pressed another dialog box pops up but i want this dialog box to be invisible so i figured that before its created get an image of the desktop where this dialog box will appear and then draw that image onto the dialog box when it does appear here is my code for doing so:
//grab a dc compatible with the desktop dc

CClientDC* pDeskCDC=new CClientDC(NULL);

//and another one to blit to (to store for WM_PAINT)

pDC=new CDC;
//get dimensions of this dialog so we get the right part of

//the desktop window

RECT Rect;

int xPos=Rect.left;
int iWidth=Rect.right-xPos;
int iHeight=Rect.bottom-yPos;
//blit the rect specified above from the dekstop to

//my memory dc to be used in OnPaint


//test that it has actually copied it

for(int y=0;y<iHeight;y++)
	for(int x=0;x<iWidth;x++)
                //find color of pixels in memory dc

		COLORREF color=pDC->GetPixel(x,y);

		DWORD Red=GetRValue(color);
		DWORD Green=GetGValue(color);
		DWORD Blue=GetBValue(color);

                //find color of pixels in desktrop dc

                //i.e. the color the above pixels should be



The problem is the dekstop pixels are the correct color but the pixels of the memory dc are all black showing me that the BitBlt() didnt work even though it returns a success. Can anyone tell me what im doing wrong? Thanks for your time

Share this post

Link to post
Share on other sites
You can't just draw into the DC. You first need to create a bitmap and select it into the DC.
So after you create the new DC, call CreateCompatibleBitmap() to create a new bitmap as the same size as the desktop, and SelectObject() it into the new DC.
Then you can blit to it

Goblineye Entertainment
The road to success is always under construction

[edited by - Tornado on July 29, 2002 6:52:50 AM]

Share this post

Link to post
Share on other sites