ReactOS  0.4.15-dev-1197-g8081ba9
dibtest.c File Reference
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for dibtest.c:

Go to the source code of this file.

Macros

#define CELL_SIZE   10
 

Functions

LRESULT WINAPI MainWndProc (HWND, UINT, WPARAM, LPARAM)
 
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
 
static void PaintCells (HDC WindowDC, WORD BitCount1, WORD BitCount2, int XDest, int YDest)
 

Variables

static RGBQUAD Colors []
 

Macro Definition Documentation

◆ CELL_SIZE

#define CELL_SIZE   10

Definition at line 5 of file dibtest.c.

Function Documentation

◆ MainWndProc()

LRESULT WINAPI MainWndProc ( HWND  Wnd,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 144 of file dibtest.c.

145 {
146  PAINTSTRUCT ps;
147  HDC WindowDC;
148 
149  switch(msg)
150  {
151  case WM_PAINT:
152  WindowDC = BeginPaint(Wnd, &ps);
153 
154  PaintCells(WindowDC, 4, 4, 0, 0);
155  PaintCells(WindowDC, 4, 8, 5 * CELL_SIZE, 0);
156  PaintCells(WindowDC, 4, 16, 10 * CELL_SIZE, 0);
157  PaintCells(WindowDC, 4, 24, 15 * CELL_SIZE, 0);
158  PaintCells(WindowDC, 4, 32, 20 * CELL_SIZE, 0);
159 
160  PaintCells(WindowDC, 8, 4, 0, 5 * CELL_SIZE);
161  PaintCells(WindowDC, 8, 8, 5 * CELL_SIZE, 5 * CELL_SIZE);
162  PaintCells(WindowDC, 8, 16, 10 * CELL_SIZE, 5 * CELL_SIZE);
163  PaintCells(WindowDC, 8, 24, 15 * CELL_SIZE, 5 * CELL_SIZE);
164  PaintCells(WindowDC, 8, 32, 20 * CELL_SIZE, 5 * CELL_SIZE);
165 
166  PaintCells(WindowDC, 16, 4, 0, 10 * CELL_SIZE);
167  PaintCells(WindowDC, 16, 8, 5 * CELL_SIZE, 10 * CELL_SIZE);
168  PaintCells(WindowDC, 16, 16, 10 * CELL_SIZE, 10 * CELL_SIZE);
169  PaintCells(WindowDC, 16, 24, 15 * CELL_SIZE, 10 * CELL_SIZE);
170  PaintCells(WindowDC, 16, 32, 20 * CELL_SIZE, 10 * CELL_SIZE);
171 
172  PaintCells(WindowDC, 24, 4, 0, 15 * CELL_SIZE);
173  PaintCells(WindowDC, 24, 8, 5 * CELL_SIZE, 15 * CELL_SIZE);
174  PaintCells(WindowDC, 24, 16, 10 * CELL_SIZE, 15 * CELL_SIZE);
175  PaintCells(WindowDC, 24, 24, 15 * CELL_SIZE, 15 * CELL_SIZE);
176  PaintCells(WindowDC, 24, 32, 20 * CELL_SIZE, 15 * CELL_SIZE);
177 
178  PaintCells(WindowDC, 32, 4, 0, 20 * CELL_SIZE);
179  PaintCells(WindowDC, 32, 8, 5 * CELL_SIZE, 20 * CELL_SIZE);
180  PaintCells(WindowDC, 32, 16, 10 * CELL_SIZE, 20 * CELL_SIZE);
181  PaintCells(WindowDC, 32, 24, 15 * CELL_SIZE, 20 * CELL_SIZE);
182  PaintCells(WindowDC, 32, 32, 20 * CELL_SIZE, 20 * CELL_SIZE);
183 
184  EndPaint(Wnd, &ps);
185  break;
186 
187  case WM_DESTROY:
188  PostQuitMessage(0);
189  break;
190 
191  default:
192  return DefWindowProc(Wnd, msg, wParam, lParam);
193  }
194 
195  return 0;
196 }
static HDC
Definition: imagelist.c:92
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
WPARAM wParam
Definition: combotst.c:138
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
static void PaintCells(HDC WindowDC, WORD BitCount1, WORD BitCount2, int XDest, int YDest)
Definition: dibtest.c:85
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1591
#define WM_PAINT
Definition: winuser.h:1602
#define CELL_SIZE
Definition: dibtest.c:5
#define msg(x)
Definition: auth_time.c:54
LPARAM lParam
Definition: combotst.c:139
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)

