首页 > 代码库 > GetBitmapFromScreen

GetBitmapFromScreen



int GetBitmapFromScreen() 

char *lpBuf; 
HBITMAP hBitmap,hOld ; 
HDC hDC,hcDC; 
BITMAP bb;BITMAPINFO b; 
HANDLE hp,fh=NULL; 
DWORD dwX,dwY; 
//*************** 
//dwX=GetSystemMetrics(SM_CXSCREEN); 
//dwY=GetSystemMetrics(SM_CYSCREEN); 
dwX=100; 
dwY=100; 
hDC=GetDC(0); 
hcDC=CreateCompatibleDC(hDC); 
hBitmap=CreateCompatibleBitmap(hDC,dwX,dwY); 
hOld=(HBITMAP)SelectObject(hcDC,hBitmap); 
BitBlt(hcDC,0, 0,dwX,dwY, hDC, 0, 0, SRCCOPY); 
bb.bmWidth=dwX; 
bb.bmHeight =dwY; 
bb.bmPlanes = 1; 
bb.bmWidthBytes=bb.bmWidth*3; 
bb.bmBitsPixel=3; 
bb.bmType=0; 
b.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 
b.bmiHeader.biWidth=dwX; 
b.bmiHeader.biHeight =dwY; 
b.bmiHeader.biPlanes = 1; 
b.bmiHeader.biBitCount =24; 
b.bmiHeader.biCompression = BI_RGB; 
b.bmiHeader.biSizeImage = 0; 
b.bmiHeader.biXPelsPerMeter = 0; 
b.bmiHeader.biYPelsPerMeter = 0; 
b.bmiHeader.biClrUsed = 0; 
b.bmiHeader.biClrImportant = 0; 
b.bmiColors[0].rgbBlue=8; 
b.bmiColors[0].rgbGreen=8; 
b.bmiColors[0].rgbRed=8; 
b.bmiColors[0].rgbReserved=0; 
hp=GetProcessHeap(); 
lpBuf=(char *)HeapAlloc(hp,HEAP_ZERO_MEMORY,bb.bmHeight*bb.bmWidth*4); 




GetDIBits(hcDC,hBitmap,0,dwY,lpBuf,&b,DIB_RGB_COLORS); 


///////////////////////////////////显示到桌面////////////////////////////////
CClientDC dc(NULL);
for (int i=0;i<100;i++)
{
for (int k=0;k<100;k++)
{
BYTE b = *lpBuf++;
BYTE g = *lpBuf++;
BYTE r = *lpBuf++;
dc.SetPixel(k+200,i+200,RGB(r,g,b));
//*lpBuf++;
}
}
/////////////////////////////////////////////////////////////////////////


ReleaseDC(NULL,hDC); 
DeleteDC(hcDC); 
DeleteObject(hBitmap); 
DeleteObject(hOld); 
HeapFree(hp,0,lpBuf); 
return true; 

GetBitmapFromScreen