1 /* Control Panel management
3 * Copyright 2001 Eric Pouech
4 * Copyright 2008 Owen Rudge
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.
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.
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
23 #define WIN32_NO_STATUS
28 #define NO_SHLWAPI_REG
31 #include <wine/debug.h>
36 #include "wine/unicode.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(shlctrl
);
40 void Control_UnloadApplet(CPlApplet
* applet
)
44 for (i
= 0; i
< applet
->count
; i
++)
45 applet
->proc(applet
->hWnd
, CPL_STOP
, i
, applet
->info
[i
].data
);
47 if (applet
->proc
) applet
->proc(applet
->hWnd
, CPL_EXIT
, 0L, 0L);
48 FreeLibrary(applet
->hModule
);
50 list_remove( &applet
->entry
);
52 HeapFree(GetProcessHeap(), 0, applet
->cmd
);
53 HeapFree(GetProcessHeap(), 0, applet
);
56 CPlApplet
* Control_LoadApplet(HWND hWnd
, LPCWSTR cmd
, CPanel
* panel
)
59 ACTCTXW ActCtx
= {sizeof(ACTCTX
), ACTCTX_FLAG_RESOURCE_NAME_VALID
};
62 WCHAR fileBuffer
[MAX_PATH
];
70 if (!(applet
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*applet
))))
73 len
= ExpandEnvironmentStringsW(cmd
, NULL
, 0);
76 if (!(applet
->cmd
= HeapAlloc(GetProcessHeap(), 0, (len
+1) * sizeof(WCHAR
))))
78 WARN("Cannot allocate memory for applet path\n");
81 ExpandEnvironmentStringsW(cmd
, applet
->cmd
, len
+1);
85 WARN("Cannot expand applet path\n");
92 StringCchCopy(fileBuffer
, MAX_PATH
, applet
->cmd
);
93 if (PathIsFileSpecW(fileBuffer
))
94 SearchPath(NULL
, fileBuffer
, NULL
, MAX_PATH
, fileBuffer
, NULL
);
95 ActCtx
.lpSource
= fileBuffer
;
96 ActCtx
.lpResourceName
= (LPCWSTR
)123;
97 applet
->hActCtx
= CreateActCtx(&ActCtx
);
98 bActivated
= (applet
->hActCtx
!= INVALID_HANDLE_VALUE
? ActivateActCtx(applet
->hActCtx
, &cookie
) : FALSE
);
101 if (!(applet
->hModule
= LoadLibraryW(applet
->cmd
))) {
102 WARN("Cannot load control panel applet %s\n", debugstr_w(applet
->cmd
));
105 if (!(applet
->proc
= (APPLET_PROC
)GetProcAddress(applet
->hModule
, "CPlApplet"))) {
106 WARN("Not a valid control panel applet %s\n", debugstr_w(applet
->cmd
));
109 if (!applet
->proc(hWnd
, CPL_INIT
, 0L, 0L)) {
110 WARN("Init of applet has failed\n");
113 if ((applet
->count
= applet
->proc(hWnd
, CPL_GETCOUNT
, 0L, 0L)) == 0) {
114 WARN("No subprogram in applet\n");
115 applet
->proc(applet
->hWnd
, CPL_EXIT
, 0, 0);
119 applet
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, applet
,
120 FIELD_OFFSET( CPlApplet
, info
[applet
->count
] ));
122 for (i
= 0; i
< applet
->count
; i
++) {
123 ZeroMemory(&newinfo
, sizeof(newinfo
));
124 newinfo
.dwSize
= sizeof(NEWCPLINFOA
);
125 applet
->info
[i
].helpfile
[0] = 0;
126 /* proc is supposed to return a null value upon success for
127 * CPL_INQUIRE and CPL_NEWINQUIRE
128 * However, real drivers don't seem to behave like this
129 * So, use introspection rather than return value
131 applet
->proc(hWnd
, CPL_INQUIRE
, i
, (LPARAM
)&info
);
132 applet
->info
[i
].data
= info
.lData
;
134 applet
->info
[i
].idIcon
= info
.idIcon
;
137 if (info
.idIcon
!= CPL_DYNAMIC_RES
)
138 applet
->info
[i
].icon
= LoadIconW(applet
->hModule
, MAKEINTRESOURCEW(info
.idIcon
));
139 if (info
.idName
!= CPL_DYNAMIC_RES
)
140 LoadStringW(applet
->hModule
, info
.idName
,
141 applet
->info
[i
].name
, sizeof(applet
->info
[i
].name
) / sizeof(WCHAR
));
142 if (info
.idInfo
!= CPL_DYNAMIC_RES
)
143 LoadStringW(applet
->hModule
, info
.idInfo
,
144 applet
->info
[i
].info
, sizeof(applet
->info
[i
].info
) / sizeof(WCHAR
));
146 /* some broken control panels seem to return incorrect values in CPL_INQUIRE,
147 but proper data in CPL_NEWINQUIRE. if we get an empty string or a null
148 icon, see what we can get from CPL_NEWINQUIRE */
150 if (!applet
->info
[i
].name
[0]) info
.idName
= CPL_DYNAMIC_RES
;
152 /* zero-length szInfo may not be a buggy applet, but it doesn't hurt for us
155 if (!applet
->info
[i
].info
[0]) info
.idInfo
= CPL_DYNAMIC_RES
;
157 if (applet
->info
[i
].icon
== NULL
)
158 info
.idIcon
= CPL_DYNAMIC_RES
;
160 if ((info
.idIcon
== CPL_DYNAMIC_RES
) || (info
.idName
== CPL_DYNAMIC_RES
) ||
161 (info
.idInfo
== CPL_DYNAMIC_RES
)) {
162 applet
->proc(hWnd
, CPL_NEWINQUIRE
, i
, (LPARAM
)&newinfo
);
164 applet
->info
[i
].data
= newinfo
.lData
;
165 if (info
.idIcon
== CPL_DYNAMIC_RES
) {
166 if (!newinfo
.hIcon
) WARN("couldn't get icon for applet %u\n", i
);
167 applet
->info
[i
].icon
= newinfo
.hIcon
;
169 if (newinfo
.dwSize
== sizeof(NEWCPLINFOW
)) {
170 if (info
.idName
== CPL_DYNAMIC_RES
)
171 memcpy(applet
->info
[i
].name
, newinfo
.szName
, sizeof(newinfo
.szName
));
172 if (info
.idInfo
== CPL_DYNAMIC_RES
)
173 memcpy(applet
->info
[i
].info
, newinfo
.szInfo
, sizeof(newinfo
.szInfo
));
174 memcpy(applet
->info
[i
].helpfile
, newinfo
.szHelpFile
, sizeof(newinfo
.szHelpFile
));
176 if (info
.idName
== CPL_DYNAMIC_RES
)
177 MultiByteToWideChar(CP_ACP
, 0, ((LPNEWCPLINFOA
)&newinfo
)->szName
,
178 sizeof(((LPNEWCPLINFOA
)&newinfo
)->szName
) / sizeof(CHAR
),
179 applet
->info
[i
].name
, sizeof(applet
->info
[i
].name
) / sizeof(WCHAR
));
180 if (info
.idInfo
== CPL_DYNAMIC_RES
)
181 MultiByteToWideChar(CP_ACP
, 0, ((LPNEWCPLINFOA
)&newinfo
)->szInfo
,
182 sizeof(((LPNEWCPLINFOA
)&newinfo
)->szInfo
) / sizeof(CHAR
),
183 applet
->info
[i
].info
, sizeof(applet
->info
[i
].info
) / sizeof(WCHAR
));
184 MultiByteToWideChar(CP_ACP
, 0, ((LPNEWCPLINFOA
)&newinfo
)->szHelpFile
,
185 sizeof(((LPNEWCPLINFOA
)&newinfo
)->szHelpFile
) / sizeof(CHAR
),
186 applet
->info
[i
].helpfile
,
187 sizeof(applet
->info
[i
].helpfile
) / sizeof(WCHAR
));
194 DeactivateActCtx(0, cookie
);
198 list_add_head( &panel
->applets
, &applet
->entry
);
204 FreeLibrary(applet
->hModule
);
205 HeapFree(GetProcessHeap(), 0, applet
->cmd
);
206 HeapFree(GetProcessHeap(), 0, applet
);
212 #define IDC_LISTVIEW 1000
213 #define IDC_STATUSBAR 1001
215 #define NUM_COLUMNS 2
216 #define LISTVIEW_DEFSTYLE (WS_CHILD | WS_VISIBLE | WS_TABSTOP |\
217 LVS_SORTASCENDING | LVS_AUTOARRANGE | LVS_SINGLESEL)
219 static BOOL
Control_CreateListView (CPanel
*panel
)
222 WCHAR empty_string
[] = {0};
223 WCHAR buf
[MAX_STRING_LEN
];
226 /* Create list view */
227 GetClientRect(panel
->hWndStatusBar
, &sb
);
228 GetClientRect(panel
->hWnd
, &ws
);
230 panel
->hWndListView
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_LISTVIEWW
,
231 empty_string
, LISTVIEW_DEFSTYLE
| LVS_ICON
,
232 0, 0, ws
.right
- ws
.left
, ws
.bottom
- ws
.top
-
233 (sb
.bottom
- sb
.top
), panel
->hWnd
,
234 (HMENU
) IDC_LISTVIEW
, panel
->hInst
, NULL
);
236 if (!panel
->hWndListView
)
239 /* Create image lists for list view */
240 panel
->hImageListSmall
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
),
241 GetSystemMetrics(SM_CYSMICON
), ILC_COLOR32
| ILC_MASK
, 1, 1);
242 panel
->hImageListLarge
= ImageList_Create(GetSystemMetrics(SM_CXICON
),
243 GetSystemMetrics(SM_CYICON
), ILC_COLOR32
| ILC_MASK
, 1, 1);
245 SendMessageW(panel
->hWndListView
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)panel
->hImageListSmall
);
246 SendMessageW(panel
->hWndListView
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)panel
->hImageListLarge
);
248 /* Create columns for list view */
249 lvc
.mask
= LVCF_FMT
| LVCF_TEXT
| LVCF_SUBITEM
| LVCF_WIDTH
;
251 lvc
.fmt
= LVCFMT_LEFT
;
255 lvc
.cx
= (ws
.right
- ws
.left
) / 3;
256 LoadStringW(shell32_hInstance
, IDS_CPANEL_NAME
, buf
, sizeof(buf
) / sizeof(buf
[0]));
258 if (ListView_InsertColumnW(panel
->hWndListView
, 0, &lvc
) == -1)
261 /* Description column */
263 lvc
.cx
= ((ws
.right
- ws
.left
) / 3) * 2;
264 LoadStringW(shell32_hInstance
, IDS_CPANEL_DESCRIPTION
, buf
, sizeof(buf
) /
267 if (ListView_InsertColumnW(panel
->hWndListView
, 1, &lvc
) == -1)
273 static void Control_WndProc_Create(HWND hWnd
, const CREATESTRUCTW
* cs
)
275 CPanel
* panel
= cs
->lpCreateParams
;
276 HMENU hMenu
, hSubMenu
;
280 int menucount
, index
;
283 INITCOMMONCONTROLSEX icex
;
287 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)panel
);
290 /* Initialise common control DLL */
291 icex
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
292 icex
.dwICC
= ICC_LISTVIEW_CLASSES
| ICC_BAR_CLASSES
;
293 InitCommonControlsEx(&icex
);
295 /* create the status bar */
296 if (!(panel
->hWndStatusBar
= CreateStatusWindowW(WS_CHILD
| WS_VISIBLE
| CCS_BOTTOM
| SBARS_SIZEGRIP
, NULL
, hWnd
, IDC_STATUSBAR
)))
300 SendMessageW(panel
->hWndStatusBar
, SB_SETPARTS
, 1, (LPARAM
) &sb_parts
);
302 /* create the list view */
303 if (!Control_CreateListView(panel
))
306 hMenu
= LoadMenuW(shell32_hInstance
, MAKEINTRESOURCEW(MENU_CPANEL
));
308 /* insert menu items for applets */
309 hSubMenu
= GetSubMenu(hMenu
, 0);
312 LIST_FOR_EACH_ENTRY( applet
, &panel
->applets
, CPlApplet
, entry
)
314 for (i
= 0; i
< applet
->count
; i
++) {
315 /* set up a CPlItem for this particular subprogram */
316 item
= HeapAlloc(GetProcessHeap(), 0, sizeof(CPlItem
));
321 item
->applet
= applet
;
324 mii
.cbSize
= sizeof(MENUITEMINFOW
);
325 mii
.fMask
= MIIM_ID
| MIIM_STRING
| MIIM_DATA
;
326 mii
.dwTypeData
= applet
->info
[i
].name
;
327 mii
.cch
= sizeof(applet
->info
[i
].name
) / sizeof(WCHAR
);
328 mii
.wID
= IDM_CPANEL_APPLET_BASE
+ menucount
;
329 mii
.dwItemData
= (ULONG_PTR
)item
;
331 if (InsertMenuItemW(hSubMenu
, menucount
, TRUE
, &mii
)) {
332 /* add the list view item */
333 HICON icon
= applet
->info
[i
].icon
;
334 if (!icon
) icon
= LoadImageW( 0, (LPCWSTR
)IDI_WINLOGO
, IMAGE_ICON
, 0, 0, LR_SHARED
);
335 index
= ImageList_AddIcon(panel
->hImageListLarge
, icon
);
336 ImageList_AddIcon(panel
->hImageListSmall
, icon
);
338 lvItem
.mask
= LVIF_IMAGE
| LVIF_TEXT
| LVIF_PARAM
;
339 lvItem
.iItem
= menucount
;
341 lvItem
.pszText
= applet
->info
[i
].name
;
342 lvItem
.iImage
= index
;
343 lvItem
.lParam
= (LPARAM
) item
;
345 itemidx
= ListView_InsertItemW(panel
->hWndListView
, &lvItem
);
347 /* add the description */
348 ListView_SetItemTextW(panel
->hWndListView
, itemidx
, 1, applet
->info
[i
].info
);
350 /* update menu bar, increment count */
357 panel
->total_subprogs
= menucount
;
359 /* check the "large items" icon in the View menu */
360 hSubMenu
= GetSubMenu(hMenu
, 1);
361 CheckMenuRadioItem(hSubMenu
, FCIDM_SHVIEW_BIGICON
, FCIDM_SHVIEW_REPORTVIEW
,
362 FCIDM_SHVIEW_BIGICON
, MF_BYCOMMAND
);
364 SetMenu(hWnd
, hMenu
);
367 static void Control_FreeCPlItems(HWND hWnd
, CPanel
*panel
)
369 HMENU hMenu
, hSubMenu
;
373 /* get the File menu */
374 hMenu
= GetMenu(hWnd
);
379 hSubMenu
= GetSubMenu(hMenu
, 0);
384 /* loop and free the item data */
385 for (i
= IDM_CPANEL_APPLET_BASE
; i
<= IDM_CPANEL_APPLET_BASE
+ panel
->total_subprogs
; i
++)
387 mii
.cbSize
= sizeof(MENUITEMINFOW
);
388 mii
.fMask
= MIIM_DATA
;
390 if (!GetMenuItemInfoW(hSubMenu
, i
, FALSE
, &mii
))
393 HeapFree(GetProcessHeap(), 0, (LPVOID
) mii
.dwItemData
);
397 static void Control_UpdateListViewStyle(CPanel
*panel
, UINT style
, UINT id
)
399 HMENU hMenu
, hSubMenu
;
401 SetWindowLongW(panel
->hWndListView
, GWL_STYLE
, LISTVIEW_DEFSTYLE
| style
);
403 /* update the menu */
404 hMenu
= GetMenu(panel
->hWnd
);
405 hSubMenu
= GetSubMenu(hMenu
, 1);
407 CheckMenuRadioItem(hSubMenu
, FCIDM_SHVIEW_BIGICON
, FCIDM_SHVIEW_REPORTVIEW
,
411 static CPlItem
* Control_GetCPlItem_From_MenuID(HWND hWnd
, UINT id
)
413 HMENU hMenu
, hSubMenu
;
416 /* retrieve the CPlItem structure from the menu item data */
417 hMenu
= GetMenu(hWnd
);
422 hSubMenu
= GetSubMenu(hMenu
, 0);
427 mii
.cbSize
= sizeof(MENUITEMINFOW
);
428 mii
.fMask
= MIIM_DATA
;
430 if (!GetMenuItemInfoW(hSubMenu
, id
, FALSE
, &mii
))
433 return (CPlItem
*) mii
.dwItemData
;
436 static CPlItem
* Control_GetCPlItem_From_ListView(CPanel
*panel
)
441 selitem
= SendMessageW(panel
->hWndListView
, LVM_GETNEXTITEM
, -1, LVNI_FOCUSED
446 lvItem
.iItem
= selitem
;
447 lvItem
.mask
= LVIF_PARAM
;
449 if (SendMessageW(panel
->hWndListView
, LVM_GETITEMW
, 0, (LPARAM
) &lvItem
))
450 return (CPlItem
*) lvItem
.lParam
;
456 static void Control_StartApplet(HWND hWnd
, CPlItem
*item
)
458 WCHAR verbOpen
[] = {'c','p','l','o','p','e','n',0};
459 WCHAR format
[] = {'@','%','d',0};
460 WCHAR param
[MAX_PATH
];
462 /* execute the applet if item is valid */
465 wsprintfW(param
, format
, item
->id
);
466 ShellExecuteW(hWnd
, verbOpen
, item
->applet
->cmd
, param
, NULL
, SW_SHOW
);
470 static LRESULT WINAPI
Control_WndProc(HWND hWnd
, UINT wMsg
,
471 WPARAM lParam1
, LPARAM lParam2
)
473 CPanel
* panel
= (CPanel
*)GetWindowLongPtrW(hWnd
, 0);
475 if (panel
|| wMsg
== WM_CREATE
) {
478 Control_WndProc_Create(hWnd
, (CREATESTRUCTW
*)lParam2
);
482 CPlApplet
*applet
, *next
;
483 LIST_FOR_EACH_ENTRY_SAFE( applet
, next
, &panel
->applets
, CPlApplet
, entry
)
484 Control_UnloadApplet(applet
);
486 Control_FreeCPlItems(hWnd
, panel
);
490 switch (LOWORD(lParam1
))
492 case IDM_CPANEL_EXIT
:
493 SendMessageW(hWnd
, WM_CLOSE
, 0, 0);
496 case IDM_CPANEL_ABOUT
:
498 WCHAR appName
[MAX_STRING_LEN
];
499 HICON icon
= LoadImageW(shell32_hInstance
, MAKEINTRESOURCEW(IDI_SHELL_CONTROL_PANEL
),
500 IMAGE_ICON
, 48, 48, LR_SHARED
);
502 LoadStringW(shell32_hInstance
, IDS_CPANEL_TITLE
, appName
,
503 sizeof(appName
) / sizeof(appName
[0]));
504 ShellAboutW(hWnd
, appName
, NULL
, icon
);
509 case FCIDM_SHVIEW_BIGICON
:
510 Control_UpdateListViewStyle(panel
, LVS_ICON
, FCIDM_SHVIEW_BIGICON
);
513 case FCIDM_SHVIEW_SMALLICON
:
514 Control_UpdateListViewStyle(panel
, LVS_SMALLICON
, FCIDM_SHVIEW_SMALLICON
);
517 case FCIDM_SHVIEW_LISTVIEW
:
518 Control_UpdateListViewStyle(panel
, LVS_LIST
, FCIDM_SHVIEW_LISTVIEW
);
521 case FCIDM_SHVIEW_REPORTVIEW
:
522 Control_UpdateListViewStyle(panel
, LVS_REPORT
, FCIDM_SHVIEW_REPORTVIEW
);
526 /* check if this is an applet */
527 if ((LOWORD(lParam1
) >= IDM_CPANEL_APPLET_BASE
) &&
528 (LOWORD(lParam1
) <= IDM_CPANEL_APPLET_BASE
+ panel
->total_subprogs
))
530 Control_StartApplet(hWnd
, Control_GetCPlItem_From_MenuID(hWnd
, LOWORD(lParam1
)));
541 LPNMHDR nmh
= (LPNMHDR
) lParam2
;
551 Control_StartApplet(hWnd
, Control_GetCPlItem_From_ListView(panel
));
554 case LVN_ITEMCHANGED
:
556 CPlItem
*item
= Control_GetCPlItem_From_ListView(panel
);
558 /* update the status bar if item is valid */
560 SetWindowTextW(panel
->hWndStatusBar
, item
->applet
->info
[item
->id
].info
);
562 SetWindowTextW(panel
->hWndStatusBar
, NULL
);
575 /* check if this is an applet */
576 if ((LOWORD(lParam1
) >= IDM_CPANEL_APPLET_BASE
) &&
577 (LOWORD(lParam1
) <= IDM_CPANEL_APPLET_BASE
+ panel
->total_subprogs
))
579 CPlItem
*item
= Control_GetCPlItem_From_MenuID(hWnd
, LOWORD(lParam1
));
581 /* update the status bar if item is valid */
583 SetWindowTextW(panel
->hWndStatusBar
, item
->applet
->info
[item
->id
].info
);
585 else if ((HIWORD(lParam1
) == 0xFFFF) && (lParam2
== 0))
587 /* reset status bar description to that of the selected icon */
588 CPlItem
*item
= Control_GetCPlItem_From_ListView(panel
);
591 SetWindowTextW(panel
->hWndStatusBar
, item
->applet
->info
[item
->id
].info
);
593 SetWindowTextW(panel
->hWndStatusBar
, NULL
);
598 SetWindowTextW(panel
->hWndStatusBar
, NULL
);
607 hdwp
= BeginDeferWindowPos(2);
612 GetClientRect(panel
->hWndStatusBar
, &sb
);
614 hdwp
= DeferWindowPos(hdwp
, panel
->hWndListView
, NULL
, 0, 0,
615 LOWORD(lParam2
), HIWORD(lParam2
) - (sb
.bottom
- sb
.top
),
616 SWP_NOZORDER
| SWP_NOMOVE
);
621 hdwp
= DeferWindowPos(hdwp
, panel
->hWndStatusBar
, NULL
, 0, 0,
622 LOWORD(lParam2
), LOWORD(lParam1
), SWP_NOZORDER
| SWP_NOMOVE
);
625 EndDeferWindowPos(hdwp
);
632 return DefWindowProcW(hWnd
, wMsg
, lParam1
, lParam2
);
635 static void Control_DoInterface(CPanel
* panel
, HWND hWnd
, HINSTANCE hInst
)
639 WCHAR appName
[MAX_STRING_LEN
];
640 const WCHAR className
[] = {'S','h','e','l','l','_','C','o','n','t','r','o',
641 'l','_','W','n','d','C','l','a','s','s',0};
643 LoadStringW(shell32_hInstance
, IDS_CPANEL_TITLE
, appName
, sizeof(appName
) / sizeof(appName
[0]));
645 wc
.cbSize
= sizeof(wc
);
646 wc
.style
= CS_HREDRAW
|CS_VREDRAW
;
647 wc
.lpfnWndProc
= Control_WndProc
;
649 wc
.cbWndExtra
= sizeof(CPlApplet
*);
650 wc
.hInstance
= panel
->hInst
= hInst
;
651 wc
.hIcon
= LoadIconW( shell32_hInstance
, MAKEINTRESOURCEW(IDI_SHELL_CONTROL_PANEL
) );
652 wc
.hCursor
= LoadCursorW( 0, (LPWSTR
)IDC_ARROW
);
653 wc
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
654 wc
.lpszMenuName
= NULL
;
655 wc
.lpszClassName
= className
;
656 wc
.hIconSm
= LoadImageW( shell32_hInstance
, MAKEINTRESOURCEW(IDI_SHELL_CONTROL_PANEL
), IMAGE_ICON
,
657 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
659 if (!RegisterClassExW(&wc
)) return;
661 CreateWindowExW(0, wc
.lpszClassName
, appName
,
662 WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
663 CW_USEDEFAULT
, CW_USEDEFAULT
,
664 CW_USEDEFAULT
, CW_USEDEFAULT
,
665 hWnd
, NULL
, hInst
, panel
);
666 if (!panel
->hWnd
) return;
668 while (GetMessageW(&msg
, panel
->hWnd
, 0, 0)) {
669 TranslateMessage(&msg
);
670 DispatchMessageW(&msg
);
674 static void Control_RegisterRegistryApplets(HWND hWnd
, CPanel
*panel
, HKEY hkey_root
, LPCWSTR szRepPath
)
676 WCHAR name
[MAX_PATH
];
677 WCHAR value
[MAX_PATH
];
680 if (RegOpenKeyW(hkey_root
, szRepPath
, &hkey
) == ERROR_SUCCESS
)
686 DWORD nameLen
= MAX_PATH
;
687 DWORD valueLen
= MAX_PATH
;
689 if (RegEnumValueW(hkey
, idx
, name
, &nameLen
, NULL
, NULL
, (LPBYTE
)value
, &valueLen
) != ERROR_SUCCESS
)
692 Control_LoadApplet(hWnd
, value
, panel
);
698 static void Control_DoWindow(CPanel
* panel
, HWND hWnd
, HINSTANCE hInst
)
702 WCHAR buffer
[MAX_PATH
];
703 static const WCHAR wszAllCpl
[] = {'*','.','c','p','l',0};
704 static const WCHAR wszRegPath
[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t',
705 '\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
706 '\\','C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','C','p','l','s',0};
709 /* first add .cpl files in the system directory */
710 GetSystemDirectoryW( buffer
, MAX_PATH
);
711 p
= buffer
+ strlenW(buffer
);
713 lstrcpyW(p
, wszAllCpl
);
715 if ((h
= FindFirstFileW(buffer
, &fd
)) != INVALID_HANDLE_VALUE
) {
717 lstrcpyW(p
, fd
.cFileName
);
718 Control_LoadApplet(hWnd
, buffer
, panel
);
719 } while (FindNextFileW(h
, &fd
));
723 /* now check for cpls in the registry */
724 Control_RegisterRegistryApplets(hWnd
, panel
, HKEY_LOCAL_MACHINE
, wszRegPath
);
725 Control_RegisterRegistryApplets(hWnd
, panel
, HKEY_CURRENT_USER
, wszRegPath
);
727 Control_DoInterface(panel
, hWnd
, hInst
);
731 static void Control_DoWindow(CPanel
* panel
, HWND hWnd
, HINSTANCE hInst
)
736 L
"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}",
742 static void Control_DoLaunch(CPanel
* panel
, HWND hWnd
, LPCWSTR wszCmd
)
758 LPWSTR extraPmtsBuf
= NULL
;
759 LPWSTR extraPmts
= NULL
;
763 buffer
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(wszCmd
) + 1) * sizeof(*wszCmd
));
766 end
= lstrcpyW(buffer
, wszCmd
);
770 if (ch
== '"') quoted
= !quoted
;
771 if (!quoted
&& (ch
== ' ' || ch
== ',' || ch
== '\0')) {
776 } else if (*beg
== '\0') {
782 if (ch
== '\0') break;
784 if (ch
== ' ') while (end
[1] == ' ') end
++;
788 while ((ptr
= StrChrW(buffer
, '"')))
789 memmove(ptr
, ptr
+1, lstrlenW(ptr
)*sizeof(WCHAR
));
791 /* now check for any quotes in extraPmtsBuf and remove */
792 if (extraPmtsBuf
!= NULL
)
794 beg
= end
= extraPmtsBuf
;
799 if (ch
== '"') quoted
= !quoted
;
800 if (!quoted
&& (ch
== ' ' || ch
== ',' || ch
== '\0')) {
807 if (ch
== '\0') break;
809 if (ch
== ' ') while (end
[1] == ' ') end
++;
814 while ((ptr
= StrChrW(extraPmts
, '"')))
815 memmove(ptr
, ptr
+1, lstrlenW(ptr
)*sizeof(WCHAR
));
817 if (extraPmts
== NULL
)
818 extraPmts
= extraPmtsBuf
;
821 /* Now check if there had been a numerical value in the extra params */
822 if ((extraPmts
) && (*extraPmts
== '@') && (sp
== -1)) {
823 sp
= atoiW(extraPmts
+ 1);
826 TRACE("cmd %s, extra %s, sp %d\n", debugstr_w(buffer
), debugstr_w(extraPmts
), sp
);
828 applet
= Control_LoadApplet(hWnd
, buffer
, panel
);
835 /* we've been given a textual parameter (or none at all) */
837 while ((++sp
) != applet
->count
) {
838 TRACE("sp %d, name %s\n", sp
, debugstr_w(applet
->info
[sp
].name
));
840 if (StrCmpIW(extraPmts
, applet
->info
[sp
].name
) == 0)
845 if (sp
>= applet
->count
) {
846 WARN("Out of bounds (%u >= %u), setting to 0\n", sp
, applet
->count
);
851 bActivated
= (applet
->hActCtx
!= INVALID_HANDLE_VALUE
? ActivateActCtx(applet
->hActCtx
, &cookie
) : FALSE
);
854 if (!applet
->proc(applet
->hWnd
, CPL_STARTWPARMSW
, sp
, (LPARAM
)extraPmts
))
855 applet
->proc(applet
->hWnd
, CPL_DBLCLK
, sp
, applet
->info
[sp
].data
);
857 Control_UnloadApplet(applet
);
861 DeactivateActCtx(0, cookie
);
866 HeapFree(GetProcessHeap(), 0, buffer
);
869 /*************************************************************************
870 * Control_RunDLLW [SHELL32.@]
873 void WINAPI
Control_RunDLLW(HWND hWnd
, HINSTANCE hInst
, LPCWSTR cmd
, DWORD nCmdShow
)
877 TRACE("(%p, %p, %s, 0x%08x)\n",
878 hWnd
, hInst
, debugstr_w(cmd
), nCmdShow
);
881 memset(&panel
, 0, sizeof(panel
));
882 list_init( &panel
.applets
);
886 Control_DoWindow(&panel
, hWnd
, hInst
);
888 Control_DoLaunch(&panel
, hWnd
, cmd
);
892 /*************************************************************************
893 * Control_RunDLLA [SHELL32.@]
896 void WINAPI
Control_RunDLLA(HWND hWnd
, HINSTANCE hInst
, LPCSTR cmd
, DWORD nCmdShow
)
898 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, cmd
, -1, NULL
, 0 );
899 LPWSTR wszCmd
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
900 if (wszCmd
&& MultiByteToWideChar(CP_ACP
, 0, cmd
, -1, wszCmd
, len
))
902 Control_RunDLLW(hWnd
, hInst
, wszCmd
, nCmdShow
);
904 HeapFree(GetProcessHeap(), 0, wszCmd
);
907 /*************************************************************************
908 * Control_FillCache_RunDLLW [SHELL32.@]
911 HRESULT WINAPI
Control_FillCache_RunDLLW(HWND hWnd
, HANDLE hModule
, DWORD w
, DWORD x
)
913 FIXME("%p %p 0x%08x 0x%08x stub\n", hWnd
, hModule
, w
, x
);
917 /*************************************************************************
918 * Control_FillCache_RunDLLA [SHELL32.@]
921 HRESULT WINAPI
Control_FillCache_RunDLLA(HWND hWnd
, HANDLE hModule
, DWORD w
, DWORD x
)
923 return Control_FillCache_RunDLLW(hWnd
, hModule
, w
, x
);
928 /*************************************************************************
929 * RunDll_CallEntry16 [SHELL32.122]
930 * the name is OK (when written with Dll, and not DLL as in Wine!)
932 void WINAPI
RunDll_CallEntry16( DWORD proc
, HWND hwnd
, HINSTANCE inst
,
933 LPCSTR cmdline
, INT cmdshow
)
935 FIXME( "proc %lx hwnd %p inst %p cmdline %s cmdshow %d\n",
936 proc
, hwnd
, inst
, debugstr_a(cmdline
), cmdshow
);
940 /*************************************************************************
941 * CallCPLEntry16 [SHELL32.166]
943 * called by desk.cpl on "Advanced" with:
944 * hMod("DeskCp16.Dll"), pFunc("CplApplet"), 0, 1, 0xc, 0
947 DWORD WINAPI
CallCPLEntry16(HMODULE hMod
, FARPROC pFunc
, DWORD dw3
, DWORD dw4
, DWORD dw5
, DWORD dw6
)
949 FIXME("(%p, %p, %08x, %08x, %08x, %08x): stub.\n", hMod
, pFunc
, dw3
, dw4
, dw5
, dw6
);