void CQueenMainDlg::SavePicture(CString SaveFileName)
{
BeginWaitCursor();
BYTE *pPicData = NULL;
//CDC *pDC = GetDC(); //1.当前显示的客户端窗口
CDC *pDC = CDC::FromHandle(::GetDC(NULL)); //2.整个屏幕
HDC pScrDC = pDC->GetSafeHdc();
HDC pMemDC = CreateCompatibleDC(pScrDC);
int nBitsPixel = pDC->GetDeviceCaps(BITSPIXEL);
//CRect rcWndRect;
int width = pDC->GetDeviceCaps(HORZRES);
int hight = pDC->GetDeviceCaps(VERTRES);
DWORD nImageSize = width*hight*nBitsPixel/8;
pPicData = new BYTE[nImageSize];
BITMAPINFOHEADER bmpinfoheader;
memset(&bmpinfoheader,0,sizeof(bmpinfoheader));
bmpinfoheader.biSize = sizeof(bmpinfoheader);
bmpinfoheader.biWidth = width;
bmpinfoheader.biHeight = hight;
bmpinfoheader.biBitCount = nBitsPixel;
bmpinfoheader.biCompression = BI_RGB;
bmpinfoheader.biPlanes = 1;
bmpinfoheader.biSizeImage = nImageSize;
//创建一个与屏幕设备描述表兼容的位图
HBITMAP hNewBit = CreateCompatibleBitmap(pScrDC,width,hight);
//把新位图放到内存设备描述表中
HBITMAP hOldBit = (HBITMAP)SelectObject(pMemDC,hNewBit);
//把屏幕设备表拷贝到内存设备表中
StretchBlt(pMemDC,0,0,width,hight,pScrDC,0,0,width,hight,SRCCOPY);
//取得位图数据
GetDIBits(pMemDC,hNewBit,0,hight,pPicData,(LPBITMAPINFO)&bmpinfoheader,DIB_RGB_COLORS);
//得到屏幕位图的句柄
SelectObject(pMemDC,hOldBit);
//释放
ReleaseDC(pDC);
DeleteDC(pMemDC);
DeleteObject(hNewBit);
if (pPicData)
{
DWORD nLineLen = (width*nBitsPixel+31)/32*4;
DWORD nColSize = sizeof(RGBQUAD)*((nBitsPixel <= 8) ? 1<<nBitsPixel:0);
DWORD nImgSize = sizeof(BITMAPINFOHEADER) + nColSize + (DWORD)(UINT)nLineLen*(DWORD)(UINT)hight;
BITMAPFILEHEADER bmpfileheader;
bmpfileheader.bfType = MAKEWORD('B','M');
bmpfileheader.bfSize = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+nImgSize;
bmpfileheader.bfReserved1 = bmpfileheader.bfReserved2 = 0;
bmpfileheader.bfOffBits = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
BITMAPINFOHEADER BmpInfoHead;
memset(&BmpInfoHead,0,sizeof(BITMAPINFOHEADER));
BmpInfoHead.biSize = sizeof(BITMAPINFOHEADER);
BmpInfoHead.biWidth = width;
BmpInfoHead.biHeight = hight;
BmpInfoHead.biBitCount = nBitsPixel;
BmpInfoHead.biCompression = BI_RGB;
BmpInfoHead.biPlanes = 1;
BmpInfoHead.biSizeImage = nImgSize-sizeof(BITMAPINFOHEADER)-nColSize;
BmpInfoHead.biXPelsPerMeter = BmpInfoHead.biYPelsPerMeter = 0;
BmpInfoHead.biClrUsed = (nBitsPixel <= 8) ? 1<<nBitsPixel:0;
BmpInfoHead.biClrImportant = 0;
CFile file;
CString strXmlFile = theApp.m_strAppPath;
strXmlFile += _T("skin\\");
file.SetFilePath(strXmlFile);
if (file.Open(SaveFileName,CFile::modeCreate | CFile::modeWrite))
{
file.Write(&bmpfileheader,sizeof(bmpfileheader));
file.Write(&BmpInfoHead,sizeof(BmpInfoHead));
file.Write(pPicData,nImgSize);
file.Close();
}
delete []pPicData;
}
EndWaitCursor();
SendTrack();
}