Adding rostests as part of the tree restructure
[reactos.git] / rostests / tests / wm_paint / wm_paint.c
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
20 const char* WndClassName = "GMainWnd";
21 LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam,
22 LPARAM LParam);
23
24
25 int 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
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;
38
39 if (RegisterClass(&wc))
40 {
41 HWND HWnd =
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);
46
47 if (HWnd)
48 {
49 ShowWindow(HWnd, nCmdShow);
50 UpdateWindow(HWnd);
51
52 while (GetMessage(&msg, NULL, 0, 0))
53 {
54 TranslateMessage(&msg);
55 DispatchMessage(&msg);
56 }
57 }
58 }
59 return 0;
60 }
61 //------------------------------------------------------------------
62
63
64 LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam,
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,
102 DT_CENTER | DT_VCENTER | DT_SINGLELINE);
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 {
124 PostQuitMessage(0);
125 return 0;
126 }
127 }
128 return DefWindowProc(HWnd, Msg, WParam, LParam);
129 }
130 //------------------------------------------------------------------
131