Referenced by WinMain().

◆ PaintCells()

static void PaintCells ( HDC  WindowDC,
WORD  BitCount1,
WORD  BitCount2,
int  XDest,
int  YDest 
)
static

Definition at line 85 of file dibtest.c.

87 {
88  HBRUSH Brush;
89  RECT Rect;
90  UINT row, col;
91  BITMAPINFO *BitmapInfo;
92  HBITMAP DIB1, DIB2;
93  HDC DC1, DC2;
94 
95  BitmapInfo = malloc(sizeof(BITMAPINFO) + 15 * sizeof(RGBQUAD));
96  BitmapInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
97  BitmapInfo->bmiHeader.biWidth = 4 * CELL_SIZE + 9;
98  BitmapInfo->bmiHeader.biHeight = -(4 * CELL_SIZE + 9); // it's top down (since BI_RGB is used, the sign is operative of direction)
99  BitmapInfo->bmiHeader.biPlanes = 1;
100  BitmapInfo->bmiHeader.biBitCount = BitCount1;
101  BitmapInfo->bmiHeader.biCompression = BI_RGB;
102  BitmapInfo->bmiHeader.biSizeImage = 0;
103  BitmapInfo->bmiHeader.biXPelsPerMeter = 0;
104  BitmapInfo->bmiHeader.biYPelsPerMeter = 0;
105  BitmapInfo->bmiHeader.biClrUsed = 16;
106  BitmapInfo->bmiHeader.biClrImportant = 16;
107  for (col = 0; col < 16; col++) {
108  BitmapInfo->bmiColors[col] = Colors[col];
109  }
110  DIB1 = CreateDIBSection(NULL, BitmapInfo, DIB_RGB_COLORS, NULL, NULL, 0);
111  DC1 = CreateCompatibleDC(NULL);
112  SelectObject(DC1, DIB1);
113 
114  BitmapInfo->bmiHeader.biBitCount = BitCount2;
115  DIB2 = CreateDIBSection(NULL, BitmapInfo, DIB_RGB_COLORS, NULL, NULL, 0);
116  DC2 = CreateCompatibleDC(NULL);
117  SelectObject(DC2, DIB2);
118  free(BitmapInfo);
119 
120  /* Now paint on the first bitmap */
121  for (row = 0; row < 4; row++)
122  {
123  for (col = 0; col < 4; col++)
124  {
125  Brush = CreateSolidBrush(RGB(Colors[4 * row + col].rgbRed,
126  Colors[4 * row + col].rgbGreen,
127  Colors[4 * row + col].rgbBlue));
128  Rect.left = CELL_SIZE * col + 5;
129  Rect.top = CELL_SIZE * row + 5;
130  Rect.right = Rect.left + CELL_SIZE;
131  Rect.bottom = Rect.top + CELL_SIZE;
132  FillRect(DC1, &Rect, Brush);
134  }
135  }
136 
137  /* Copy the first bitmap to the second */
138  BitBlt(DC2, 4, 4, 4 * CELL_SIZE, 4 * CELL_SIZE, DC1, 5, 5, SRCCOPY);
139 
140  /* Show results on screen */
141  BitBlt(WindowDC, XDest, YDest, 4 * CELL_SIZE, 4 * CELL_SIZE, DC2, 4, 4, SRCCOPY);
142 }
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1475
DWORD biClrImportant
Definition: amvideo.idl:40
#define RGB(r, g, b)
Definition: precomp.h:62
LONG biXPelsPerMeter
Definition: amvideo.idl:37
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
#define free
Definition: debug_ros.c:5
static HDC
Definition: imagelist.c:92
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1499
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
LONG biYPelsPerMeter
Definition: amvideo.idl:38
DWORD biCompression
Definition: amvideo.idl:35
void Brush(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF color, LONG style)
Definition: drawing.cpp:160
smooth NULL
Definition: ftsmooth.c:416
ULONG RGBQUAD
Definition: precomp.h:50
RGBQUAD bmiColors[1]
Definition: wingdi.h:1476
Colors
Definition: ansiprsr.h:4
DWORD biSizeImage
Definition: amvideo.idl:36
#define CELL_SIZE
Definition: dibtest.c:5
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:197
unsigned int UINT
Definition: ndis.h:50
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
#define malloc
Definition: debug_ros.c:4
static HBITMAP
Definition: button.c:44
#define DIB_RGB_COLORS
Definition: wingdi.h:366
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
#define BI_RGB
Definition: precomp.h:47
#define SRCCOPY
Definition: wingdi.h:332
static VOID NTAPI BitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_reads_bytes_(Delta *Height) PUCHAR Buffer, _In_ ULONG BitsPerPixel, _In_ ULONG Delta)
Definition: common.c:49
struct Rect Rect
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:78

