ReactOS 0.4.15-dev-7918-g2a2556c
patblt.cpp File Reference
#include <windows.h>
Include dependency graph for patblt.cpp:

Go to the source code of this file.

Functions

LRESULT CALLBACK MainWndProc (HWND HWnd, UINT Msg, WPARAM WParam, LPARAM LParam)
 
int APIENTRY WinMain (HINSTANCE HInstance, HINSTANCE, LPTSTR, int nCmdShow)
 
void MapRect (IN HWND HWndFrom, IN HWND HWndTo, IN OUT RECT &RMap)
 
void RenderTrackingRect (IN HDC HDestDC, IN const RECT &RRender)
 

Variables

HINSTANCE HInst
 
const charWndClassName = "GMainWnd"
 
HDC HMemDC = NULL
 
HBITMAP HOldBmp = NULL
 
const charfilename = "PENGUIN.BMP"
 
RECT RImage = {225, 110, 225, 110}
 
bool is_tracking = false
 
HDC HScreenDC = NULL
 
POINT PMouse = {0, 0}
 
RECT RTrack = {0, 0, 0, 0}
 
const int line_width = 5
 

Function Documentation

◆ MainWndProc()

LRESULT CALLBACK MainWndProc ( HWND  HWnd,
UINT  Msg,
WPARAM  WParam,
LPARAM  LParam 
)

Definition at line 128 of file patblt.cpp.

