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
![]() |
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 |
bool Graphics_LoadBitmap(const wchar_t *pFilename, HDC *pDC, HBITMAP *phBitmap) { HDC dcMainWindow; HANDLE hFile; unsigned long ulBitmapSize; BITMAPINFO bmInfo; BITMAPINFOHEADER bmFile; unsigned long ulBytesRead; char *pBitmapData = NULL; // Open file if(((hFile = CreateFile(pFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL))) == INVALID_HANDLE_VALUE) { return false; } if((!ReadFile(hFile, &bmFile, sizeof(BITMAPFILEHEADER), &ulBytesRead, NULL)) || (ulBytesRead != sizeof(BITMAPFILEHEADER))) { CloseHandle(hFile); return false; } if(!ReadFile(hFile, &bmInfo.bmiHeader, sizeof(BITMAPINFOHEADER), &ulBytesRead, NULL) || ulBytesRead != sizeof(BITMAPINFOHEADER) || bmInfo.bmiHeader.biCompression != BI_RGB || bmInfo.bmiHeader.biBitCount != 24) { CloseHandle(hFile); return false; } SetFilePointer(hFile, bmFile.biBitCount, NULL, FILE_BEGIN); // Calculate size of bitmap ulBitmapSize = ((bmInfo.bmiHeader.biWidth + 3) / 4) * 4; ulBitmapSize = (ulBitmapSize * (bmInfo.bmiHeader.biHeight * bmInfo.bmiHeader.biBitCount)) / 8; pBitmapData = new char[ulBitmapSize]; // Allocate memory if(!ReadFile(hFile, pBitmapData, ulBitmapSize, &ulBytesRead, NULL) || ulBytesRead != ulBitmapSize) { CloseHandle(hFile); delete pBitmapData; return false; } dcMainWindow = GetDC(Game.hWndMain); *pDC = CreateCompatibleDC(dcMainWindow); *phBitmap = CreateCompatibleBitmap(dcMainWindow, bmInfo.bmiHeader.biWidth, bmInfo.bmiHeader.biHeight); SetDIBits(*pDC, *phBitmap, 0, bmInfo.bmiHeader.biHeight, pBitmapData, &bmInfo, DIB_RGB_COLORS); SelectObject(*pDC, *phBitmap); delete pBitmapData; CloseHandle(hFile); ReleaseDC(Game.hWndMain, dcMainWindow); return true; } // Graphics_LoadBitmap() |
![]() |
C-/C++-Quelltext |
1 2 3 4 5 |
bool Graphics_LoadBitmaps() { Graphics_LoadBitmap(L"Bitmap.bmp", &dcPlayerDCs, &hPlayerBitmaps); return true; } // Graphics_LoadBitmaps() |
Anonymous
unregistriert
![]() |
C-/C++-Quelltext |
1 2 3 4 5 6 |
if(!ReadFile(hFile, pBitmapData, ulBitmapSize, &ulBytesRead, NULL) || ulBytesRead != ulBitmapSize) { CloseHandle(hFile); delete pBitmapData; return false; } |
![]() |
C-/C++-Quelltext |
1 2 3 4 5 6 |
if(!ReadFile(hFile, pBitmapData, ulBitmapSize, &ulBytesRead, NULL)) { CloseHandle(hFile); delete pBitmapData; return false; } |
Anonymous
unregistriert
Werbeanzeige