1 /* The idea of this test app is inspired from tutorial *
2 * found at http://www.theparticle.com/pgraph.html *
4 * Developed by: Aleksey Bragin <aleksey@studiocerebral.com> *
13 // special version of BITMAPINFO and LOGPALETTE for max of 256 palette entries
16 BITMAPINFOHEADER bmiHeader
;
17 RGBQUAD bmiColors
[256];
23 PALETTEENTRY palPalEntry
[256];
26 // The only global variable --- contents of the DIBitmap
29 void GeneratePalette(RGBQUAD
* p
)
41 void DoBlt(HBITMAP hBM
)
48 if((ActiveWindow
= GetActiveWindow()) == NULL
)
51 hDC
= GetDC(ActiveWindow
);
52 GetClientRect(ActiveWindow
,&dest
);
54 Context
= CreateCompatibleDC(0);
55 dflBmp
= SelectObject(Context
, hBM
);
56 BitBlt(hDC
, 0, 0, dest
.right
, dest
.bottom
, Context
, 0, 0, SRCCOPY
);
57 SelectObject(Context
, dflBmp
);
60 ReleaseDC(ActiveWindow
, hDC
);
63 void UpdatePalette(HBITMAP hBM
){
65 static unsigned int c
=0;
67 for(i
=0;i
<W_WIDTH
;i
++){
68 for(y
=0;y
<=W_HEIGHT
-1;y
++)
69 dibits
[y
*320+i
] = c
% 256;
74 c
++; // It's operation of incrementing of c variable, not reference of a cool OO language :-)
80 void InitBitmap(HANDLE
*hBM
){
89 ActiveWindow
= GetActiveWindow();
90 hDC
= GetDC(ActiveWindow
);
92 bmInf
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
93 bmInf
.bmiHeader
.biWidth
= W_WIDTH
;
94 bmInf
.bmiHeader
.biHeight
= -abs(W_HEIGHT
);
95 bmInf
.bmiHeader
.biPlanes
= 1;
96 bmInf
.bmiHeader
.biBitCount
= 8;
97 bmInf
.bmiHeader
.biCompression
= BI_RGB
;
98 bmInf
.bmiHeader
.biSizeImage
= 0;
99 bmInf
.bmiHeader
.biXPelsPerMeter
= 0;
100 bmInf
.bmiHeader
.biYPelsPerMeter
= 0;
101 bmInf
.bmiHeader
.biClrUsed
= 256;
102 bmInf
.bmiHeader
.biClrImportant
= 256;
104 GeneratePalette(palette
);
107 bmInf
.bmiColors
[i
] = palette
[i
];
109 palInf
.palVersion
= 0x300;
110 palInf
.palNumEntries
= 256;
112 palInf
.palPalEntry
[i
].peRed
= palette
[i
].rgbRed
;
113 palInf
.palPalEntry
[i
].peGreen
= palette
[i
].rgbGreen
;
114 palInf
.palPalEntry
[i
].peBlue
= palette
[i
].rgbBlue
;
115 palInf
.palPalEntry
[i
].peFlags
= PC_NOCOLLAPSE
;
119 PalHan
= CreatePalette((LOGPALETTE
*)&palInf
);
121 // Select it into hDC
122 SelectPalette(hDC
,PalHan
,FALSE
);
124 // Realize palette in hDC
127 // Delete handle to palette
128 DeleteObject(PalHan
);
130 // Create dib section
131 *hBM
= CreateDIBSection(hDC
,(BITMAPINFO
*)&bmInf
,
132 DIB_RGB_COLORS
,(void**)&dibits
,0,0);
135 ReleaseDC(ActiveWindow
,hDC
);
138 LRESULT CALLBACK
WndProc(HWND hWnd
,UINT msg
, WPARAM wParam
,LPARAM lParam
)
145 return DefWindowProc(hWnd
,msg
,wParam
,lParam
);
151 int WINAPI
WinMain(HINSTANCE hInstance
,HINSTANCE hPrevInstance
, LPSTR lpszCmdParam
,int nCmdShow
)
156 char szName
[] = "Palette BitBlt test";
160 // Create and register window class (not modified!!!!!!!!!!!1)
161 WndClass
.style
= CS_HREDRAW
|CS_VREDRAW
|CS_OWNDC
;
162 WndClass
.lpfnWndProc
= WndProc
;
163 WndClass
.cbClsExtra
= 0;
164 WndClass
.cbWndExtra
= 0;
165 WndClass
.hbrBackground
= NULL
;//GetStockObject(BLACK_BRUSH);
166 WndClass
.hIcon
= NULL
;//LoadIcon(hInstance,NULL);
167 WndClass
.hCursor
= NULL
;//LoadCursor(NULL,IDC_ARROW);
168 WndClass
.hInstance
= hInstance
;
169 WndClass
.lpszClassName
= szName
;
170 WndClass
.lpszMenuName
= 0;
172 RegisterClass(&WndClass
);
174 // Create and show window (change styles !!!!!!!!)
175 hWnd
= CreateWindow(szName
, "ReactOS palette bitblt test",
176 WS_CAPTION
|WS_MINIMIZEBOX
|WS_SYSMENU
,
177 CW_USEDEFAULT
,CW_USEDEFAULT
,W_WIDTH
,W_HEIGHT
,
179 ShowWindow(hWnd
,nCmdShow
);
181 // Prepare bitmap to be bitblt
190 if(PeekMessage(&msg
,0,0,0,PM_NOREMOVE
) == TRUE
)
192 if (!GetMessage(&msg
,0,0,0))
195 TranslateMessage(&msg
);
196 DispatchMessage(&msg
);