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)
29 memset(&wc, 0, sizeof(WNDCLASS));
31 wc.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
32 wc.lpfnWndProc = MainWndProc;
33 wc.hInstance = HInstance;
34 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
35 wc.hbrBackground = (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);
51 while (GetMessage(&msg, NULL, 0, 0))
53 TranslateMessage(&msg);
54 DispatchMessage(&msg);
60 //------------------------------------------------------------------
63 LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam,
66 const char* text = "Persistent Text";
72 // determine the invalidated area of the window
75 GetUpdateRect(HWnd, &RUpdate, NULL);
77 // grab a handle to our window's
78 // common display device context
85 GetClientRect(HWnd, &RClient);
87 // set the clipping region
88 IntersectClipRect(Hdc, RUpdate.left, RUpdate.top,
89 RUpdate.right, RUpdate.bottom);
91 // fill the client area with the background brush
93 //reinterpret_cast<HBRUSH>
94 (HBRUSH)(GetClassLong(HWnd, GCL_HBRBACKGROUND)
96 FillRect(Hdc, &RClient, NULL);
98 // render the persistent text
99 SetTextColor(Hdc, PALETTERGB(0, 0, 255));
100 DrawText(Hdc, text, strlen(text), &RClient,
101 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
107 // release the device context
108 ReleaseDC(HWnd, Hdc);
110 // validate the update area
111 ValidateRect(HWnd, &RUpdate);
113 // release the device context
114 ReleaseDC(HWnd, Hdc);
116 // validate the update area
117 ValidateRect(HWnd, &RUpdate);
127 return DefWindowProc(HWnd, Msg, WParam, LParam);
129 //------------------------------------------------------------------