?
Hi
Alles was ich Probiert habe hier ist mull ! syntaxfehler etc.
Hier 2 Stunden müssame Arbeit.
Ohne Syntaxfehler. Für C and C++;
int main()
{
HDC hdc;
HWND hWnd;
hWnd = GetDesktopWindow();
hdc = GetDC(hWnd);
dc2bitmap(hdc, 1680, 1050, "c:\\hallo.BMP");
return 0;
}
void dc2bitmap(HDC hdc, int width, int height, char *filename)
{
HDC hdc2;
HBITMAP aBmp;
BITMAPINFO bi;
HGDIOBJ OldObj;
void *dibvalues;
HANDLE fileHandle;
BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmih;
DWORD bytes_write;
DWORD bytes_written;
hdc2=CreateCompatibleDC(hdc);
ZeroMemory(&bmih,sizeof(BITMAPINFOHEADER));
bmih.biSize=sizeof(BITMAPINFOHEADER);
bmih.biHeight=height;
bmih.biWidth=width;
bmih.biPlanes=1;
bmih.biBitCount=24;
bmih.biCompression=BI_RGB;
bmih.biSizeImage = ((((bmih.biWidth * bmih.biBitCount) + 31) & ~31) >> 3) * bmih.biHeight;
bmih.biXPelsPerMeter = 0;
bmih.biYPelsPerMeter = 0;
bmih.biClrImportant = 0;
//bmih.biSizeImage=(3*bmih.biHeight*bmih.biWidth);
//bmih.biSizeImage = 0;
bi.bmiHeader=bmih;
aBmp=CreateDIBSection(hdc,&bi,DIB_RGB_COLORS,(void**)&dibvalues,NULL,NULL);
if (aBmp==NULL)
{
OutputDebugString("CreateDIBSection failed!\n");
return 0;
}
OldObj=SelectObject(hdc2,aBmp);
BitBlt(hdc2,0,0,width,height,hdc,0,0,SRCCOPY);
ZeroMemory(&bmfh,sizeof(BITMAPFILEHEADER));
bmfh.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
bmfh.bfSize=(3*bmih.biHeight*bmih.biWidth)+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
bmfh.bfType=0x4d42;
bmfh.bfReserved1 = 0;
bmfh.bfReserved2 = 0;
fileHandle=CreateFile(filename,GENERIC_READ | GENERIC_WRITE,(DWORD)0,NULL,
CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,(HANDLE) NULL);
if (fileHandle==INVALID_HANDLE_VALUE)
{
OutputDebugString("CreateFile failed!\n");
return 0;
}
// Write the BITMAPFILEHEADER
bytes_write=sizeof(BITMAPFILEHEADER);
if (!WriteFile(fileHandle,(void*)&bmfh,bytes_write,&bytes_written,NULL))
{
OutputDebugString("WriteFile failed!\n");
return 0;
}
//Write the BITMAPINFOHEADER
bytes_write=sizeof(BITMAPINFOHEADER);
if (!WriteFile(fileHandle,(void*)&bmih,bytes_write,&bytes_written,NULL))
{
OutputDebugString("WriteFile failed!\n");
return 0;
}
//Write the Color Index Array???
bytes_write=bmih.biSizeImage;//3*bmih.biHeight*bmih.biWidth;
if (!WriteFile(fileHandle,(void*)dibvalues,bytes_write,&bytes_written,NULL))
{
OutputDebugString("WriteFile failed!\n");
return 0;
}
CloseHandle(fileHandle);
DeleteObject(SelectObject(hdc2,OldObj));
DeleteDC(hdc2);
return 1;
}
lowbyte