43 BITMAPFILEHEADER bitmapHeader;
44 BITMAPINFOHEADER bitmapInfoHeader;
45 LPLOGPALETTE lpLogPalette;
59 hBitmapFile = CreateFile(
63 (LPSECURITY_ATTRIBUTES)
NULL,
65 FILE_ATTRIBUTE_READONLY,
68 if (hBitmapFile==
NULL)
72 ReadFile(hBitmapFile, &bitmapHeader,
sizeof(BITMAPFILEHEADER), &dwRead,
77 ReadFile(hBitmapFile, &bitmapInfoHeader,
sizeof(BITMAPINFOHEADER),
78 &dwRead, (LPOVERLAPPED)
NULL);
82 HGLOBAL infoHeaderMem = GlobalAlloc(GHND,
sizeof(BITMAPINFOHEADER) +
83 ((1<<bitmapInfoHeader.biBitCount) *
sizeof(RGBQUAD)));
85 LPBITMAPINFO lpHeaderMem = (LPBITMAPINFO)GlobalLock(infoHeaderMem);
88 lpHeaderMem->bmiHeader.biSize = bitmapInfoHeader.biSize;
89 lpHeaderMem->bmiHeader.biWidth = bitmapInfoHeader.biWidth;
90 lpHeaderMem->bmiHeader.biHeight = bitmapInfoHeader.biHeight;
91 lpHeaderMem->bmiHeader.biPlanes = bitmapInfoHeader.biPlanes;
92 lpHeaderMem->bmiHeader.biBitCount = bitmapInfoHeader.biBitCount;
93 lpHeaderMem->bmiHeader.biCompression = bitmapInfoHeader.biCompression;
94 lpHeaderMem->bmiHeader.biSizeImage = bitmapInfoHeader.biSizeImage;
95 lpHeaderMem->bmiHeader.biXPelsPerMeter = bitmapInfoHeader.biXPelsPerMeter;
96 lpHeaderMem->bmiHeader.biYPelsPerMeter = bitmapInfoHeader.biYPelsPerMeter;
97 lpHeaderMem->bmiHeader.biClrUsed = bitmapInfoHeader.biClrUsed;
98 lpHeaderMem->bmiHeader.biClrImportant = bitmapInfoHeader.biClrImportant;
103 ReadFile(hBitmapFile, lpHeaderMem->bmiColors,
104 ((1<<bitmapInfoHeader.biBitCount) *
sizeof(RGBQUAD)),
105 &dwRead, (LPOVERLAPPED)
NULL);
108 lpLogPalette=(LPLOGPALETTE)
new char[(
sizeof(LOGPALETTE)+
109 sizeof(PALETTEENTRY)*256)];
110 lpLogPalette->palVersion=0x300;
111 lpLogPalette->palNumEntries=256;
113 palData=(
char *)lpHeaderMem->bmiColors;
115 for (i=0; i<256; i++)
117 lpLogPalette->palPalEntry[i].peRed=*palData++;
118 lpLogPalette->palPalEntry[i].peGreen=*palData++;
119 lpLogPalette->palPalEntry[i].peBlue=*palData++;
120 lpLogPalette->palPalEntry[i].peFlags=*palData++;
122 PalHandle_=CreatePalette(lpLogPalette);
123 delete(lpLogPalette);
127 hmem2 = GlobalAlloc(GHND, (bitmapHeader.bfSize - bitmapHeader.bfOffBits));
129 lpvBits = GlobalLock(hmem2);
132 ReadFile(hBitmapFile, lpvBits, (bitmapHeader.bfSize - bitmapHeader.bfOffBits),
133 &dwRead, (LPOVERLAPPED)
NULL);
138 select=SelectPalette(hdc,PalHandle_,0);
141 realize=RealizePalette(hdc);
142 if (realize==GDI_ERROR)
144 BitmapHandle_=CreateDIBitmap(hdc, &bitmapInfoHeader, CBM_INIT, lpvBits, lpHeaderMem, DIB_RGB_COLORS);
148 if (BitmapHandle_==
NULL)
152 GlobalUnlock(infoHeaderMem);
154 CloseHandle(hBitmapFile);
156 if (BitmapHandle_==
NULL)
160 GetClientRect(hwnd, &rect);
161 InvalidateRect(hwnd, &rect,
TRUE);
176 if (BitmapHandle_ ==
NULL)
179 InvalidateRect(WindowHandle_,
NULL,
FALSE);
181 hdc=BeginPaint(WindowHandle_,&ps);
184 HPALETTE select=SelectPalette(ps.hdc,PalHandle_,0);
187 sprintf(
string,
"Select Pal Fail: %d",GetLastError());
188 MessageBox(
NULL,
string,
"OK",MB_OK);
190 UINT realize=RealizePalette(ps.hdc);
191 if (realize==GDI_ERROR)
193 sprintf(
string,
"Realize Pal Fail: %d",GetLastError());
194 MessageBox(
NULL,
string,
"OK",MB_OK);
197 HDC hdcMem = CreateCompatibleDC(ps.hdc);
198 SelectObject(hdcMem, BitmapHandle_);
200 GetObject(BitmapHandle_,
sizeof(BITMAP), (LPSTR) &bm);
206 GetClientRect(WindowHandle_,&clientRect);
207 SetStretchBltMode(ps.hdc,COLORONCOLOR);
208 StretchBlt(ps.hdc,0,0,clientRect.right,clientRect.bottom,hdcMem,0,0,bm.bmWidth,
209 bm.bmHeight,SRCCOPY);
213 EndPaint(WindowHandle_,&ps);