Archived

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

Zeke

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;
pDC->CreateCompatibleDC(NULL);
//get dimensions of this dialog so we get the right part of

//the desktop window

RECT Rect;
GetWindowRect(&Rect);

int xPos=Rect.left;
int yPos=Rect.top;
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

pDC->BitBlt(0,0,iWidth,iHeight,pDeskCDC,xPos,yPos,SRCCOPY);

//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

		color=pDeskCDC->GetPixel(x,y);

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

  
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