Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Administrator
Anonymous
unregistriert
Anonymous
unregistriert
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
#include <windows.h> BOOL saveBMP(LPSTR filename, HDC hdcHBMP, int width, int height); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCommandLine, int iShowCommand) { HWND hDesktop = GetDesktopWindow(); HDC hdc = GetWindowDC(hDesktop); HBITMAP hBitmap=CreateCompatibleBitmap(hdc,208,156); void *data=malloc(208*156); GetBitmapBits(hBitmap, 208*156, data); saveBMP("hello.bmp", hdc, 1024, 768); return 0; } BOOL saveBMP(LPSTR filename, HDC hdcHBMP, int width, int height) { int offset = width%4; int bmpsize = 3 * width * height + height * offset; HDC hdcDisplay = CreateDC("DISPLAY", 0, 0, 0); if (hdcDisplay == NULL) return FALSE; BITMAPINFO bmpinfo; ZeroMemory(&bmpinfo, sizeof(bmpinfo)); bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmpinfo.bmiHeader.biWidth = width; bmpinfo.bmiHeader.biHeight = height; bmpinfo.bmiHeader.biPlanes = 1; bmpinfo.bmiHeader.biBitCount = 24; bmpinfo.bmiHeader.biCompression = BI_RGB; bmpinfo.bmiHeader.biXPelsPerMeter = 3780; bmpinfo.bmiHeader.biYPelsPerMeter = 3780; BYTE *pixels = new BYTE[bmpsize]; HBITMAP hbmpDIB = CreateDIBSection(NULL, &bmpinfo, DIB_RGB_COLORS, (void**)&pixels, NULL, NULL); if (hbmpDIB == NULL) { delete [] pixels; DeleteDC(hdcDisplay); return FALSE; } HDC hdcDIB = CreateCompatibleDC(hdcDisplay); if (SelectObject(hdcDIB, hbmpDIB) == NULL) { delete [] pixels; DeleteDC(hdcDisplay); return FALSE; } if (BitBlt(hdcDIB, 0, 0, width, height, hdcHBMP, 0, 0, SRCCOPY) == NULL) { delete [] pixels; DeleteDC(hdcDisplay); DeleteDC(hdcDIB); return FALSE; } BITMAPFILEHEADER bfh; ZeroMemory(&bfh, sizeof(bfh)); bfh.bfOffBits = sizeof(bmpinfo.bmiHeader)+sizeof(bfh); bfh.bfSize = bfh.bfOffBits+bmpsize; bfh.bfType = MAKEWORD('B', 'M'); HANDLE file = CreateFile(filename, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (file == INVALID_HANDLE_VALUE) { delete [] pixels; DeleteDC(hdcDisplay); DeleteDC(hdcDIB); return FALSE; } DWORD written; WriteFile(file, (LPCVOID)&bfh, sizeof(bfh), &written, NULL); WriteFile(file, (LPCVOID)&bmpinfo.bmiHeader, sizeof(bmpinfo.bmiHeader), &written, NULL); WriteFile(file, (LPCVOID)pixels, bmpsize, &written, NULL); CloseHandle(file); delete [] pixels; DeleteDC(hdcDisplay); DeleteDC(hdcDIB); return TRUE; } |
Anonymous
unregistriert
Zitat von »"nix da"«
John91
Frage: Wie hoch wäre der Lerneffekt gewesen wenn er auf die MSDN gegangen wäre und dort sich die Infos alleine beschaft hätte?
Und wie hoch ist der Lerneffekt wenn er jetzt ganz einfach Copy'n Paste macht?
Schäm dich
Werbeanzeige