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 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
16 //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
19 const char* WndClassName = "GMainWnd";
20 LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam,
24 int APIENTRY WinMain(HINSTANCE HInstance, HINSTANCE HPrevInstance,
25 LPTSTR lpCmdLine, int nCmdShow)
28 memset(&wc, 0, sizeof(WNDCLASS));
30 wc.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
31 wc.lpfnWndProc = MainWndProc;
32 wc.hInstance = HInstance;
33 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
35 reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1);
36 wc.lpszClassName = WndClassName;
38 if (RegisterClass(&wc))
41 CreateWindow(WndClassName, TEXT("WM_PAINT Demo"),
42 WS_OVERLAPPEDWINDOW | WS_CAPTION | WS_VISIBLE,
43 CW_USEDEFAULT, CW_USEDEFAULT, 200, 150,
44 NULL, NULL, HInstance, NULL);
48 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,
71 // determine the invalidated area of the window
73 GetUpdateRect(HWnd, &RUpdate, false);
75 // grab a handle to our window's
76 // common display device context
77 HDC Hdc = GetDC(HWnd);
83 GetClientRect(HWnd, &RClient);
85 // set the clipping region
86 IntersectClipRect(Hdc, RUpdate.left, RUpdate.top,
87 RUpdate.right, RUpdate.bottom);
89 // fill the client area with the background brush
91 reinterpret_cast<HBRUSH>(
92 GetClassLong(HWnd, GCL_HBRBACKGROUND)
94 FillRect(Hdc, &RClient, HBrush);
96 // render the persistent text
97 const char* text = "Persistent Text";
98 SetTextColor(Hdc, PALETTERGB(0, 0, 255));
99 DrawText(Hdc, text, strlen(text), &RClient,
100 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
106 // release the device context
107 ReleaseDC(HWnd, Hdc);
109 // validate the update area
110 ValidateRect(HWnd, &RUpdate);
112 // release the device context
113 ReleaseDC(HWnd, Hdc);
115 // validate the update area
116 ValidateRect(HWnd, &RUpdate);
126 return DefWindowProc(HWnd, Msg, WParam, LParam);
128 //------------------------------------------------------------------