ReactOS  0.4.15-dev-3165-gdf6fff7
sysicon.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  /* This testapp demonstrates WS_SYSMENU + WS_EX_DLGMODALFRAME
20  * behavior and shows that DrawCaption does care
21  * about WS_EX_DLGMODALFRAME and WS_EX_TOOLWINDOW
22  */
23 
24 #include <windows.h>
25 #include <stdio.h>
26 
27 WCHAR WndClass[] = L"sysicon_class";
29 
31  UINT msg,
32  WPARAM wParam,
33  LPARAM lParam)
34 {
35  switch (msg)
36  {
37  case WM_PAINT:
38  {
39  HDC hDc;
40  PAINTSTRUCT Ps;
41  RECT Rect;
43 
44  Rect.left = 10;
45  Rect.top = 10;
46  Rect.right -= 10;
47  Rect.bottom = 25;
48 
49  hDc = BeginPaint(hWnd, &Ps);
50  SetBkMode(hDc, TRANSPARENT);
51 
52  DrawCaption(hWnd, hDc, &Rect, DC_GRADIENT | DC_ACTIVE | DC_TEXT | DC_ICON);
53 
54  EndPaint(hWnd, &Ps);
55 
56  return 0;
57  }
58 
59  case WM_DESTROY:
60  PostQuitMessage(0);
61  return 0;
62  }
63 
64  return DefWindowProcW(hWnd, msg, wParam, lParam);
65 }
66 
68  HINSTANCE hPrevInstance,
69  LPWSTR lpCmdLine,
70  int nCmdShow)
71 {
72  HWND hWnd1a, hWnd1b, hWnd2a, hWnd2b, hWnd3a, hWnd3b;
73  MSG msg;
74  WNDCLASSEXW wcx;
75  UINT result;
76 
77  memset(&wcx, 0, sizeof(wcx));
78  wcx.cbSize = sizeof(wcx);
80  wcx.hInstance = hInst;
81  wcx.hbrBackground = (HBRUSH)COLOR_WINDOW;
82  wcx.lpszClassName = WndClass;
83 
84  if (!(result = RegisterClassExW(&wcx)))
85  return 1;
86 
87  /* Load the user icons */
90 
91  /* WS_EX_DLGMODALFRAME */
93  WndClass,
94  L"WS_SYSMENU | WS_EX_DLGMODALFRAME without user icon",
97  400, 100,
98  NULL, 0,
99  hInst, NULL);
100  if (!hWnd1a)
101  return 1;
102 
103  ShowWindow(hWnd1a, SW_SHOW);
104  UpdateWindow(hWnd1a);
105 
106  /* WS_EX_DLGMODALFRAME */
108  WndClass,
109  L"WS_SYSMENU | WS_EX_DLGMODALFRAME with user icon",
112  400, 100,
113  NULL, 0,
114  hInst, NULL);
115 
116  if (!hWnd1b)
117  return 1;
118 
119  ShowWindow(hWnd1b, SW_SHOW);
120  UpdateWindow(hWnd1b);
121  SendMessageW(hWnd1b, WM_SETICON, ICON_SMALL, (LPARAM)hIconSm);
122  SendMessageW(hWnd1b, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
123 
125  WndClass,
126  L"WS_SYSMENU | WS_EX_TOOLWINDOW without user icon",
129  400, 100,
130  NULL, 0,
131  hInst, NULL);
132  if (!hWnd2a)
133  return 1;
134 
135  ShowWindow(hWnd2a, SW_SHOW);
136  UpdateWindow(hWnd2a);
137 
139  WndClass,
140  L"WS_SYSMENU | WS_EX_TOOLWINDOW with user icon",
143  400, 100,
144  NULL, 0,
145  hInst, NULL);
146  if (!hWnd2b)
147  return 1;
148 
149  ShowWindow(hWnd2b, SW_SHOW);
150  UpdateWindow(hWnd2b);
151  SendMessageW(hWnd2b, WM_SETICON, ICON_SMALL, (LPARAM)hIconSm);
152  SendMessageW(hWnd2b, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
153 
154  hWnd3a = CreateWindowExW(0,
155  WndClass,
156  L"WS_SYSMENU without user icon",
159  400, 100,
160  NULL, 0,
161  hInst, NULL);
162  if (!hWnd3a)
163  return 1;
164 
165  ShowWindow(hWnd3a, SW_SHOW);
166  UpdateWindow(hWnd3a);
167 
168  hWnd3b = CreateWindowExW(0,
169  WndClass,
170  L"WS_SYSMENU with user icon",
173  400, 100,
174  NULL, 0,
175  hInst, NULL);
176  if (!hWnd3b)
177  return 1;
178 
179  ShowWindow(hWnd3b, SW_SHOW);
180  UpdateWindow(hWnd3b);
181  SendMessageW(hWnd3b, WM_SETICON, ICON_SMALL, (LPARAM)hIconSm);
182  SendMessageW(hWnd3b, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
183 
184  while(GetMessageW(&msg, NULL, 0, 0 ))
185  {
188  }
189 
190  if (hIcon) DestroyIcon(hIcon);
192 
194  return 0;
195 }
BOOL WINAPI TranslateMessage(_In_ const MSG *)
static HICON
Definition: imagelist.c:84
#define LR_SHARED
Definition: winuser.h:1090
#define IMAGE_ICON
Definition: winuser.h:212
GLuint64EXT * result
Definition: glext.h:11304
BOOL WINAPI UnregisterClassW(_In_ LPCWSTR, HINSTANCE)
HICON hIconSm
Definition: sysicon.c:28
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
BOOL WINAPI DrawCaption(_In_ HWND, _In_ HDC, _In_ LPCRECT, _In_ UINT)
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:35
BOOL WINAPI UpdateWindow(_In_ HWND)
HWND hWnd
Definition: settings.c:17
#define SM_CYSMICON
Definition: winuser.h:1003
UINT_PTR WPARAM
Definition: windef.h:207
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
HICON hIcon
Definition: sysicon.c:28
#define WS_EX_TOOLWINDOW
Definition: winuser.h:404
#define COLOR_WINDOW
Definition: winuser.h:908
WPARAM wParam
Definition: combotst.c:138
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
int APIENTRY wWinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
Definition: sysicon.c:67
#define DC_ICON
Definition: winuser.h:429
#define ICON_SMALL
Definition: tnclass.cpp:48
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: sysicon.c:30
ATOM WINAPI RegisterClassExW(_In_ CONST WNDCLASSEXW *)
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1034
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:2172
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
WCHAR WndClass[]
Definition: sysicon.c:27
HANDLE WINAPI CopyImage(_In_ HANDLE, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:1956
#define TRANSPARENT
Definition: wingdi.h:949
#define CW_USEDEFAULT
Definition: winuser.h:225
#define WS_EX_DLGMODALFRAME
Definition: pedump.c:645
LONG_PTR LPARAM
Definition: windef.h:208
#define SW_SHOW
Definition: winuser.h:769
LPCWSTR lpszClassName
Definition: winuser.h:3202
#define WM_DESTROY
Definition: winuser.h:1592
#define DC_ACTIVE
Definition: winuser.h:427
#define WS_CAPTION
Definition: pedump.c:624
#define LR_DEFAULTSIZE
Definition: winuser.h:1084
__wchar_t WCHAR
Definition: xmlstorage.h:180
HBRUSH hbrBackground
Definition: winuser.h:3200
UINT cbSize
Definition: winuser.h:3192
int WINAPI GetSystemMetrics(_In_ int)
HINSTANCE hInstance
Definition: winuser.h:3197
#define WM_PAINT
Definition: winuser.h:1603
#define SM_CXSMICON
Definition: winuser.h:1002
static const WCHAR L[]
Definition: oid.c:1250
HWND WINAPI CreateWindowExW(_In_ DWORD dwExStyle, _In_opt_ LPCWSTR lpClassName, _In_opt_ LPCWSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
WNDPROC lpfnWndProc
Definition: winuser.h:3194
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2882
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define LR_COPYFROMRESOURCE
Definition: winuser.h:1089
HINSTANCE hInst
Definition: dxdiag.c:13
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
BOOL WINAPI GetMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
#define msg(x)
Definition: auth_time.c:54
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
WCHAR * LPWSTR
Definition: xmlstorage.h:184
LONG_PTR LRESULT
Definition: windef.h:209
#define WS_SYSMENU
Definition: pedump.c:629
#define memset(x, y, z)
Definition: compat.h:39
LPARAM lParam
Definition: combotst.c:139
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define DC_TEXT
Definition: winuser.h:430
#define APIENTRY
Definition: api.h:79
struct Rect Rect
#define ICON_BIG
Definition: tnclass.cpp:51