[CPL] Properly set display icons of control panel applets (#1129)
[reactos.git] / dll / cpl / inetcpl / inetcpl.c
1 /*
2 * Internet control panel applet
3 *
4 * Copyright 2010 Detlef Riekenberg
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 *
20 */
21
22 #define NONAMELESSUNION
23 #define COBJMACROS
24 #define CONST_VTABLE
25
26 #include <stdarg.h>
27 #include <windef.h>
28 #include <winbase.h>
29 #include <wingdi.h>
30 #include <winuser.h>
31 #include <commctrl.h>
32 #include <cpl.h>
33 #include "ole2.h"
34
35 #include "wine/debug.h"
36
37 #include "inetcpl.h"
38
39
40 WINE_DEFAULT_DEBUG_CHANNEL(inetcpl);
41
42 DECLSPEC_HIDDEN HMODULE hcpl;
43
44 /*********************************************************************
45 * DllMain (inetcpl.@)
46 */
47 BOOL WINAPI DllMain(HINSTANCE hdll, DWORD reason, LPVOID reserved)
48 {
49 TRACE("(%p, %d, %p)\n", hdll, reason, reserved);
50
51 switch (reason)
52 {
53 #ifndef __REACTOS__
54 case DLL_WINE_PREATTACH:
55 return FALSE; /* prefer native version */
56 #endif
57
58 case DLL_PROCESS_ATTACH:
59 DisableThreadLibraryCalls(hdll);
60 hcpl = hdll;
61 }
62 return TRUE;
63 }
64
65 /***********************************************************************
66 * DllInstall (inetcpl.@)
67 */
68 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
69 {
70 FIXME("(%s, %s): stub\n", bInstall ? "TRUE" : "FALSE", debugstr_w(cmdline));
71 return S_OK;
72 }
73
74 /******************************************************************************
75 * propsheet_callback [internal]
76 *
77 */
78 static int CALLBACK propsheet_callback(HWND hwnd, UINT msg, LPARAM lparam)
79 {
80 // NOTE: This callback is needed to set large icon correctly.
81 HICON hIcon;
82 TRACE("(%p, 0x%08x/%d, 0x%lx)\n", hwnd, msg, msg, lparam);
83 switch (msg)
84 {
85 case PSCB_INITIALIZED:
86 {
87 hIcon = LoadIconW(hcpl, MAKEINTRESOURCEW(ICO_MAIN));
88 SendMessageW(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
89 break;
90 }
91 }
92 return 0;
93 }
94
95 /******************************************************************************
96 * display_cpl_sheets [internal]
97 *
98 * Build and display the dialog with all control panel propertysheets
99 *
100 */
101 static void display_cpl_sheets(HWND parent)
102 {
103 INITCOMMONCONTROLSEX icex;
104 PROPSHEETPAGEW psp[NUM_PROPERTY_PAGES];
105 PROPSHEETHEADERW psh;
106 DWORD id = 0;
107
108 OleInitialize(NULL);
109 /* Initialize common controls */
110 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
111 icex.dwICC = ICC_LISTVIEW_CLASSES | ICC_BAR_CLASSES;
112 InitCommonControlsEx(&icex);
113
114 ZeroMemory(&psh, sizeof(psh));
115 ZeroMemory(psp, sizeof(psp));
116
117 /* Fill out all PROPSHEETPAGE */
118 psp[id].dwSize = sizeof (PROPSHEETPAGEW);
119 psp[id].hInstance = hcpl;
120 psp[id].u.pszTemplate = MAKEINTRESOURCEW(IDD_GENERAL);
121 psp[id].pfnDlgProc = general_dlgproc;
122 id++;
123
124 psp[id].dwSize = sizeof (PROPSHEETPAGEW);
125 psp[id].hInstance = hcpl;
126 psp[id].u.pszTemplate = MAKEINTRESOURCEW(IDD_SECURITY);
127 psp[id].pfnDlgProc = security_dlgproc;
128 id++;
129
130 psp[id].dwSize = sizeof (PROPSHEETPAGEW);
131 psp[id].hInstance = hcpl;
132 psp[id].u.pszTemplate = MAKEINTRESOURCEW(IDD_CONTENT);
133 psp[id].pfnDlgProc = content_dlgproc;
134 id++;
135
136 psp[id].dwSize = sizeof (PROPSHEETPAGEW);
137 psp[id].hInstance = hcpl;
138 psp[id].u.pszTemplate = MAKEINTRESOURCEW(IDD_CONNECTIONS);
139 psp[id].pfnDlgProc = connections_dlgproc;
140 id++;
141
142 /* Fill out the PROPSHEETHEADER */
143 psh.dwSize = sizeof (PROPSHEETHEADERW);
144 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK;
145 psh.hwndParent = parent;
146 psh.hInstance = hcpl;
147 psh.u.pszIcon = MAKEINTRESOURCEW(ICO_MAIN);
148 psh.pszCaption = MAKEINTRESOURCEW(IDS_CPL_NAME);
149 psh.nPages = id;
150 psh.u3.ppsp = psp;
151 psh.pfnCallback = propsheet_callback;
152
153 /* display the dialog */
154 PropertySheetW(&psh);
155
156 OleUninitialize();
157 }
158
159 /*********************************************************************
160 * CPlApplet (inetcpl.@)
161 *
162 * Control Panel entry point
163 *
164 * PARAMS
165 * hWnd [I] Handle for the Control Panel Window
166 * command [I] CPL_* Command
167 * lParam1 [I] first extra Parameter
168 * lParam2 [I] second extra Parameter
169 *
170 * RETURNS
171 * Depends on the command
172 *
173 */
174 LONG CALLBACK CPlApplet(HWND hWnd, UINT command, LPARAM lParam1, LPARAM lParam2)
175 {
176 TRACE("(%p, %u, 0x%lx, 0x%lx)\n", hWnd, command, lParam1, lParam2);
177
178 switch (command)
179 {
180 case CPL_INIT:
181 return TRUE;
182
183 case CPL_GETCOUNT:
184 return 1;
185
186 case CPL_INQUIRE:
187 {
188 CPLINFO *appletInfo = (CPLINFO *) lParam2;
189
190 appletInfo->idIcon = ICO_MAIN;
191 appletInfo->idName = IDS_CPL_NAME;
192 appletInfo->idInfo = IDS_CPL_INFO;
193 appletInfo->lData = 0;
194 return TRUE;
195 }
196
197 case CPL_DBLCLK:
198 display_cpl_sheets(hWnd);
199 break;
200 }
201
202 return FALSE;
203 }
204
205 /*********************************************************************
206 * LaunchInternetControlPanel (inetcpl.@)
207 *
208 * Launch the Internet Control Panel dialog
209 *
210 * PARAMS
211 * parent [I] Handle for the parent window
212 *
213 * RETURNS
214 * Success: TRUE
215 *
216 * NOTES
217 * rundll32 callable function: rundll32 inetcpl.cpl,LaunchInternetControlPanel
218 *
219 */
220 BOOL WINAPI LaunchInternetControlPanel(HWND parent)
221 {
222 display_cpl_sheets(parent);
223 return TRUE;
224 }
225
226 /*********************************************************************
227 * LaunchConnectionDialog (inetcpl.@)
228 *
229 */
230 BOOL WINAPI LaunchConnectionDialog(HWND hParent)
231 {
232 FIXME("(%p): stub\n", hParent);
233 return FALSE;
234 }
235
236 /*********************************************************************
237 * LaunchInternetControlPanel (inetcpl.@)
238 *
239 */
240 BOOL WINAPI LaunchPrivacyDialog(HWND hParent)
241 {
242 FIXME("(%p): stub\n", hParent);
243 return FALSE;
244 }