24f00aa5b9cb949de8ef903d7d61c96f592d7126
2 // ------------------------------------------------------------------
3 // Windows 2000 Graphics API Black Book
4 // Chapter 1 - Listing 1.1 (WM_PAINT Demo)
6 // Created by Damon Chandler <dmc27@ee.cornell.edu>
7 // Updates can be downloaded at: <www.coriolis.com>
9 // Please do not hesistate to e-mail me at dmc27@ee.cornell.edu
10 // if you have any questions about this code.
11 // ------------------------------------------------------------------
14 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
17 //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
20 const char* WndClassName
= "GMainWnd";
21 LRESULT CALLBACK
MainWndProc(HWND HWnd
, UINT Msg
, WPARAM WParam
,
25 int APIENTRY
WinMain(HINSTANCE HInstance
, HINSTANCE HPrevInstance
,
26 LPTSTR lpCmdLine
, int nCmdShow
)
30 memset(&wc
, 0, sizeof(WNDCLASS
));
32 wc
.style
= CS_VREDRAW
| CS_HREDRAW
| CS_DBLCLKS
;
33 wc
.lpfnWndProc
= MainWndProc
;
34 wc
.hInstance
= HInstance
;
35 wc
.hCursor
= LoadCursor(NULL
, (LPCTSTR
)IDC_ARROW
);
36 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
37 wc
.lpszClassName
= WndClassName
;
39 if (RegisterClass(&wc
))
42 CreateWindow(WndClassName
, TEXT("WM_PAINT Demo"),
43 WS_OVERLAPPEDWINDOW
| WS_CAPTION
| WS_VISIBLE
,
44 CW_USEDEFAULT
, CW_USEDEFAULT
, 200, 150,
45 NULL
, NULL
, HInstance
, NULL
);
49 ShowWindow(HWnd
, nCmdShow
);
52 while (GetMessage(&msg
, NULL
, 0, 0))
54 TranslateMessage(&msg
);
55 DispatchMessage(&msg
);
61 //------------------------------------------------------------------
64 LRESULT CALLBACK
MainWndProc(HWND HWnd
, UINT Msg
, WPARAM WParam
,
67 const char* text
= "Persistent Text";
73 // determine the invalidated area of the window
76 GetUpdateRect(HWnd
, &RUpdate
, FALSE
);
78 // grab a handle to our window's
79 // common display device context
86 GetClientRect(HWnd
, &RClient
);
88 // set the clipping region
89 IntersectClipRect(Hdc
, RUpdate
.left
, RUpdate
.top
,
90 RUpdate
.right
, RUpdate
.bottom
);
92 // fill the client area with the background brush
94 reinterpret_cast<HBRUSH>
95 (HBRUSH)(GetClassLong(HWnd, GCL_HBRBACKGROUND)
97 FillRect(Hdc
, &RClient
, NULL
);
99 // render the persistent text
100 SetTextColor(Hdc
, PALETTERGB(0, 0, 255));
101 DrawText(Hdc
, text
, strlen(text
), &RClient
,
102 DT_CENTER
| DT_VCENTER
| DT_SINGLELINE
);
108 // release the device context
109 ReleaseDC(HWnd
, Hdc
);
111 // validate the update area
112 ValidateRect(HWnd
, &RUpdate
);
114 // release the device context
115 ReleaseDC(HWnd
, Hdc
);
117 // validate the update area
118 ValidateRect(HWnd
, &RUpdate
);
128 return DefWindowProc(HWnd
, Msg
, WParam
, LParam
);
130 //------------------------------------------------------------------