12.12.2012 Views

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>C++</strong> Class Frameworks and the Visual Component Model<br />

8: HBITMAP hBitmap;<br />

9: void _huge *bits;<br />

10: do<br />

11: {<br />

12: if ((hFile = _lopen(data.FileName, OF_READ)) == HFILE_ERROR) break;<br />

13: if (_hread(hFile, &bfh, sizeof(bfh)) != sizeof(bfh)) break;<br />

<strong>14</strong>: if (bfh.bfType != ‘BM’) break;<br />

15: if (_hread(hFile, &bih, sizeof(bih)) != sizeof(bih)) break;<br />

16: nClrUsed =<br />

17: (bih.biClrUsed) ? bih.biClrUsed : 1 bmiColors, nSize) != nSize) break;<br />

25: if (_llseek(hFile, bfh.bfOffBits, 0) == HFILE_ERROR) break;<br />

26: nSize = bfh.bfSize-bfh.bfOffBits;<br />

27: if ((bits = GlobalAllocPtr(GHND, nSize)) == NULL) break;<br />

28: if (_hread(hFile, bits, nSize) != nSize) break;<br />

29: hDC = GetDC(hWnd);<br />

30: hBitmap = CreateDIBitmap(hDC, &(lpbi->bmiHeader), CBM_INIT,<br />

31: bits, lpbi, DIB_RGB_COLORS);<br />

32: if (hBitmap) {<br />

33: LPLOGPALETTE lppal;<br />

34: DWORD nsize = sizeof(LOGPALETTE)<br />

35: + (nClrUsed-1) * sizeof(PALETTEENTRY);<br />

36: lppal = (LPLOGPALETTE) GlobalAllocPtr(GHND, nSize);<br />

37: if (lppal) {<br />

38: lppal->palVersion = 0x0300;<br />

39: lppal->palNumEntries = (WORD) nClrUsed;<br />

40: hmemcpy(lppal->palPalEntry, lpbi->bmiColors,<br />

41: nClrUsed * sizeof(PALETTEENTRY));<br />

42: hPal = CreatePalette(lppal);<br />

43: (void) GlobalFreePtr(lppal);<br />

44: }<br />

45: }<br />

46: } while(FALSE);<br />

47: if (hFile != HFILE_ERROR) _lclose(hFile);<br />

48: HPALETTE oldPal = SelectPalette(hDC, hPal, FALSE);<br />

49: RealizePalette(hDC);<br />

50: HDC hMemDC = CreateCompatibleDC(hDC);<br />

51: HBITMAP oldBitmap =(HBITMAP)SelectObject(hMemDC, hBitmap);<br />

52: BitBlt(hDC, 0, 0, (WORD)bih.biWidth, (WORD)bih.biHeight,<br />

53: hMemDC, 0, 0, SRCCOPY);<br />

54: SelectObject(hMemDC, oldBitmap);<br />

55: DeleteDC(hMemDC);<br />

56: SelectPalette(hDC, oldPal, FALSE);<br />

57: ReleaseDC(hWnd, hDC);<br />

58: if (bits) (void) GlobalFreePtr(bits);<br />

59: if (lpbi) (void) GlobalFreePtr(lpbi);<br />

133<br />

5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!