对于存图和上面说的一样,屏暮刷新可用以下三个函数 BOOL GetWindowRect( HWND hWnd, // handle to window LPRECT lpRect // address of structure for window coordinates );HWND GetDesktopWindow(VOID);InvalidateRect( HWND hWnd, // handle of window with changed update region CONST RECT *lpRect, // address of rectangle coordinates BOOL bErase // erase-background flag }
BOOL GetWindowRect(
HWND hWnd, // handle to window
LPRECT lpRect // address of structure for window coordinates
);HWND GetDesktopWindow(VOID);InvalidateRect(
HWND hWnd, // handle of window with changed update region
CONST RECT *lpRect,
// address of rectangle coordinates
BOOL bErase // erase-background flag
}
int iScrWidth = GetSystemMetrics(SM_CXSCREEN);
int iScrHeight = GetSystemMetrics(SM_CYSCREEN);HDC hdcScreen = GetDC(NULL);BITMAPINFO bmpInfo;
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biWidth = iScrWidth;
bmpInfo.bmiHeader.biHeight = iScrHeight;
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biBitCount = 24;
bmpInfo.bmiHeader.biCompression = BI_RGB;
bmpInfo.bmiHeader.biSizeImage = 0;
bmpInfo.bmiHeader.biXPelsPerMeter = 0;
bmpInfo.bmiHeader.biYPelsPerMeter = 0;
bmpInfo.bmiHeader.biClrUsed = 0;
bmpInfo.bmiHeader.biClrImportant = 0;void *pvBits = NULL;
HBITMAP hBitmap = CreateDIBSection(hdcScreen,&bmpInfo,DIB_RGB_COLORS,&pvBits,NULL,0);
HDC hdcCompatible = CreateCompatibleDC(hdcScreen);
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hdcCompatible,hBitmap);
BOOL b = BitBlt(hdcCompatible,0,0,iScrWidth,iScrHeight,hdcScreen,0,0,SRCCOPY);HANDLE hFile = CreateFile("yourbmp.bmp",GENERIC_WRITE,FILE_SHARE_WRITE,NULL,
CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
DWORD dwCnt;
char z[14];
ZeroMemory(z,14);
strcpy(z,"BM8");
z[4] = 0x24;
z[10] = 0x36;
WriteFile(hFile,z,14,&dwCnt,NULL);
WriteFile(hFile,(char*)&bmpInfo,sizeof(BITMAPINFO)-4,&dwCnt,NULL);
WriteFile(hFile,(char*)pvBits,iScrWidth*iScrHeight*3,&dwCnt,NULL);
CloseHandle(hFile);
}
------------Method 2---------
CDC * pDC;
CBitmap bmpTmp;
CBitmap * bmpOld = bmpTmp.CreateCompatibleBitmap(pDC, 640, 480);
pDC->SelectObject(bmpTmp);
pDC->MoveTo(0,0);
pDC->LineTo(300,200);
CBitmap * bmpOut = pDC->SelectObject(bmpOld);----------