ReactOS 0.4.15-dev-7924-g5949c20
wm_paint.c
Go to the documentation of this file.
1
2// ------------------------------------------------------------------
3// Windows 2000 Graphics API Black Book
4// Chapter 1 - Listing 1.1 (WM_PAINT Demo)
5//
6// Created by Damon Chandler <dmc27@ee.cornell.edu>
7// Updates can be downloaded at: <www.coriolis.com>
8//
9// Please do not hesistate to e-mail me at dmc27@ee.cornell.edu
10// if you have any questions about this code.
11// ------------------------------------------------------------------
12
13
14//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
15#include <windows.h>
16#include <string.h>
17//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
18
19
20const char* WndClassName = "GMainWnd";
22 LPARAM LParam);
23
24
25int APIENTRY WinMain(HINSTANCE HInstance, HINSTANCE HPrevInstance,
26 LPTSTR lpCmdLine, int nCmdShow)
27{
28 MSG msg;
29 WNDCLASS wc;
30 memset(&wc, 0, sizeof(WNDCLASS));
31
34 wc.hInstance = HInstance;
36 wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
38
39 if (RegisterClass(&wc))
40 {
41 HWND HWnd =
42 CreateWindow(WndClassName, TEXT("WM_PAINT Demo"),
45 NULL, NULL, HInstance, NULL);
46
47 if (HWnd)
48 {
49 ShowWindow(HWnd, nCmdShow);
50 UpdateWindow(HWnd);
51
52 while (GetMessage(&msg, NULL, 0, 0))
53 {
56 }
57 }
58 }
59 return 0;
60}
61//------------------------------------------------------------------
62
63
65 LPARAM LParam)
66{
67 const char* text = "Persistent Text";
68
69 switch (Msg)
70 {
71 case WM_PAINT:
72 {
73 // determine the invalidated area of the window
74 RECT RUpdate;
75 HDC Hdc;
76 GetUpdateRect(HWnd, &RUpdate, FALSE);
77
78 // grab a handle to our window's
79 // common display device context
80 Hdc = GetDC(HWnd);
81#if 0
82 try
83#endif
84 {
85 RECT RClient;
86 GetClientRect(HWnd, &RClient);
87
88 // set the clipping region
89 IntersectClipRect(Hdc, RUpdate.left, RUpdate.top,
90 RUpdate.right, RUpdate.bottom);
91
92 // fill the client area with the background brush
93 /*HBRUSH HBrush =
94 reinterpret_cast<HBRUSH>
95 (HBRUSH)(GetClassLong(HWnd, GCL_HBRBACKGROUND)
96 );*/
97 FillRect(Hdc, &RClient, NULL);
98
99 // render the persistent text
100 SetTextColor(Hdc, PALETTERGB(0, 0, 255));
101 DrawText(Hdc, text, strlen(text), &RClient,
103 }
104#if 0
105 catch (...)
106#endif
107 {
108 // release the device context
109 ReleaseDC(HWnd, Hdc);
110
111 // validate the update area
112 ValidateRect(HWnd, &RUpdate);
113 }
114 // release the device context
115 ReleaseDC(HWnd, Hdc);
116
117 // validate the update area
118 ValidateRect(HWnd, &RUpdate);
119
120 break;
121 }
122 case WM_DESTROY:
123 {
125 return 0;
126 }
127 }
128 return DefWindowProc(HWnd, Msg, WParam, LParam);
129}
130//------------------------------------------------------------------
131
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define msg(x)
Definition: auth_time.c:54
struct @1632 Msg[]
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define APIENTRY
Definition: api.h:79
#define CALLBACK
Definition: compat.h:35
const WCHAR * text
Definition: package.c:1799
#define TEXT(s)
Definition: k32.h:26
static HDC
Definition: imagelist.c:92
unsigned int UINT
Definition: ndis.h:50
#define WS_CAPTION
Definition: pedump.c:624
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define WS_VISIBLE
Definition: pedump.c:620
#define DefWindowProc
Definition: ros2win.h:31
#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
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
int WINAPI IntersectClipRect(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
#define PALETTERGB(r, g, b)
Definition: wingdi.h:2942
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:918
#define WM_PAINT
Definition: winuser.h:1620
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define CS_VREDRAW
Definition: winuser.h:658
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define DT_CENTER
Definition: winuser.h:527
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define DT_SINGLELINE
Definition: winuser.h:540
BOOL WINAPI ValidateRect(_In_opt_ HWND, _In_opt_ LPCRECT)
#define CS_HREDRAW
Definition: winuser.h:653
#define IDC_ARROW
Definition: winuser.h:687
#define CS_DBLCLKS
Definition: winuser.h:651
#define DrawText
Definition: winuser.h:5771
#define CreateWindow
Definition: winuser.h:5754
#define GetMessage
Definition: winuser.h:5790
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI UpdateWindow(_In_ HWND)
#define LoadCursor
Definition: winuser.h:5812
HDC WINAPI GetDC(_In_opt_ HWND)
#define DT_VCENTER
Definition: winuser.h:543
#define CW_USEDEFAULT
Definition: winuser.h:225
#define RegisterClass
Definition: winuser.h:5836
#define WM_DESTROY
Definition: winuser.h:1609
#define DispatchMessage
Definition: winuser.h:5765
BOOL WINAPI GetUpdateRect(_In_ HWND, _Out_opt_ LPRECT, _In_ BOOL)
#define COLOR_BTNFACE
Definition: winuser.h:928
const char * WndClassName
Definition: wm_paint.c:20
int APIENTRY WinMain(HINSTANCE HInstance, HINSTANCE HPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
Definition: wm_paint.c:25
LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam, LPARAM LParam)
Definition: wm_paint.c:64
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
CHAR * LPTSTR
Definition: xmlstorage.h:192