130{
131 switch (Msg)
132 {
133 case WM_CREATE:
134 {
135 // create a memory DC
137 if (HMemDC)
138 {
139 // load the penguin bitmap
140 HBITMAP HBmp = static_cast<HBITMAP>(
143 );
144 if (HBmp)
145 {
146 // get the bitmap's dimensions
147 BITMAP bmp;
148 if (GetObject(HBmp, sizeof(BITMAP), &bmp))
149 {
150 RImage.right += bmp.bmWidth;
151 RImage.bottom += bmp.bmHeight;
152
153 // realize the bitmap
154 HOldBmp = static_cast<HBITMAP>(
156 );
157 }
158 else DeleteObject(HBmp);
159 }
160 }
161 break;
162 }
163 case WM_LBUTTONDOWN:
164 {
165 PMouse.x = LOWORD(LParam);
166 PMouse.y = HIWORD(LParam);
167
168 RECT RClient;
169 if (PtInRect(&RImage, PMouse) &&
170 GetClientRect(HWnd, &RClient))
171 {
172 MapRect(HWnd, HWND_DESKTOP, RClient);
173 ClipCursor(&RClient);
174
175 // grab a handle to the screen DC and clip
176 // all output to the client area of our window
178 HRGN HClipRgn = CreateRectRgnIndirect(&RClient);
179 SelectClipRgn(HScreenDC, HClipRgn);
180 DeleteObject(HClipRgn);
181
184
185 // render the first tracking rect
187 is_tracking = true;
188 }
189 break;
190 }
191 case WM_MOUSEMOVE:
192 {
193 if (HScreenDC && is_tracking)
194 {
195 POINT PCurrent = {LOWORD(LParam), HIWORD(LParam)};
196 const int dX = PCurrent.x - PMouse.x;
197 const int dY = PCurrent.y - PMouse.y;
198
199 // erase the previous rectangle
201 // update the postion
202 OffsetRect(&RTrack, dX, dY);
203 // render the new tracking rectangle
205
206 // update the mouse position
207 memcpy(&PMouse, &PCurrent, sizeof(POINT));
208 }
209 break;
210 }
211 case WM_LBUTTONUP:
212 {
213 // clean up
214 if (is_tracking)
215 {
216 is_tracking = false;
219
220 InvalidateRect(HWnd, &RImage, true);
223 InvalidateRect(HWnd, &RImage, true);
224
226 }
227 break;
228 }
229 case WM_PAINT:
230 {
231 PAINTSTRUCT ps;
232 HDC Hdc = BeginPaint(HWnd, &ps);
233 try
234 {
235 //
236 // TODO: Add palette support...
237 //
238
239 // render the penguin
243 HMemDC, 0, 0,
244 SRCCOPY);
245 }
246 catch (...)
247 {
248 EndPaint(HWnd, &ps);
249 }
250 EndPaint(HWnd, &ps);
251 break;
252 }
253 case WM_DESTROY:
254 {
255 // clean up
256 if (HOldBmp)
257 {
259 }
260 if (HMemDC)
261 {
263 }
265 return 0;
266 }
267 }
268 return DefWindowProc(HWnd, Msg, WParam, LParam);
269}
struct @1632 Msg[]
#define NULL
Definition: types.h:112
static VOID 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:57
pKey DeleteObject()
const char * filename
Definition: ioapi.h:137
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
BITMAP bmp
Definition: alphablend.c:62
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:92
bool is_tracking
Definition: patblt.cpp:77
HDC HMemDC
Definition: patblt.cpp:71
void RenderTrackingRect(IN HDC HDestDC, IN const RECT &RRender)
Definition: patblt.cpp:97
RECT RImage
Definition: patblt.cpp:74
HDC HScreenDC
Definition: patblt.cpp:78
HINSTANCE HInst
Definition: patblt.cpp:19
RECT RTrack
Definition: patblt.cpp:80
POINT PMouse
Definition: patblt.cpp:79
void MapRect(IN HWND HWndFrom, IN HWND HWndTo, IN OUT RECT &RMap)
Definition: patblt.cpp:85
HBITMAP HOldBmp
Definition: patblt.cpp:72
#define LOWORD(l)
Definition: pedump.c:82
#define DefWindowProc
Definition: ros2win.h:31
Definition: bl.h:1331
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
#define HIWORD(l)
Definition: typedefs.h:247
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define SRCCOPY
Definition: wingdi.h:333
#define GetObject
Definition: wingdi.h:4468
HRGN WINAPI CreateRectRgnIndirect(_In_ LPCRECT)
BOOL WINAPI DeleteDC(_In_ HDC)
int WINAPI SelectClipRgn(_In_ HDC, _In_opt_ HRGN)
#define WM_PAINT
Definition: winuser.h:1620
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
BOOL WINAPI CopyRect(_Out_ LPRECT, _In_ LPCRECT)
#define IMAGE_BITMAP
Definition: winuser.h:211
#define LR_LOADFROMFILE
Definition: winuser.h:1092
#define WM_CREATE
Definition: winuser.h:1608
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
BOOL WINAPI ClipCursor(_In_opt_ LPCRECT)
#define WM_MOUSEMOVE
Definition: winuser.h:1775
#define WM_LBUTTONDOWN
Definition: winuser.h:1776
#define HWND_DESKTOP
Definition: winuser.h:1209
BOOL WINAPI PtInRect(_In_ LPCRECT, _In_ POINT)
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
HDC WINAPI GetDC(_In_opt_ HWND)
#define WM_LBUTTONUP
Definition: winuser.h:1777
#define LoadImage
Definition: winuser.h:5815
BOOL WINAPI OffsetRect(_Inout_ LPRECT, _In_ int, _In_ int)
#define WM_DESTROY
Definition: winuser.h:1609
#define LR_DEFAULTSIZE
Definition: winuser.h:1094
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
HBITMAP HBmp

Referenced by WinMain().

◆ MapRect()

void MapRect ( IN HWND  HWndFrom,
IN HWND  HWndTo,
IN OUT RECT RMap 
)

Definition at line 85 of file patblt.cpp.

86{
88 HWndFrom, HWndTo,
89 reinterpret_cast<LPPOINT>(&RMap), 2
90 );
91}
int WINAPI MapWindowPoints(_In_opt_ HWND hWndFrom, _In_opt_ HWND hWndTo, _Inout_updates_(cPoints) LPPOINT lpPoints, _In_ UINT cPoints)

Referenced by MainWndProc().

◆ RenderTrackingRect()

void RenderTrackingRect ( IN HDC  HDestDC,
IN const RECT RRender 
)

Definition at line 97 of file patblt.cpp.

98{
99 const int width = RRender.right - RRender.left;
100 const int height = RRender.bottom - RRender.top;
101 const DWORD dwROP3 = DSTINVERT; // experiment with others
102
103 // render top bar
104 PatBlt(HDestDC,
105 RRender.left, RRender.top,
107 dwROP3);
108 // render bottom bar
109 PatBlt(HDestDC,
110 RRender.left, RRender.bottom - line_width,
112 dwROP3);
113 // render left bar
114 PatBlt(HDestDC,
115 RRender.left, RRender.top + line_width,
117 dwROP3);
118 // render right bar
119 PatBlt(HDestDC,
120 RRender.right - line_width, RRender.top + line_width,
122 dwROP3);
123
124}
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
const int line_width
Definition: patblt.cpp:81
#define DSTINVERT
Definition: wingdi.h:327
BOOL WINAPI PatBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)

