void OnScreenSave()

{

HDC  hScrDC, hMemDC;         

    int  width, height; 

 

BYTE  *lpBitmapBits = NULL; 

 

    hScrDC = CreateDC(_T("DISPLAY"), NULL, NULL, NULL);

 

    width = GetDeviceCaps(hScrDC, HORZRES);

    height = GetDeviceCaps(hScrDC, VERTRES);

 

    hMemDC = CreateCompatibleDC(hScrDC);

 

    BITMAPINFO RGB24BitsBITMAPINFO; 

    ZeroMemory(&RGB24BitsBITMAPINFO, sizeof(BITMAPINFO));

    RGB24BitsBITMAPINFO.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);

    RGB24BitsBITMAPINFO.bmiHeader.biWidth = width;

    RGB24BitsBITMAPINFO.bmiHeader.biHeight = height;

    RGB24BitsBITMAPINFO.bmiHeader.biPlanes = 1;

    RGB24BitsBITMAPINFO.bmiHeader.biBitCount = 24;

 

    HBITMAP directBmp = CreateDIBSection(hMemDC, (BITMAPINFO*)&RGB24BitsBITMAPINFO, 

DIB_RGB_COLORS, (void **)&lpBitmapBits, NULL, 0);

HGDIOBJ previousObject = SelectObject(hMemDC, directBmp);

 

BitBlt(hMemDC, 0, 0, width, height, hScrDC, 0, 0, SRCCOPY);

 

BITMAPFILEHEADER bmBITMAPFILEHEADER;

ZeroMemory(&bmBITMAPFILEHEADER, sizeof(BITMAPFILEHEADER));

bmBITMAPFILEHEADER.bfType = 0x4d42;  //bmp  

    bmBITMAPFILEHEADER.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);

    bmBITMAPFILEHEADER.bfSize = bmBITMAPFILEHEADER.bfOffBits + ((width*height)*3); ///3=(24 / 8)

 

 

char g_chPhotoPathName[50];

char g_chPhotoName[30];

FILE *mStream = NULL;

COleDateTime tmTime = COleDateTime::GetCurrentTime();

sprintf(g_chPhotoName, "%d%d%d%d%d%d.bmp", tmTime.GetYear(), tmTime.GetMonth(), tmTime.GetDay(),tmTime.GetHour(),tmTime.GetMinute(),tmTime.GetSecond());

sprintf(g_chPhotoPathName, "//NAND//screen//%s", g_chPhotoName);

CreateDirectory(_T("//NAND//screen"), NULL);

if((mStream = fopen(g_chPhotoPathName,"wb")))

{  

 

fwrite(&bmBITMAPFILEHEADER, sizeof(BITMAPFILEHEADER), 1, mStream);

 

fwrite(&(RGB24BitsBITMAPINFO.bmiHeader), sizeof(BITMAPINFOHEADER), 1, mStream);

 

fwrite(lpBitmapBits, 3*width*height, 1, mStream);

 

fclose(mStream);

}

else

{

MessageBox(NULL,_T("创建图像文件失败"),_T("错误"),MB_OK);

return;

}

 

//delete

DeleteObject(hMemDC);

DeleteObject(hScrDC);

DeleteObject(directBmp);

DeleteObject(previousObject);

}