cef5ca22f3c83369d975a1050ccc1170ed072179
[reactos.git] / rostests / win32 / user32 / drawcaption / capicon.c
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 "stdio.h"
21 #include "resource.h"
22
23 WCHAR WndClass[] = L"capicon_class";
24
25 HINSTANCE hInst;
26 INT testnum = 0;
27
28
29 LRESULT CALLBACK WndProc(HWND hWnd,
30 UINT msg,
31 WPARAM wParam,
32 LPARAM lParam)
33 {
34 HICON hIcon;
35
36 switch (msg)
37 {
38 case WM_GETICON:
39 if(testnum>2)
40 {
41 if(wParam == ICON_SMALL)
42 hIcon = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON2SM));
43 else if(wParam == ICON_BIG)
44 hIcon = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON2BIG));
45 else hIcon = (HICON)1;
46
47 if(!hIcon)
48 {
49 printf("LoadIcon() failed: %d\n", (INT)GetLastError());
50 break;
51 }
52
53 return (LRESULT)hIcon;
54 }
55 break;
56
57 case WM_DESTROY:
58 PostQuitMessage(0);
59 return 0;
60 }
61
62 return DefWindowProc(hWnd, msg, wParam, lParam);
63 }
64
65
66 INT main(INT argc, CHAR **argv)
67 {
68 HWND hWnd;
69 MSG msg;
70 WNDCLASSEX wcx;
71 UINT result;
72
73 if(argc<2)
74 {
75 printf("DrawCaption icon test.\n");
76 printf("USAGE: drawcap.exe <testnumber>\n\n");
77 printf("Available tests:\n"
78 "1. Class small icon\n"
79 "2. Class big icon\n"
80 "3. Class small icon + WM_GETICON\n"
81 "4. Class big icon + WM_GETICON\n"
82 "5. WM_GETICON only\n\n");
83 return 0;
84 }
85
86 testnum = atoi(argv[1]);
87 if(testnum < 1 || testnum > 5)
88 {
89 printf("Unknown test %d\n", testnum);
90 return 1;
91 }
92
93 hInst = GetModuleHandle(NULL);
94
95 memset(&wcx, 0, sizeof(wcx));
96 wcx.cbSize = sizeof(wcx);
97 wcx.style = CS_HREDRAW | CS_VREDRAW;
98 wcx.lpfnWndProc = (WNDPROC) WndProc;
99 wcx.hInstance = hInst;
100 wcx.hbrBackground = (HBRUSH)COLOR_WINDOW;
101 wcx.lpszClassName = WndClass;
102 if(testnum<5)wcx.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON1BIG));
103 if(testnum == 1 || testnum == 3)
104 wcx.hIconSm = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON1SM));
105
106 if(!(result = RegisterClassEx(&wcx)))
107 {
108 printf("Shit! RegisterClassEx failed: %d\n",
109 (int)GetLastError());
110 return 1;
111 }
112
113 hWnd = CreateWindowEx(0,
114 WndClass,
115 L"DrawCaption icon test",
116 WS_OVERLAPPED|WS_THICKFRAME|WS_SYSMENU,
117 CW_USEDEFAULT,
118 CW_USEDEFAULT,
119 250,
120 100,
121 NULL,
122 0,
123 hInst,
124 NULL);
125
126 if(!hWnd)
127 {
128 printf("Shit! Can't create wnd!\n");
129 UnregisterClass(WndClass, hInst);
130 return 1;
131 }
132
133
134 ShowWindow(hWnd, SW_SHOW);
135 UpdateWindow(hWnd);
136
137 while(GetMessage(&msg, NULL, 0, 0 ))
138 {
139 TranslateMessage(&msg);
140 DispatchMessage(&msg);
141 }
142
143 UnregisterClass(WndClass, hInst);
144 return 0;
145 }