ok..I'll try the steps one
/edit:
After googling around I came out with this:
Code:
int SaveDCToBitmap(HWND hStatic, const char *pszFile) {
BITMAPFILEHEADER bmfh = {0};
BITMAPINFOHEADER bmih = {0};
RECT rc = {0};
HDC hdc1;
HDC hdc2;
HBITMAP aBmp;
BITMAPINFO bi;
HGDIOBJ OldObj;
void *dibvalues;
HANDLE fileHandle;
DWORD bytes_write;
DWORD bytes_written;
int w;
int h;
hdc1 = GetWindowDC(hStatic);
hdc2 = CreateCompatibleDC(hdc1);
GetWindowRect(hStatic, &rc);
w = rc.right-rc.left;
h = rc.bottom-rc.top;
bmih.biSize = sizeof(BITMAPINFOHEADER);
bmih.biWidth = w;
bmih.biHeight = h;
bmih.biPlanes = 1;
bmih.biBitCount = 24;
bmih.biCompression = BI_RGB;
bmih.biSizeImage = ((((bmih.biWidth * bmih.biBitCount) + 31) & ~31) >> 3) * bmih.biHeight;
bi.bmiHeader = bmih;
aBmp = CreateDIBSection(hdc1, &bi ,DIB_RGB_COLORS, (void**)&dibvalues, NULL, NULL);
OldObj = SelectObject(hdc2, aBmp);
BitBlt(hdc2, 0, 0, w, h, hdc1, 0, 0, SRCCOPY);
bmfh.bfOffBits = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
bmfh.bfSize = (3*bmih.biHeight*bmih.biWidth)+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
bmfh.bfType = 0x4d42;
fileHandle = CreateFile(pszFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
bytes_write = sizeof(BITMAPFILEHEADER);
WriteFile(fileHandle, &bmfh, bytes_write, &bytes_written, NULL);
bytes_write = sizeof(BITMAPINFOHEADER);
WriteFile(fileHandle, &bmih, bytes_write, &bytes_written, NULL);
bytes_write = bmih.biSizeImage;
WriteFile(fileHandle, (void*)dibvalues, bytes_write, &bytes_written, NULL);
CloseHandle(fileHandle);
DeleteObject(SelectObject(hdc2,OldObj));
DeleteDC(hdc2);
ReleaseDC(hStatic, hdc1);
return 0;
}
Seems to be working.. what do you think?