Referenced by MainWndProc().

◆ WinMain()

int WINAPI WinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPSTR  lpszCmdLine,
int  nCmdShow 
)

Definition at line 30 of file dibtest.c.

34 {
35  WNDCLASS wc;
36  MSG msg;
37  HWND hWnd;
38 
39  wc.lpszClassName = "DibTestClass";
42  wc.hInstance = hInstance;
46  wc.lpszMenuName = NULL;
47  wc.cbClsExtra = 0;
48  wc.cbWndExtra = 0;
49  if (RegisterClass(&wc) == 0)
50  {
51  fprintf(stderr, "RegisterClass failed (last error 0x%lX)\n",
52  GetLastError());
53  return(1);
54  }
55 
56  hWnd = CreateWindow("DibTestClass",
57  "DIB Test",
61  25 * CELL_SIZE + 5,
62  25 * CELL_SIZE + 20,
63  NULL,
64  NULL,
65  hInstance,
66  NULL);
67  if (hWnd == NULL)
68  {
69  fprintf(stderr, "CreateWindow failed (last error 0x%lX)\n",
70  GetLastError());
71  return(1);
72  }
73 
74  ShowWindow(hWnd, nCmdShow);
75 
76  while(GetMessage(&msg, NULL, 0, 0))
77  {
80  }
81 
82  return msg.wParam;
83 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define DispatchMessage
Definition: winuser.h:5740
BOOL WINAPI TranslateMessage(_In_ const MSG *)
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define CreateWindow
Definition: winuser.h:5729
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
HWND hWnd
Definition: settings.c:17
int cbClsExtra
Definition: winuser.h:3140
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define CS_HREDRAW
Definition: winuser.h:648
LPCSTR lpszMenuName
Definition: winuser.h:3146
#define IDI_APPLICATION
Definition: winuser.h:699
HBRUSH hbrBackground
Definition: winuser.h:3145
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
int cbWndExtra
Definition: winuser.h:3141
HINSTANCE hInstance
Definition: charmap.c:20
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
HCURSOR hCursor
Definition: winuser.h:3144
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
#define GRAY_BRUSH
Definition: wingdi.h:897
LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM)
Definition: dibtest.c:144
#define CS_VREDRAW
Definition: winuser.h:653
#define CELL_SIZE
Definition: dibtest.c:5
LPCSTR lpszClassName
Definition: winuser.h:3147
#define LoadCursor
Definition: winuser.h:5787
UINT style
Definition: winuser.h:3138
HINSTANCE hInstance
Definition: winuser.h:3142
#define GetMessage
Definition: winuser.h:5765
WNDPROC lpfnWndProc
Definition: winuser.h:3139
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
FILE * stderr
#define RegisterClass
Definition: winuser.h:5811
#define LoadIcon
Definition: winuser.h:5788
HICON hIcon
Definition: winuser.h:3143

Variable Documentation

◆ Colors

RGBQUAD Colors[]
static
Initial value:
=
{
{ 0x00, 0x00, 0x00, 0x00 },
{ 0x00, 0x00, 0x80, 0x00 },
{ 0x00, 0x80, 0x00, 0x00 },
{ 0x00, 0x80, 0x80, 0x00 },
{ 0x80, 0x00, 0x00, 0x00 },
{ 0x80, 0x00, 0x80, 0x00 },
{ 0x80, 0x80, 0x00, 0x00 },
{ 0x80, 0x80, 0x80, 0x00 },
{ 0xc0, 0xc0, 0xc0, 0x00 },
{ 0x00, 0x00, 0xFF, 0x00 },
{ 0x00, 0xFF, 0x00, 0x00 },
{ 0x00, 0xFF, 0xFF, 0x00 },
{ 0xFF, 0x00, 0x00, 0x00 },
{ 0xFF, 0x00, 0xFF, 0x00 },
{ 0xFF, 0xFF, 0x00, 0x00 },
{ 0xFF, 0xFF, 0xFF, 0x00 }
}

Definition at line 7 of file dibtest.c.