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> *
12 // special version of BITMAPINFO and LOGPALETTE for max of 256 palette entries
15 BITMAPINFOHEADER bmiHeader;
16 RGBQUAD bmiColors[256];
22 PALETTEENTRY palPalEntry[256];
25 // The only global variable --- contents of the DIBitmap
28 void GeneratePalette(RGBQUAD* p)
40 void DoBlt(HBITMAP hBM)
47 if((ActiveWindow = GetActiveWindow()) == NULL)
50 hDC = GetDC(ActiveWindow);
51 GetClientRect(ActiveWindow,&dest);
53 Context = CreateCompatibleDC(0);
54 dflBmp = SelectObject(Context, hBM);
55 BitBlt(hDC, 0, 0, dest.right, dest.bottom, Context, 0, 0, SRCCOPY);
56 SelectObject(Context, dflBmp);
59 ReleaseDC(ActiveWindow, hDC);
62 void UpdatePalette(HBITMAP hBM){
64 static unsigned int c=0;
66 for(i=0;i<W_WIDTH;i++){
67 for(y=0;y<=W_HEIGHT-1;y++)
68 dibits[y*320+i] = c % 256;
73 c++; // It's operation of incrementing of c variable, not reference of a cool OO language :-)
79 void InitBitmap(HANDLE *hBM){
88 ActiveWindow = GetActiveWindow();
89 hDC = GetDC(ActiveWindow);
91 bmInf.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
92 bmInf.bmiHeader.biWidth = W_WIDTH;
93 bmInf.bmiHeader.biHeight = -abs(W_HEIGHT);
94 bmInf.bmiHeader.biPlanes = 1;
95 bmInf.bmiHeader.biBitCount = 8;
96 bmInf.bmiHeader.biCompression = BI_RGB;
97 bmInf.bmiHeader.biSizeImage = 0;
98 bmInf.bmiHeader.biXPelsPerMeter = 0;
99 bmInf.bmiHeader.biYPelsPerMeter = 0;
100 bmInf.bmiHeader.biClrUsed = 256;
101 bmInf.bmiHeader.biClrImportant = 256;
103 GeneratePalette(palette);
106 bmInf.bmiColors[i] = palette[i];
108 palInf.palVersion = 0x300;
109 palInf.palNumEntries = 256;
111 palInf.palPalEntry[i].peRed = palette[i].rgbRed;
112 palInf.palPalEntry[i].peGreen = palette[i].rgbGreen;
113 palInf.palPalEntry[i].peBlue = palette[i].rgbBlue;
114 palInf.palPalEntry[i].peFlags = PC_NOCOLLAPSE;
118 PalHan = CreatePalette((LOGPALETTE*)&palInf);
120 // Select it into hDC
121 SelectPalette(hDC,PalHan,FALSE);
123 // Realize palette in hDC
126 // Delete handle to palette
127 DeleteObject(PalHan);
129 // Create dib section
130 *hBM = CreateDIBSection(hDC,(BITMAPINFO*)&bmInf,
131 DIB_RGB_COLORS,(void**)&dibits,0,0);
134 ReleaseDC(ActiveWindow,hDC);
137 LRESULT CALLBACK WndProc(HWND hWnd,UINT msg, WPARAM wParam,LPARAM lParam)
144 return DefWindowProc(hWnd,msg,wParam,lParam);
150 int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpszCmdParam,int nCmdShow)
155 char szName[] = "Palette BitBlt test";
159 // Create and register window class (not modified!!!!!!!!!!!1)
160 WndClass.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC;
161 WndClass.lpfnWndProc = WndProc;
162 WndClass.cbClsExtra = 0;
163 WndClass.cbWndExtra = 0;
164 WndClass.hbrBackground = NULL;//GetStockObject(BLACK_BRUSH);
165 WndClass.hIcon = NULL;//LoadIcon(hInstance,NULL);
166 WndClass.hCursor = NULL;//LoadCursor(NULL,IDC_ARROW);
167 WndClass.hInstance = hInstance;
168 WndClass.lpszClassName = szName;
169 WndClass.lpszMenuName = 0;
171 RegisterClass(&WndClass);
173 // Create and show window (change styles !!!!!!!!)
174 hWnd = CreateWindow(szName, "ReactOS palette bitblt test",
175 WS_CAPTION|WS_MINIMIZEBOX|WS_SYSMENU,
176 CW_USEDEFAULT,CW_USEDEFAULT,W_WIDTH,W_HEIGHT,
178 ShowWindow(hWnd,nCmdShow);
180 // Prepare bitmap to be bitblt
189 if(PeekMessage(&msg,0,0,0,PM_NOREMOVE) == TRUE)
191 if (!GetMessage(&msg,0,0,0))
194 TranslateMessage(&msg);
195 DispatchMessage(&msg);