ReactOS 0.4.15-dev-7887-g64a59a1
drawcap.c
Go to the documentation of this file.
1/*
2 * Copyright 2006 Saveliy Tretiakov
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19#include "windows.h"
20#include "resource.h"
21#include "stdio.h"
22
23WCHAR CaptWndClass[] = L"captwnd_class";
24
27
28//BOOL WINAPI (*DrawCaptionTemp) (
29// HWND hwnd,
30// HDC hdc,
31// const RECT *rect,
32// HFONT hFont,
33// HICON hIcon,
34// LPCWSTR str,
35// UINT uFlags);
36
38 HDC hDc,
39 LPRECT pR,
40 WCHAR *Text,
42 WCHAR *AddonStr,
43 DWORD Addon)
44{
45 WCHAR Buf[512];
46
47 lstrcpy(Buf, AddonStr);
48 if(lstrlen(Buf))lstrcat(Buf, L" | ");
49 lstrcat(Buf, Text);
50
51 DrawText( hDc, Buf, lstrlen(Buf), pR, DT_LEFT );
52
53 pR->top+=20;
54 pR->bottom+=20;
55
56 if(!DrawCaption(hWnd, hDc, pR, Flags | Addon))
57 {
58 printf("PAINT: DrawCaption failed: %d\n", (int)GetLastError());
59 }
60
61 pR->top+=30;
62 pR->bottom+=30;
63}
64
65VOID DrawCaptionTest(HWND hWnd, HDC hDc, WCHAR *AddonStr, DWORD Addon)
66{
67 RECT Rect;
69 Rect.bottom = 30;
70 Rect.left = 10;
71 Rect.right-=10;
72 Rect.top = 10;
73
74 CapTest(hWnd, hDc, &Rect, L"DC_TEXT:", DC_TEXT, AddonStr, Addon);
75
76 CapTest(hWnd, hDc, &Rect,
77 L"DC_TEXT | DC_ACTIVE:",
79 AddonStr, Addon);
80
81 CapTest(hWnd, hDc, &Rect,
82 L"DC_TEXT | DC_ICON:" ,
84 AddonStr, Addon);
85
86 CapTest(hWnd, hDc, &Rect,
87 L"DC_TEXT | DC_ACTIVE | DC_ICON:" ,
89 AddonStr, Addon);
90
91 CapTest(hWnd, hDc, &Rect,
92 L"DC_TEXT | DC_INBUTTON:" ,
94 AddonStr, Addon);
95
96 CapTest(hWnd, hDc, &Rect,
97 L"DC_TEXT | DC_ACTIVE | DC_INBUTTON:" ,
99 AddonStr, Addon);
100
101 CapTest(hWnd, hDc, &Rect,
102 L"DC_TEXT | DC_ICON | DC_INBUTTON:" ,
104 AddonStr, Addon);
105
106 CapTest(hWnd, hDc, &Rect,
107 L"DC_TEXT | DC_ACTIVE | DC_ICON | DC_INBUTTON:" ,
109 AddonStr, Addon);
110
111}
112
114 UINT msg,
117{
118
119
120 switch (msg)
121 {
122
123 case WM_PAINT:
124 {
125 HDC hDc;
126 PAINTSTRUCT Ps;
127
128 hDc = BeginPaint(hWnd, &Ps);
129 SetBkMode( hDc, TRANSPARENT );
130
131 switch(testnum)
132 {
133 case 1:
134 DrawCaptionTest(hWnd, hDc, L"", 0);
135 break;
136 case 2:
137 DrawCaptionTest(hWnd, hDc, L"DC_GRADIENT", DC_GRADIENT);
138 break;
139 case 3:
140 DrawCaptionTest(hWnd, hDc, L"DC_SMALLCAP", DC_SMALLCAP);
141 break;
142 case 4:
143 DrawCaptionTest(hWnd, hDc, L"DC_BUTTONS", DC_BUTTONS);
144 break;
145 case 5:
147 L"DC_GRADIENT | DC_SMALLCAP",
148 DC_GRADIENT | DC_SMALLCAP);
149 break;
150 case 6:
152 L"DC_GRADIENT | DC_BUTTONS",
153 DC_GRADIENT | DC_BUTTONS);
154 break;
155 case 7:
157 L"DC_BUTTONS | DC_SMALLCAP",
158 DC_BUTTONS | DC_SMALLCAP);
159 break;
160 case 8:
162 L"DC_BUTTONS | DC_SMALLCAP | DC_GRADIENT",
163 DC_BUTTONS | DC_SMALLCAP | DC_GRADIENT);
164 break;
165 }
166
167 EndPaint(hWnd, &Ps);
168
169 return 0;
170 }
171
172 case WM_DESTROY:
173 {
175 return 0;
176 }
177 }
178
180}
181
182
183int wmain(int argc, wchar_t**argv)
184{
185 HWND hWnd;
186 MSG msg;
187 WNDCLASSEX wcx;
188 UINT result;
189 HBRUSH hBr;
190 //HMODULE hLib;
191
192 if(argc<2)
193 {
194 printf("DrawCaption testcode.\n");
195 printf("USAGE: drawcap.exe <testnumber> [useicon]\n\n");
196 printf("Available tests:\n"
197 "1. DrawCaption test\n"
198 "2. DrawCaption test + DC_GRADIENT\n"
199 "3. DrawCaption test + DC_SMALLCAP\n"
200 "4. DrawCaption test + DC_BUTTONS\n"
201 "5. DrawCaption test + DC_GRADIENT | DC_SMALLCAP\n"
202 "6. DrawCaption test + DC_GRADIENT | DC_BUTTONS\n"
203 "7. DrawCaption test + DC_BUTTONS | DC_SMALLCAP\n"
204 "8. DrawCaption test + DC_BUTTONS | DC_SMALLCAP | DC_GRADIENT\n\n");
205 return 0;
206 }
207
208 testnum = _wtoi(argv[1]);
209 if(testnum < 1 || testnum > 8)
210 {
211 printf("Unknown test %d\n", testnum);
212 return 1;
213 }
214
216
217 //hLib = LoadLibrary(L"user32");
218 //if(!hLib)
219 //{
220 // printf("Shit! Can't load user32.dll\n");
221 // return 1;
222 //}
223
224 //DrawCaptionTemp = GetProcAddress(hLib, "DrawCaptionTempW");
225 //if(!DrawCaptionTemp)
226 //{
227 // printf("Shit! Can't get DrawCaptionTemp address\n");
228 // return 1;
229 //}
230
231 hBr = CreateSolidBrush(RGB(255, 255, 255));
232 if(!hBr)
233 {
234 printf("Shit! Can't create brush.");
235 return 1;
236 }
237
238 memset(&wcx, 0, sizeof(wcx));
239 wcx.cbSize = sizeof(wcx);
242 wcx.hInstance = hInst;
243 wcx.hbrBackground = hBr;
246
247 if(!(result = RegisterClassEx(&wcx)))
248 {
249 printf("Shit! RegisterClassEx failed: %d\n",
250 (int)GetLastError());
251 DeleteObject(hBr);
252 return 1;
253 }
254
257 L"DrawCaption test",
261 600,
262 470,
263 NULL,
264 0,
265 hInst,
266 NULL);
267
268 if(!hWnd)
269 {
270 printf("Shit! Can't create wnd!\n");
272 DeleteObject(hBr);
273 return 1;
274 }
275
276
279
280 while(GetMessage(&msg, NULL, 0, 0 ))
281 {
284 }
285
286 DeleteObject(hBr);
288 return 0;
289}
static int argc
Definition: ServiceArgs.c:12
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
WPARAM wParam
Definition: combotst.c:138
char * Text
Definition: combotst.c:136
LPARAM lParam
Definition: combotst.c:139
#define DC_ACTIVE
Definition: dc21x4.h:120
#define NULL
Definition: types.h:112
#define CALLBACK
Definition: compat.h:35
HINSTANCE hInst
Definition: drawcap.c:25
INT testnum
Definition: drawcap.c:26
VOID DrawCaptionTest(HWND hWnd, HDC hDc, WCHAR *AddonStr, DWORD Addon)
Definition: drawcap.c:65
WCHAR CaptWndClass[]
Definition: drawcap.c:23
LRESULT CALLBACK CaptWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: drawcap.c:113
VOID CapTest(HWND hWnd, HDC hDc, LPRECT pR, WCHAR *Text, DWORD Flags, WCHAR *AddonStr, DWORD Addon)
Definition: drawcap.c:37
#define RGB(r, g, b)
Definition: precomp.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
#define printf
Definition: freeldr.h:93
pKey DeleteObject()
GLuint64EXT * result
Definition: glext.h:11304
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
#define ID_ICON1SM
Definition: resource.h:5
static HDC
Definition: imagelist.c:92
#define argv
Definition: mplay32.c:18
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define WS_OVERLAPPED
Definition: pedump.c:615
#define WS_SYSMENU
Definition: pedump.c:629
#define WS_THICKFRAME
Definition: pedump.c:630
int wmain()
#define DefWindowProc
Definition: ros2win.h:31
#define memset(x, y, z)
Definition: compat.h:39
HINSTANCE hInstance
Definition: winuser.h:3206
HICON hIconSm
Definition: winuser.h:3212
UINT style
Definition: winuser.h:3202
UINT cbSize
Definition: winuser.h:3201
WNDPROC lpfnWndProc
Definition: winuser.h:3203
LPCSTR lpszClassName
Definition: winuser.h:3211
HBRUSH hbrBackground
Definition: winuser.h:3209
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
int32_t INT
Definition: typedefs.h:58
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define GetModuleHandle
Definition: winbase.h:3827
#define lstrcpy
Definition: winbase.h:3874
#define lstrlen
Definition: winbase.h:3876
#define lstrcat
Definition: winbase.h:3871
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define TRANSPARENT
Definition: wingdi.h:950
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1056
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
#define WM_PAINT
Definition: winuser.h:1620
#define CS_VREDRAW
Definition: winuser.h:658
#define CreateWindowEx
Definition: winuser.h:5755
#define DC_INBUTTON
Definition: winuser.h:431
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI DrawCaption(_In_ HWND, _In_ HDC, _In_ LPCRECT, _In_ UINT)
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define CS_HREDRAW
Definition: winuser.h:653
#define UnregisterClass
Definition: winuser.h:5861
#define DrawText
Definition: winuser.h:5771
#define GetMessage
Definition: winuser.h:5790
#define DT_LEFT
Definition: winuser.h:534
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define RegisterClassEx
Definition: winuser.h:5837
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
#define LoadIcon
Definition: winuser.h:5813
BOOL WINAPI UpdateWindow(_In_ HWND)
#define DC_TEXT
Definition: winuser.h:430
#define CW_USEDEFAULT
Definition: winuser.h:225
#define SW_SHOW
Definition: winuser.h:775
#define WM_DESTROY
Definition: winuser.h:1609
#define DC_ICON
Definition: winuser.h:429
#define DispatchMessage
Definition: winuser.h:5765
#define DC_SMALLCAP
Definition: winuser.h:428
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2906
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
#define MAKEINTRESOURCE
Definition: winuser.h:591
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__wchar_t WCHAR
Definition: xmlstorage.h:180