Referenced by MainWndProc().

◆ WinMain()

int APIENTRY WinMain ( HINSTANCE  HInstance,
HINSTANCE  ,
LPTSTR  ,
int  nCmdShow 
)

Definition at line 25 of file patblt.cpp.

27{
28 HInst = HInstance;
29
30 WNDCLASS wc;
31 memset(&wc, 0, sizeof(WNDCLASS));
32
36 wc.hInstance = HInstance;
38 wc.hbrBackground = static_cast<HBRUSH>(
40 );
41
42 if (RegisterClass(&wc))
43 {
44 HWND HWnd =
46 TEXT("PatBlt Tracking Rect Demo"),
50 NULL, NULL, HInst, NULL);
51
52 if (HWnd)
53 {
54 ShowWindow(HWnd, nCmdShow);
55 UpdateWindow(HWnd);
56
57 MSG msg;
58 while (GetMessage(&msg, NULL, 0, 0))
59 {
62 }
63 }
64 }
65 return 0;
66}
#define msg(x)
Definition: auth_time.c:54
#define TEXT(s)
Definition: k32.h:26
const char * WndClassName
Definition: patblt.cpp:20
LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, LPARAM LParam)
Definition: patblt.cpp:128
#define WS_CAPTION
Definition: pedump.c:624
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define WS_VISIBLE
Definition: pedump.c:620
#define WS_CLIPCHILDREN
Definition: pedump.c:619
#define memset(x, y, z)
Definition: compat.h:39
HBRUSH hbrBackground
Definition: winuser.h:3170
HINSTANCE hInstance
Definition: winuser.h:3167
HCURSOR hCursor
Definition: winuser.h:3169
UINT style
Definition: winuser.h:3163
LPCSTR lpszClassName
Definition: winuser.h:3172
WNDPROC lpfnWndProc
Definition: winuser.h:3164
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define BLACK_BRUSH
Definition: wingdi.h:896
#define CS_VREDRAW
Definition: winuser.h:658
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define CS_HREDRAW
Definition: winuser.h:653
#define IDC_ARROW
Definition: winuser.h:687
#define CreateWindow
Definition: winuser.h:5754
#define GetMessage
Definition: winuser.h:5790
BOOL WINAPI UpdateWindow(_In_ HWND)
#define LoadCursor
Definition: winuser.h:5812
#define CW_USEDEFAULT
Definition: winuser.h:225
#define RegisterClass
Definition: winuser.h:5836
#define DispatchMessage
Definition: winuser.h:5765

Variable Documentation

◆ filename

const char* filename = "PENGUIN.BMP"

Definition at line 73 of file patblt.cpp.

◆ HInst

HINSTANCE HInst

Definition at line 19 of file patblt.cpp.

Referenced by MainWndProc(), and WinMain().

◆ HMemDC

HDC HMemDC = NULL

Definition at line 71 of file patblt.cpp.

Referenced by MainWndProc().

◆ HOldBmp

HBITMAP HOldBmp = NULL

Definition at line 72 of file patblt.cpp.

Referenced by MainWndProc().

◆ HScreenDC

HDC HScreenDC = NULL

Definition at line 78 of file patblt.cpp.

Referenced by MainWndProc().

◆ is_tracking

bool is_tracking = false

Definition at line 77 of file patblt.cpp.

Referenced by MainWndProc().

◆ line_width

const int line_width = 5

Definition at line 81 of file patblt.cpp.

Referenced by RenderTrackingRect().

◆ PMouse

POINT PMouse = {0, 0}

Definition at line 79 of file patblt.cpp.

Referenced by MainWndProc().

◆ RImage

RECT RImage = {225, 110, 225, 110}

Definition at line 74 of file patblt.cpp.

Referenced by MainWndProc().

◆ RTrack

RECT RTrack = {0, 0, 0, 0}

Definition at line 80 of file patblt.cpp.

Referenced by MainWndProc().

◆ WndClassName

const char* WndClassName = "GMainWnd"

Definition at line 20 of file patblt.cpp.

Referenced by WinMain().