1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  *  Copyright 2006 Saveliy Tretiakov
3*c2c66affSColin Finck  *
4*c2c66affSColin Finck  *  This program is free software; you can redistribute it and/or modify
5*c2c66affSColin Finck  *  it under the terms of the GNU General Public License as published by
6*c2c66affSColin Finck  *  the Free Software Foundation; either version 2 of the License, or
7*c2c66affSColin Finck  *  (at your option) any later version.
8*c2c66affSColin Finck  *
9*c2c66affSColin Finck  *  This program is distributed in the hope that it will be useful,
10*c2c66affSColin Finck  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11*c2c66affSColin Finck  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12*c2c66affSColin Finck  *  GNU General Public License for more details.
13*c2c66affSColin Finck  *
14*c2c66affSColin Finck  *  You should have received a copy of the GNU General Public License
15*c2c66affSColin Finck  *  along with this program; if not, write to the Free Software
16*c2c66affSColin Finck  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17*c2c66affSColin Finck  */
18*c2c66affSColin Finck 
19*c2c66affSColin Finck #include "windows.h"
20*c2c66affSColin Finck #include "resource.h"
21*c2c66affSColin Finck #include "stdio.h"
22*c2c66affSColin Finck 
23*c2c66affSColin Finck WCHAR CaptWndClass[] = L"captwnd_class";
24*c2c66affSColin Finck 
25*c2c66affSColin Finck HINSTANCE hInst;
26*c2c66affSColin Finck INT testnum = 0;
27*c2c66affSColin Finck 
28*c2c66affSColin Finck //BOOL WINAPI (*DrawCaptionTemp) (
29*c2c66affSColin Finck //		 HWND        hwnd,
30*c2c66affSColin Finck //		 HDC         hdc,
31*c2c66affSColin Finck //		 const RECT *rect,
32*c2c66affSColin Finck //		 HFONT       hFont,
33*c2c66affSColin Finck //		 HICON       hIcon,
34*c2c66affSColin Finck //		 LPCWSTR     str,
35*c2c66affSColin Finck //		 UINT        uFlags);
36*c2c66affSColin Finck 
CapTest(HWND hWnd,HDC hDc,LPRECT pR,WCHAR * Text,DWORD Flags,WCHAR * AddonStr,DWORD Addon)37*c2c66affSColin Finck VOID CapTest(HWND hWnd,
38*c2c66affSColin Finck 	HDC hDc,
39*c2c66affSColin Finck 	LPRECT pR,
40*c2c66affSColin Finck 	WCHAR *Text,
41*c2c66affSColin Finck 	DWORD Flags,
42*c2c66affSColin Finck 	WCHAR *AddonStr,
43*c2c66affSColin Finck 	DWORD Addon)
44*c2c66affSColin Finck {
45*c2c66affSColin Finck 	WCHAR Buf[512];
46*c2c66affSColin Finck 
47*c2c66affSColin Finck 	lstrcpy(Buf, AddonStr);
48*c2c66affSColin Finck 	if(lstrlen(Buf))lstrcat(Buf, L" | ");
49*c2c66affSColin Finck 	lstrcat(Buf, Text);
50*c2c66affSColin Finck 
51*c2c66affSColin Finck 	DrawText( hDc, Buf, lstrlen(Buf), pR, DT_LEFT );
52*c2c66affSColin Finck 
53*c2c66affSColin Finck 	pR->top+=20;
54*c2c66affSColin Finck 	pR->bottom+=20;
55*c2c66affSColin Finck 
56*c2c66affSColin Finck 	if(!DrawCaption(hWnd, hDc, pR, Flags | Addon))
57*c2c66affSColin Finck 	{
58*c2c66affSColin Finck 		printf("PAINT: DrawCaption failed: %d\n", (int)GetLastError());
59*c2c66affSColin Finck 	}
60*c2c66affSColin Finck 
61*c2c66affSColin Finck 	pR->top+=30;
62*c2c66affSColin Finck 	pR->bottom+=30;
63*c2c66affSColin Finck }
64*c2c66affSColin Finck 
DrawCaptionTest(HWND hWnd,HDC hDc,WCHAR * AddonStr,DWORD Addon)65*c2c66affSColin Finck VOID DrawCaptionTest(HWND hWnd, HDC hDc, WCHAR *AddonStr, DWORD Addon)
66*c2c66affSColin Finck {
67*c2c66affSColin Finck 	RECT Rect;
68*c2c66affSColin Finck 	GetClientRect(hWnd, &Rect);
69*c2c66affSColin Finck 	Rect.bottom = 30;
70*c2c66affSColin Finck 	Rect.left = 10;
71*c2c66affSColin Finck 	Rect.right-=10;
72*c2c66affSColin Finck 	Rect.top = 10;
73*c2c66affSColin Finck 
74*c2c66affSColin Finck 	CapTest(hWnd, hDc, &Rect, L"DC_TEXT:", DC_TEXT, AddonStr, Addon);
75*c2c66affSColin Finck 
76*c2c66affSColin Finck 	CapTest(hWnd, hDc, &Rect,
77*c2c66affSColin Finck 		L"DC_TEXT | DC_ACTIVE:",
78*c2c66affSColin Finck 		DC_TEXT | DC_ACTIVE,
79*c2c66affSColin Finck 		AddonStr, Addon);
80*c2c66affSColin Finck 
81*c2c66affSColin Finck 	CapTest(hWnd, hDc, &Rect,
82*c2c66affSColin Finck 		L"DC_TEXT | DC_ICON:" ,
83*c2c66affSColin Finck 		DC_TEXT | DC_ICON,
84*c2c66affSColin Finck 		AddonStr, Addon);
85*c2c66affSColin Finck 
86*c2c66affSColin Finck 	CapTest(hWnd, hDc, &Rect,
87*c2c66affSColin Finck 		L"DC_TEXT | DC_ACTIVE | DC_ICON:" ,
88*c2c66affSColin Finck 		DC_TEXT | DC_ACTIVE | DC_ICON,
89*c2c66affSColin Finck 		AddonStr, Addon);
90*c2c66affSColin Finck 
91*c2c66affSColin Finck 	CapTest(hWnd, hDc, &Rect,
92*c2c66affSColin Finck 		L"DC_TEXT | DC_INBUTTON:" ,
93*c2c66affSColin Finck 		DC_TEXT | DC_INBUTTON,
94*c2c66affSColin Finck 		AddonStr, Addon);
95*c2c66affSColin Finck 
96*c2c66affSColin Finck 	CapTest(hWnd, hDc, &Rect,
97*c2c66affSColin Finck 		L"DC_TEXT | DC_ACTIVE | DC_INBUTTON:" ,
98*c2c66affSColin Finck 		DC_TEXT | DC_ACTIVE | DC_INBUTTON,
99*c2c66affSColin Finck 		AddonStr, Addon);
100*c2c66affSColin Finck 
101*c2c66affSColin Finck 	CapTest(hWnd, hDc, &Rect,
102*c2c66affSColin Finck 		L"DC_TEXT | DC_ICON | DC_INBUTTON:" ,
103*c2c66affSColin Finck 		DC_TEXT | DC_ICON | DC_INBUTTON,
104*c2c66affSColin Finck 		AddonStr, Addon);
105*c2c66affSColin Finck 
106*c2c66affSColin Finck 	CapTest(hWnd, hDc, &Rect,
107*c2c66affSColin Finck 		L"DC_TEXT | DC_ACTIVE | DC_ICON | DC_INBUTTON:" ,
108*c2c66affSColin Finck 		DC_TEXT | DC_ACTIVE | DC_ICON | DC_INBUTTON,
109*c2c66affSColin Finck 		AddonStr, Addon);
110*c2c66affSColin Finck 
111*c2c66affSColin Finck }
112*c2c66affSColin Finck 
CaptWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)113*c2c66affSColin Finck LRESULT CALLBACK CaptWndProc(HWND hWnd,
114*c2c66affSColin Finck 							 UINT msg,
115*c2c66affSColin Finck 							 WPARAM wParam,
116*c2c66affSColin Finck 							 LPARAM lParam)
117*c2c66affSColin Finck {
118*c2c66affSColin Finck 
119*c2c66affSColin Finck 
120*c2c66affSColin Finck 	switch (msg)
121*c2c66affSColin Finck 	{
122*c2c66affSColin Finck 
123*c2c66affSColin Finck 		case WM_PAINT:
124*c2c66affSColin Finck 		{
125*c2c66affSColin Finck 			HDC hDc;
126*c2c66affSColin Finck 			PAINTSTRUCT Ps;
127*c2c66affSColin Finck 
128*c2c66affSColin Finck 			hDc = BeginPaint(hWnd, &Ps);
129*c2c66affSColin Finck 			SetBkMode( hDc, TRANSPARENT );
130*c2c66affSColin Finck 
131*c2c66affSColin Finck 			switch(testnum)
132*c2c66affSColin Finck 			{
133*c2c66affSColin Finck 			case 1:
134*c2c66affSColin Finck 				DrawCaptionTest(hWnd, hDc, L"", 0);
135*c2c66affSColin Finck 				break;
136*c2c66affSColin Finck 			case 2:
137*c2c66affSColin Finck 				DrawCaptionTest(hWnd, hDc, L"DC_GRADIENT", DC_GRADIENT);
138*c2c66affSColin Finck 				break;
139*c2c66affSColin Finck 			case 3:
140*c2c66affSColin Finck 				DrawCaptionTest(hWnd, hDc, L"DC_SMALLCAP", DC_SMALLCAP);
141*c2c66affSColin Finck 				break;
142*c2c66affSColin Finck 			case 4:
143*c2c66affSColin Finck 				DrawCaptionTest(hWnd, hDc, L"DC_BUTTONS", DC_BUTTONS);
144*c2c66affSColin Finck 				break;
145*c2c66affSColin Finck 			case 5:
146*c2c66affSColin Finck 				DrawCaptionTest(hWnd, hDc,
147*c2c66affSColin Finck 					L"DC_GRADIENT | DC_SMALLCAP",
148*c2c66affSColin Finck 					DC_GRADIENT | DC_SMALLCAP);
149*c2c66affSColin Finck 				break;
150*c2c66affSColin Finck 			case 6:
151*c2c66affSColin Finck 				DrawCaptionTest(hWnd, hDc,
152*c2c66affSColin Finck 					L"DC_GRADIENT | DC_BUTTONS",
153*c2c66affSColin Finck 					DC_GRADIENT | DC_BUTTONS);
154*c2c66affSColin Finck 				break;
155*c2c66affSColin Finck 			case 7:
156*c2c66affSColin Finck 				DrawCaptionTest(hWnd, hDc,
157*c2c66affSColin Finck 					L"DC_BUTTONS | DC_SMALLCAP",
158*c2c66affSColin Finck 					DC_BUTTONS | DC_SMALLCAP);
159*c2c66affSColin Finck 				break;
160*c2c66affSColin Finck 			case 8:
161*c2c66affSColin Finck 				DrawCaptionTest(hWnd, hDc,
162*c2c66affSColin Finck 					L"DC_BUTTONS | DC_SMALLCAP | DC_GRADIENT",
163*c2c66affSColin Finck 					DC_BUTTONS | DC_SMALLCAP | DC_GRADIENT);
164*c2c66affSColin Finck 				break;
165*c2c66affSColin Finck 			}
166*c2c66affSColin Finck 
167*c2c66affSColin Finck 			EndPaint(hWnd, &Ps);
168*c2c66affSColin Finck 
169*c2c66affSColin Finck 			return 0;
170*c2c66affSColin Finck 		}
171*c2c66affSColin Finck 
172*c2c66affSColin Finck 		case WM_DESTROY:
173*c2c66affSColin Finck 		{
174*c2c66affSColin Finck 			PostQuitMessage(0);
175*c2c66affSColin Finck 			return 0;
176*c2c66affSColin Finck 		}
177*c2c66affSColin Finck 	}
178*c2c66affSColin Finck 
179*c2c66affSColin Finck 	return DefWindowProc(hWnd, msg, wParam, lParam);
180*c2c66affSColin Finck }
181*c2c66affSColin Finck 
182*c2c66affSColin Finck 
wmain(int argc,wchar_t ** argv)183*c2c66affSColin Finck int wmain(int argc, wchar_t**argv)
184*c2c66affSColin Finck {
185*c2c66affSColin Finck 	HWND hWnd;
186*c2c66affSColin Finck 	MSG msg;
187*c2c66affSColin Finck 	WNDCLASSEX wcx;
188*c2c66affSColin Finck 	UINT result;
189*c2c66affSColin Finck 	HBRUSH hBr;
190*c2c66affSColin Finck 	//HMODULE hLib;
191*c2c66affSColin Finck 
192*c2c66affSColin Finck 	if(argc<2)
193*c2c66affSColin Finck 	{
194*c2c66affSColin Finck 		printf("DrawCaption testcode.\n");
195*c2c66affSColin Finck 		printf("USAGE: drawcap.exe <testnumber> [useicon]\n\n");
196*c2c66affSColin Finck 		printf("Available tests:\n"
197*c2c66affSColin Finck 			"1. DrawCaption test\n"
198*c2c66affSColin Finck 			"2. DrawCaption test + DC_GRADIENT\n"
199*c2c66affSColin Finck 			"3. DrawCaption test + DC_SMALLCAP\n"
200*c2c66affSColin Finck 			"4. DrawCaption test + DC_BUTTONS\n"
201*c2c66affSColin Finck 			"5. DrawCaption test + DC_GRADIENT | DC_SMALLCAP\n"
202*c2c66affSColin Finck 			"6. DrawCaption test + DC_GRADIENT | DC_BUTTONS\n"
203*c2c66affSColin Finck 			"7. DrawCaption test + DC_BUTTONS | DC_SMALLCAP\n"
204*c2c66affSColin Finck 			"8. DrawCaption test + DC_BUTTONS | DC_SMALLCAP | DC_GRADIENT\n\n");
205*c2c66affSColin Finck 		return 0;
206*c2c66affSColin Finck 	}
207*c2c66affSColin Finck 
208*c2c66affSColin Finck 	testnum = _wtoi(argv[1]);
209*c2c66affSColin Finck 	if(testnum < 1 || testnum > 8)
210*c2c66affSColin Finck 	{
211*c2c66affSColin Finck 		printf("Unknown test %d\n", testnum);
212*c2c66affSColin Finck 		return 1;
213*c2c66affSColin Finck 	}
214*c2c66affSColin Finck 
215*c2c66affSColin Finck 	hInst = GetModuleHandle(NULL);
216*c2c66affSColin Finck 
217*c2c66affSColin Finck 	//hLib = LoadLibrary(L"user32");
218*c2c66affSColin Finck 	//if(!hLib)
219*c2c66affSColin Finck 	//{
220*c2c66affSColin Finck 	//	printf("Shit! Can't load user32.dll\n");
221*c2c66affSColin Finck 	//	return 1;
222*c2c66affSColin Finck 	//}
223*c2c66affSColin Finck 
224*c2c66affSColin Finck 	//DrawCaptionTemp = GetProcAddress(hLib, "DrawCaptionTempW");
225*c2c66affSColin Finck 	//if(!DrawCaptionTemp)
226*c2c66affSColin Finck 	//{
227*c2c66affSColin Finck 	//	printf("Shit! Can't get DrawCaptionTemp address\n");
228*c2c66affSColin Finck 	//	return 1;
229*c2c66affSColin Finck 	//}
230*c2c66affSColin Finck 
231*c2c66affSColin Finck 	hBr = CreateSolidBrush(RGB(255, 255, 255));
232*c2c66affSColin Finck 	if(!hBr)
233*c2c66affSColin Finck 	{
234*c2c66affSColin Finck 		printf("Shit! Can't create brush.");
235*c2c66affSColin Finck 		return 1;
236*c2c66affSColin Finck 	}
237*c2c66affSColin Finck 
238*c2c66affSColin Finck 	memset(&wcx, 0, sizeof(wcx));
239*c2c66affSColin Finck 	wcx.cbSize = sizeof(wcx);
240*c2c66affSColin Finck 	wcx.style = CS_HREDRAW | CS_VREDRAW;
241*c2c66affSColin Finck 	wcx.lpfnWndProc = (WNDPROC) CaptWndProc;
242*c2c66affSColin Finck 	wcx.hInstance = hInst;
243*c2c66affSColin Finck 	wcx.hbrBackground = hBr;
244*c2c66affSColin Finck 	wcx.lpszClassName = CaptWndClass;
245*c2c66affSColin Finck 	if(argc > 2) wcx.hIconSm = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON1SM));
246*c2c66affSColin Finck 
247*c2c66affSColin Finck 	if(!(result = RegisterClassEx(&wcx)))
248*c2c66affSColin Finck 	{
249*c2c66affSColin Finck 		printf("Shit! RegisterClassEx failed: %d\n",
250*c2c66affSColin Finck 			(int)GetLastError());
251*c2c66affSColin Finck 		DeleteObject(hBr);
252*c2c66affSColin Finck 		return 1;
253*c2c66affSColin Finck 	}
254*c2c66affSColin Finck 
255*c2c66affSColin Finck 	hWnd = CreateWindowEx(0,
256*c2c66affSColin Finck 				CaptWndClass,
257*c2c66affSColin Finck 				L"DrawCaption test",
258*c2c66affSColin Finck 				WS_OVERLAPPED|WS_THICKFRAME|WS_SYSMENU,
259*c2c66affSColin Finck 				CW_USEDEFAULT,
260*c2c66affSColin Finck 				CW_USEDEFAULT,
261*c2c66affSColin Finck 				600,
262*c2c66affSColin Finck 				470,
263*c2c66affSColin Finck 				NULL,
264*c2c66affSColin Finck 				0,
265*c2c66affSColin Finck 				hInst,
266*c2c66affSColin Finck 				NULL);
267*c2c66affSColin Finck 
268*c2c66affSColin Finck 	if(!hWnd)
269*c2c66affSColin Finck 	{
270*c2c66affSColin Finck 		printf("Shit! Can't create wnd!\n");
271*c2c66affSColin Finck 		UnregisterClass(CaptWndClass, hInst);
272*c2c66affSColin Finck 		DeleteObject(hBr);
273*c2c66affSColin Finck 		return 1;
274*c2c66affSColin Finck 	}
275*c2c66affSColin Finck 
276*c2c66affSColin Finck 
277*c2c66affSColin Finck 	ShowWindow(hWnd, SW_SHOW);
278*c2c66affSColin Finck 	UpdateWindow(hWnd);
279*c2c66affSColin Finck 
280*c2c66affSColin Finck 	while(GetMessage(&msg, NULL, 0, 0 ))
281*c2c66affSColin Finck 	{
282*c2c66affSColin Finck 		TranslateMessage(&msg);
283*c2c66affSColin Finck 		DispatchMessage(&msg);
284*c2c66affSColin Finck 	}
285*c2c66affSColin Finck 
286*c2c66affSColin Finck 	DeleteObject(hBr);
287*c2c66affSColin Finck 	UnregisterClass(CaptWndClass, hInst);
288*c2c66affSColin Finck 	return 0;
289*c2c66affSColin Finck }
290