- BITMAP bm;
- BITMAPINFOHEADER bi;
- BITMAPINFOHEADER FAR *lpbi;
- DWORD dwLen;
- HANDLE hdib;
- HANDLE h;
- HDC hdc;
-
- if (!hbm)
- return NULL;
-
- if (hpal == NULL)
- hpal = GetStockObject(DEFAULT_PALETTE);
-
- GetObject(hbm, sizeof (bm), (LPSTR) &bm);
-
- if (biBits == 0)
- biBits = bm.bmPlanes * bm.bmBitsPixel;
-
- bi.biSize = sizeof(BITMAPINFOHEADER);
- bi.biWidth = bm.bmWidth;
- bi.biHeight = bm.bmHeight;
- bi.biPlanes = 1;
- bi.biBitCount = biBits;
- bi.biCompression = biStyle;
- bi.biSizeImage = 0;
- bi.biXPelsPerMeter = 0;
- bi.biYPelsPerMeter = 0;
- bi.biClrUsed = 0;
- bi.biClrImportant = 0;
-
- dwLen = bi.biSize + wxPaletteSize(&bi);
-
- hdc = GetDC((HWND) NULL);
- hpal = SelectPalette(hdc, hpal, FALSE);
- RealizePalette(hdc);
-
- hdib = GlobalAlloc(GHND, dwLen);
-
- if (!hdib) {
- SelectPalette(hdc, hpal, FALSE);
- ReleaseDC(NULL, hdc);
- return NULL;
- }
-
-#ifdef __WINDOWS_386__
- lpbi = (BITMAPINFOHEADER FAR *) MK_FP32(GlobalLock(hdib));
-#else
- lpbi = (BITMAPINFOHEADER FAR *) GlobalLock(hdib);
-#endif
-
- *lpbi = bi;
-
- /* call GetDIBits with a NULL lpBits param, so it will calculate the
- * biSizeImage field for us
- */
- GetDIBits(hdc, hbm, 0, (WORD) bi.biHeight,
- NULL, (LPBITMAPINFO) lpbi, DIB_RGB_COLORS);
-
- bi = *lpbi;
- GlobalUnlock(hdib);