ReactOS  0.4.12-dev-918-g6c6e7b8
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 
23 WCHAR 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,
41  DWORD Flags,
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 
65 VOID 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:" ,
83  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,
115  WPARAM wParam,
116  LPARAM lParam)
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:
146  DrawCaptionTest(hWnd, hDc,
147  L"DC_GRADIENT | DC_SMALLCAP",
148  DC_GRADIENT | DC_SMALLCAP);
149  break;
150  case 6:
151  DrawCaptionTest(hWnd, hDc,
152  L"DC_GRADIENT | DC_BUTTONS",
153  DC_GRADIENT | DC_BUTTONS);
154  break;
155  case 7:
156  DrawCaptionTest(hWnd, hDc,
157  L"DC_BUTTONS | DC_SMALLCAP",
158  DC_BUTTONS | DC_SMALLCAP);
159  break;
160  case 8:
161  DrawCaptionTest(hWnd, hDc,
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  {
174  PostQuitMessage(0);
175  return 0;
176  }
177  }
178 
179  return DefWindowProc(hWnd, msg, wParam, lParam);
180 }
181 
182 
183 int 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);
240  wcx.style = CS_HREDRAW | CS_VREDRAW;
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 
255  hWnd = CreateWindowEx(0,
256  CaptWndClass,
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 }
#define WS_THICKFRAME
Definition: pedump.c:630
UINT style
Definition: winuser.h:3155
static int argc
Definition: ServiceArgs.c:12
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define DispatchMessage
Definition: winuser.h:5631
BOOL WINAPI TranslateMessage(_In_ const MSG *)
#define RegisterClassEx
Definition: winuser.h:5703
HINSTANCE hInst
Definition: drawcap.c:25
INT testnum
Definition: drawcap.c:26
WNDPROC lpfnWndProc
Definition: winuser.h:3156
LPCSTR lpszClassName
Definition: winuser.h:3164
int wmain(int argc, wchar_t **argv)
Definition: drawcap.c:183
BOOL WINAPI DrawCaption(_In_ HWND, _In_ HDC, _In_ LPCRECT, _In_ UINT)
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:27
BOOL WINAPI UpdateWindow(_In_ HWND)
HWND hWnd
Definition: settings.c:17
LONG top
Definition: windef.h:292
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define CS_HREDRAW
Definition: winuser.h:648
UINT_PTR WPARAM
Definition: windef.h:207
HICON hIconSm
Definition: winuser.h:3165
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
#define argv
Definition: mplay32.c:18
int32_t INT
Definition: typedefs.h:56
WPARAM wParam
Definition: combotst.c:138
#define DrawText
Definition: winuser.h:5637
#define DC_ICON
Definition: winuser.h:429
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1032
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define DT_LEFT
Definition: winuser.h:534
HINSTANCE hInstance
Definition: winuser.h:3159
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
#define CreateWindowEx
Definition: winuser.h:5621
#define TRANSPARENT
Definition: wingdi.h:949
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
UINT cbSize
Definition: winuser.h:3154
#define SW_SHOW
Definition: winuser.h:769
HBRUSH hbrBackground
Definition: winuser.h:3162
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1591
#define DC_ACTIVE
Definition: winuser.h:427
#define CS_VREDRAW
Definition: winuser.h:653
#define WS_OVERLAPPED
Definition: pedump.c:615
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define ID_ICON1SM
Definition: resource.h:5
#define RGB(r, g, b)
Definition: wingdi.h:2918
unsigned long DWORD
Definition: ntddk_ex.h:95
WCHAR CaptWndClass[]
Definition: drawcap.c:23
#define WM_PAINT
Definition: winuser.h:1602
static const WCHAR L[]
Definition: oid.c:1250
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2859
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define lstrlen
Definition: winbase.h:3690
#define DC_SMALLCAP
Definition: winuser.h:428
#define GetModuleHandle
Definition: winbase.h:3641
#define lstrcpy
Definition: winbase.h:3688
unsigned int UINT
Definition: ndis.h:50
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
#define GetMessage
Definition: winuser.h:5656
#define msg(x)
Definition: auth_time.c:54
VOID DrawCaptionTest(HWND hWnd, HDC hDc, WCHAR *AddonStr, DWORD Addon)
Definition: drawcap.c:65
LONG bottom
Definition: windef.h:294
#define LoadIcon
Definition: winuser.h:5679
LONG_PTR LRESULT
Definition: windef.h:209
#define UnregisterClass
Definition: winuser.h:5727
#define WS_SYSMENU
Definition: pedump.c:629
GLuint64EXT * result
Definition: glext.h:11304
#define memset(x, y, z)
Definition: compat.h:39
LRESULT CALLBACK CaptWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: drawcap.c:113
#define lstrcat
Definition: winbase.h:3685
LPARAM lParam
Definition: combotst.c:139
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define DC_TEXT
Definition: winuser.h:430
VOID CapTest(HWND hWnd, HDC hDc, LPRECT pR, WCHAR *Text, DWORD Flags, WCHAR *AddonStr, DWORD Addon)
Definition: drawcap.c:37
struct Rect Rect
char * Text
Definition: combotst.c:136
#define printf
Definition: config.h:203
#define DC_INBUTTON
Definition: winuser.h:431