| 3235 | } |
| 3236 | |
| 3237 | void CColorCopDlg::CreateBMPFile(HWND /*hwnd*/, LPTSTR pszFile, |
| 3238 | PBITMAPINFO pbi, HBITMAP hBMP, HDC hDC) { |
| 3239 | HANDLE hf; // file handle |
| 3240 | BITMAPFILEHEADER hdr; // bitmap file-header |
| 3241 | PBITMAPINFOHEADER pbih; // bitmap info-header |
| 3242 | LPBYTE lpBits; // memory pointer |
| 3243 | DWORD dwTotal; // total count of bytes |
| 3244 | DWORD cb; // incremental count of bytes |
| 3245 | BYTE* hp; // byte pointer |
| 3246 | DWORD dwTmp; |
| 3247 | |
| 3248 | pbih = (PBITMAPINFOHEADER) pbi; |
| 3249 | lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage); |
| 3250 | |
| 3251 | if (!lpBits) { |
| 3252 | AfxMessageBox(_T("GlobalAlloc failed")); |
| 3253 | return; |
| 3254 | } |
| 3255 | |
| 3256 | // Retrieve the color table (RGBQUAD array) and the bits |
| 3257 | // (array of palette indices) from the DIB. |
| 3258 | if (!GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi, |
| 3259 | DIB_RGB_COLORS)) { |
| 3260 | AfxMessageBox(_T("GetDIBits failed")); |
| 3261 | return; |
| 3262 | } |
| 3263 | |
| 3264 | // Create the .BMP file. |
| 3265 | hf = CreateFile(pszFile, |
| 3266 | GENERIC_READ | GENERIC_WRITE, |
| 3267 | static_cast<DWORD>(0), |
| 3268 | NULL, |
| 3269 | CREATE_ALWAYS, |
| 3270 | FILE_ATTRIBUTE_NORMAL, |
| 3271 | (HANDLE) NULL); |
| 3272 | if (hf == INVALID_HANDLE_VALUE) { |
| 3273 | TRACE(_T("Warning: Could not create BMP file: %s (error=%lu)\n"), pszFile, GetLastError()); |
| 3274 | return; |
| 3275 | } |
| 3276 | |
| 3277 | hdr.bfType = 0x4d42; // 0x42 = "B" 0x4d = "M" |
| 3278 | |
| 3279 | // Compute the size of the entire file. |
| 3280 | hdr.bfSize = static_cast<DWORD>((sizeof(BITMAPFILEHEADER)) + |
| 3281 | pbih->biSize + pbih->biClrUsed * sizeof(RGBQUAD) + pbih->biSizeImage); |
| 3282 | hdr.bfReserved1 = 0; |
| 3283 | hdr.bfReserved2 = 0; |
| 3284 | |
| 3285 | // Compute the offset to the array of color indices. |
| 3286 | hdr.bfOffBits = static_cast<DWORD>(sizeof(BITMAPFILEHEADER)) + |
| 3287 | pbih->biSize + pbih->biClrUsed * sizeof(RGBQUAD); |
| 3288 | |
| 3289 | // Copy the BITMAPFILEHEADER into the .BMP file. |
| 3290 | if (!WriteFile(hf, (LPVOID) &hdr, sizeof(BITMAPFILEHEADER), |
| 3291 | (LPDWORD) &dwTmp, NULL)) { |
| 3292 | AfxMessageBox(_T("WriteFile failed")); |
| 3293 | return; |
| 3294 | } |
nothing calls this directly
no outgoing calls
no test coverage detected