- bool CGsPreviewCtrl::GetPreviewIcon( AcDbBlockTableRecord::PreviewIcon &icn )
- {
- CDC *view = GetDC();
- HDC hview = view->GetSafeHdc();
- HDC hCompDC = CreateCompatibleDC(hview);
- int nWidth = 32;
- int nHeight = 32;
- HBITMAP hBmp = CreateCompatibleBitmap(hview, nWidth, nHeight);
- HBITMAP hOld = (HBITMAP)SelectObject(hCompDC, hBmp);
- BitBlt(hCompDC, 0, 0, nWidth, nHeight, hview, 0, 0, SRCCOPY);
-
- BITMAP bmp;
- GetObject(hBmp, sizeof(BITMAP), (void*)&bmp);
- BITMAPINFOHEADER bi;
- ZeroMemory(&bi,sizeof(BITMAPINFOHEADER));
- bi.biSize = sizeof(BITMAPINFOHEADER);
- bi.biWidth = bmp.bmWidth;
- bi.biHeight = bmp.bmHeight;
- bi.biPlanes = 1;
- bi.biBitCount = 32;
- bi.biCompression = BI_RGB;
- DWORD dwBmpSize = ((bmp.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmp.bmHeight;
- HANDLE hDIB = GlobalAlloc(GHND,dwBmpSize);
- Adesk::UInt8 *bmpBuffer = (Adesk::UInt8*)GlobalLock(hDIB);
-
- int res = GetDIBits(hview, hBmp, 0,(UINT)bmp.bmHeight, bmpBuffer,(BITMAPINFO *)&bi, DIB_RGB_COLORS);
- icn.setLogicalLength(dwBmpSize);
- memcpy(icn.asArrayPtr(),bmpBuffer,dwBmpSize);
- GlobalUnlock(hDIB);
- GlobalFree(hDIB);
- DeleteObject(hBmp);
- ReleaseDC(view);
- DeleteDC(hCompDC);
- return true;
- }