void saveBitmap()
{
HDC hdc=GetDC(NULL);
int wScreen=GetSystemMetrics(SM_CXSCREEN);
int hScreen=GetSystemMetrics(SM_CYSCREEN);
HDC memdc=CreateCompatibleDC(hdc);
HBITMAP hBitmap=CreateCompatibleBitmap(hdc,wScreen,hScreen);
SelectObject(memdc,hBitmap);
BitBlt(memdc,0,0,wScreen,hScreen,hdc,0,0,SRCCOPY);
BITMAPINFO bi;
//RtlZeroMemory(&bi,sizeof(bi));
bi.bmiHeader.biSize=sizeof(bi.bmiHeader);
bi.bmiHeader.biWidth=wScreen;
bi.bmiHeader.biHeight=hScreen;
bi.bmiHeader.biPlanes=1;
bi.bmiHeader.biBitCount=24;
bi.bmiHeader.biCompression=BI_RGB;
bi.bmiHeader.biSizeImage=0;
bi.bmiHeader.biXPelsPerMeter=wScreen;
bi.bmiHeader.biYPelsPerMeter=hScreen;
bi.bmiHeader.biClrUsed=0;
bi.bmiHeader.biClrImportant=0;
int bitsize=wScreen*hScreen*3;
BYTE* buff=new BYTE[bitsize];
RtlZeroMemory(buff,bitsize);
GetDIBits(memdc,hBitmap,0,hScreen,buff,&bi,DIB_RGB_COLORS);
BITMAPFILEHEADER bf;
bf.bfType=0x4d42;
bf.bfSize=bitsize+14+sizeof(BITMAPINFOHEADER);
bf.bfOffBits=sizeof(bi.bmiHeader)+sizeof(bf);
bf.bfReserved1=0;
bf.bfReserved2=0;
HANDLE hFile=CreateFile(L"桌面 .bmp",GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
DWORD num=0;
WriteFile(hFile,&bf,sizeof(bf),&num,NULL);
WriteFile(hFile,&bi,sizeof(bi),&num,NULL);
WriteFile(hFile,buff,bitsize,&num,NULL);
CloseHandle(hFile);
delete buff;
}
这个函数是截屏然后保存为一副位图,但是不知道为什么位图的颜色不正确,请教各位大侠。我自己已经查了3天了,始终不知道错在哪,MSDN我也看过,都要崩溃了。
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课