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
32 #include "wine/debug.h"
34 #include "wine/unicode.h"
37 #define NO_SHLWAPI_REG
42 #include "shell32_main.h"
44 #define MAX_STRING_LEN 1024
46 WINE_DEFAULT_DEBUG_CHANNEL(shlctrl
);
48 CPlApplet
* Control_UnloadApplet(CPlApplet
* applet
)
53 for (i
= 0; i
< applet
->count
; i
++) {
54 if (!applet
->info
[i
].dwSize
) continue;
55 applet
->proc(applet
->hWnd
, CPL_STOP
, i
, applet
->info
[i
].lData
);
57 if (applet
->proc
) applet
->proc(applet
->hWnd
, CPL_EXIT
, 0L, 0L);
58 FreeLibrary(applet
->hModule
);
60 HeapFree(GetProcessHeap(), 0, applet
->cmd
);
61 HeapFree(GetProcessHeap(), 0, applet
);
65 CPlApplet
* Control_LoadApplet(HWND hWnd
, LPCWSTR cmd
, CPanel
* panel
)
72 if (!(applet
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*applet
))))
77 if (!(applet
->hModule
= LoadLibraryW(cmd
))) {
78 WARN("Cannot load control panel applet %s\n", debugstr_w(cmd
));
81 if (!(applet
->proc
= (APPLET_PROC
)GetProcAddress(applet
->hModule
, "CPlApplet"))) {
82 WARN("Not a valid control panel applet %s\n", debugstr_w(cmd
));
85 if (!applet
->proc(hWnd
, CPL_INIT
, 0L, 0L)) {
86 WARN("Init of applet has failed\n");
89 if ((applet
->count
= applet
->proc(hWnd
, CPL_GETCOUNT
, 0L, 0L)) == 0) {
90 WARN("No subprogram in applet\n");
94 applet
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, applet
,
95 sizeof(*applet
) + (applet
->count
- 1) * sizeof(NEWCPLINFOW
));
97 if (!(applet
->cmd
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmd
)+1) * sizeof(WCHAR
)))) {
98 WARN("Cannot allocate memory for applet path\n");
102 lstrcpyW(applet
->cmd
, cmd
);
104 for (i
= 0; i
< applet
->count
; i
++) {
105 ZeroMemory(&newinfo
, sizeof(newinfo
));
106 newinfo
.dwSize
= sizeof(NEWCPLINFOA
);
107 applet
->info
[i
].dwSize
= sizeof(NEWCPLINFOW
);
108 applet
->info
[i
].dwFlags
= 0;
109 applet
->info
[i
].dwHelpContext
= 0;
110 applet
->info
[i
].szHelpFile
[0] = '\0';
111 /* proc is supposed to return a null value upon success for
112 * CPL_INQUIRE and CPL_NEWINQUIRE
113 * However, real drivers don't seem to behave like this
114 * So, use introspection rather than return value
116 applet
->proc(hWnd
, CPL_INQUIRE
, i
, (LPARAM
)&info
);
117 applet
->info
[i
].lData
= info
.lData
;
118 if (info
.idIcon
!= CPL_DYNAMIC_RES
)
119 applet
->info
[i
].hIcon
= LoadIconW(applet
->hModule
,
120 MAKEINTRESOURCEW(info
.idIcon
));
121 if (info
.idName
!= CPL_DYNAMIC_RES
)
122 LoadStringW(applet
->hModule
, info
.idName
,
123 applet
->info
[i
].szName
, sizeof(applet
->info
[i
].szName
) / sizeof(WCHAR
));
124 if (info
.idInfo
!= CPL_DYNAMIC_RES
)
125 LoadStringW(applet
->hModule
, info
.idInfo
,
126 applet
->info
[i
].szInfo
, sizeof(applet
->info
[i
].szInfo
) / sizeof(WCHAR
));
128 /* some broken control panels seem to return incorrect values in CPL_INQUIRE,
129 but proper data in CPL_NEWINQUIRE. if we get an empty string or a null
130 icon, see what we can get from CPL_NEWINQUIRE */
132 if ((applet
->info
[i
].szName
== 0) || (lstrlenW(applet
->info
[i
].szName
) == 0))
133 info
.idName
= CPL_DYNAMIC_RES
;
135 /* zero-length szInfo may not be a buggy applet, but it doesn't hurt for us
138 if ((applet
->info
[i
].szInfo
== 0) || (lstrlenW(applet
->info
[i
].szInfo
) == 0))
139 info
.idInfo
= CPL_DYNAMIC_RES
;
141 if (applet
->info
[i
].hIcon
== NULL
)
142 info
.idIcon
= CPL_DYNAMIC_RES
;
144 if ((info
.idIcon
== CPL_DYNAMIC_RES
) || (info
.idName
== CPL_DYNAMIC_RES
) ||
145 (info
.idInfo
== CPL_DYNAMIC_RES
)) {
146 applet
->proc(hWnd
, CPL_NEWINQUIRE
, i
, (LPARAM
)&newinfo
);
148 applet
->info
[i
].dwFlags
= newinfo
.dwFlags
;
149 applet
->info
[i
].dwHelpContext
= newinfo
.dwHelpContext
;
150 applet
->info
[i
].lData
= newinfo
.lData
;
151 if (info
.idIcon
== CPL_DYNAMIC_RES
) {
152 if (!newinfo
.hIcon
) WARN("couldn't get icon for applet %u\n", i
);
153 applet
->info
[i
].hIcon
= newinfo
.hIcon
;
155 if (newinfo
.dwSize
== sizeof(NEWCPLINFOW
)) {
156 if (info
.idName
== CPL_DYNAMIC_RES
)
157 memcpy(applet
->info
[i
].szName
, newinfo
.szName
, sizeof(newinfo
.szName
));
158 if (info
.idInfo
== CPL_DYNAMIC_RES
)
159 memcpy(applet
->info
[i
].szInfo
, newinfo
.szInfo
, sizeof(newinfo
.szInfo
));
160 memcpy(applet
->info
[i
].szHelpFile
, newinfo
.szHelpFile
, sizeof(newinfo
.szHelpFile
));
162 if (info
.idName
== CPL_DYNAMIC_RES
)
163 MultiByteToWideChar(CP_ACP
, 0, ((LPNEWCPLINFOA
)&newinfo
)->szName
,
164 sizeof(((LPNEWCPLINFOA
)&newinfo
)->szName
) / sizeof(CHAR
),
165 applet
->info
[i
].szName
,
166 sizeof(applet
->info
[i
].szName
) / sizeof(WCHAR
));
167 if (info
.idInfo
== CPL_DYNAMIC_RES
)
168 MultiByteToWideChar(CP_ACP
, 0, ((LPNEWCPLINFOA
)&newinfo
)->szInfo
,
169 sizeof(((LPNEWCPLINFOA
)&newinfo
)->szInfo
) / sizeof(CHAR
),
170 applet
->info
[i
].szInfo
,
171 sizeof(applet
->info
[i
].szInfo
) / sizeof(WCHAR
));
172 MultiByteToWideChar(CP_ACP
, 0, ((LPNEWCPLINFOA
)&newinfo
)->szHelpFile
,
173 sizeof(((LPNEWCPLINFOA
)&newinfo
)->szHelpFile
) / sizeof(CHAR
),
174 applet
->info
[i
].szHelpFile
,
175 sizeof(applet
->info
[i
].szHelpFile
) / sizeof(WCHAR
));
180 applet
->next
= panel
->first
;
181 panel
->first
= applet
;
186 Control_UnloadApplet(applet
);
190 #define IDC_LISTVIEW 1000
191 #define IDC_STATUSBAR 1001
193 #define NUM_COLUMNS 2
194 #define LISTVIEW_DEFSTYLE (WS_CHILD | WS_VISIBLE | WS_TABSTOP |\
195 LVS_SORTASCENDING | LVS_AUTOARRANGE | LVS_SINGLESEL)
197 static BOOL
Control_CreateListView (CPanel
*panel
)
200 WCHAR empty_string
[] = {0};
201 WCHAR buf
[MAX_STRING_LEN
];
204 /* Create list view */
205 GetClientRect(panel
->hWndStatusBar
, &sb
);
206 GetClientRect(panel
->hWnd
, &ws
);
208 panel
->hWndListView
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_LISTVIEWW
,
209 empty_string
, LISTVIEW_DEFSTYLE
| LVS_ICON
,
210 0, 0, ws
.right
- ws
.left
, ws
.bottom
- ws
.top
-
211 (sb
.bottom
- sb
.top
), panel
->hWnd
,
212 (HMENU
) IDC_LISTVIEW
, panel
->hInst
, NULL
);
214 if (!panel
->hWndListView
)
217 /* Create image lists for list view */
218 panel
->hImageListSmall
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
),
219 GetSystemMetrics(SM_CYSMICON
), ILC_MASK
, 1, 1);
220 panel
->hImageListLarge
= ImageList_Create(GetSystemMetrics(SM_CXICON
),
221 GetSystemMetrics(SM_CYICON
), ILC_MASK
, 1, 1);
223 SendMessageW(panel
->hWndListView
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)panel
->hImageListSmall
);
224 SendMessageW(panel
->hWndListView
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)panel
->hImageListLarge
);
226 /* Create columns for list view */
227 lvc
.mask
= LVCF_FMT
| LVCF_TEXT
| LVCF_SUBITEM
| LVCF_WIDTH
;
229 lvc
.fmt
= LVCFMT_LEFT
;
233 lvc
.cx
= (ws
.right
- ws
.left
) / 3;
234 LoadStringW(shell32_hInstance
, IDS_CPANEL_NAME
, buf
, sizeof(buf
) / sizeof(buf
[0]));
236 if (ListView_InsertColumnW(panel
->hWndListView
, 0, &lvc
) == -1)
239 /* Description column */
241 lvc
.cx
= ((ws
.right
- ws
.left
) / 3) * 2;
242 LoadStringW(shell32_hInstance
, IDS_CPANEL_DESCRIPTION
, buf
, sizeof(buf
) /
245 if (ListView_InsertColumnW(panel
->hWndListView
, 1, &lvc
) == -1)
251 static void Control_WndProc_Create(HWND hWnd
, const CREATESTRUCTW
* cs
)
253 CPanel
* panel
= cs
->lpCreateParams
;
254 HMENU hMenu
, hSubMenu
;
258 int menucount
, index
;
261 INITCOMMONCONTROLSEX icex
;
265 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)panel
);
268 /* Initialise common control DLL */
269 icex
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
270 icex
.dwICC
= ICC_LISTVIEW_CLASSES
| ICC_BAR_CLASSES
;
271 InitCommonControlsEx(&icex
);
273 /* create the status bar */
274 if (!(panel
->hWndStatusBar
= CreateStatusWindowW(WS_CHILD
| WS_VISIBLE
| CCS_BOTTOM
| SBARS_SIZEGRIP
, NULL
, hWnd
, IDC_STATUSBAR
)))
278 SendMessageW(panel
->hWndStatusBar
, SB_SETPARTS
, 1, (LPARAM
) &sb_parts
);
280 /* create the list view */
281 if (!Control_CreateListView(panel
))
284 hMenu
= LoadMenuW(shell32_hInstance
, MAKEINTRESOURCEW(MENU_CPANEL
));
286 /* insert menu items for applets */
287 hSubMenu
= GetSubMenu(hMenu
, 0);
290 for (applet
= panel
->first
; applet
; applet
= applet
->next
) {
291 for (i
= 0; i
< applet
->count
; i
++) {
292 if (!applet
->info
[i
].dwSize
)
295 /* set up a CPlItem for this particular subprogram */
296 item
= HeapAlloc(GetProcessHeap(), 0, sizeof(CPlItem
));
301 item
->applet
= applet
;
304 mii
.cbSize
= sizeof(MENUITEMINFOW
);
305 mii
.fMask
= MIIM_ID
| MIIM_STRING
| MIIM_DATA
;
306 mii
.dwTypeData
= applet
->info
[i
].szName
;
307 mii
.cch
= sizeof(applet
->info
[i
].szName
) / sizeof(applet
->info
[i
].szName
[0]);
308 mii
.wID
= IDM_CPANEL_APPLET_BASE
+ menucount
;
309 mii
.dwItemData
= (ULONG_PTR
)item
;
311 if (InsertMenuItemW(hSubMenu
, menucount
, TRUE
, &mii
)) {
312 /* add the list view item */
313 index
= ImageList_AddIcon(panel
->hImageListLarge
, applet
->info
[i
].hIcon
);
314 ImageList_AddIcon(panel
->hImageListSmall
, applet
->info
[i
].hIcon
);
316 lvItem
.mask
= LVIF_IMAGE
| LVIF_TEXT
| LVIF_PARAM
;
317 lvItem
.iItem
= menucount
;
319 lvItem
.pszText
= applet
->info
[i
].szName
;
320 lvItem
.iImage
= index
;
321 lvItem
.lParam
= (LPARAM
) item
;
323 itemidx
= ListView_InsertItemW(panel
->hWndListView
, &lvItem
);
325 /* add the description */
326 ListView_SetItemTextW(panel
->hWndListView
, itemidx
, 1,
327 applet
->info
[i
].szInfo
);
329 /* update menu bar, increment count */
336 panel
->total_subprogs
= menucount
;
338 /* check the "large items" icon in the View menu */
339 hSubMenu
= GetSubMenu(hMenu
, 1);
340 CheckMenuRadioItem(hSubMenu
, FCIDM_SHVIEW_BIGICON
, FCIDM_SHVIEW_REPORTVIEW
,
341 FCIDM_SHVIEW_BIGICON
, MF_BYCOMMAND
);
343 SetMenu(hWnd
, hMenu
);
346 static void Control_FreeCPlItems(HWND hWnd
, CPanel
*panel
)
348 HMENU hMenu
, hSubMenu
;
352 /* get the File menu */
353 hMenu
= GetMenu(hWnd
);
358 hSubMenu
= GetSubMenu(hMenu
, 0);
363 /* loop and free the item data */
364 for (i
= IDM_CPANEL_APPLET_BASE
; i
<= IDM_CPANEL_APPLET_BASE
+ panel
->total_subprogs
; i
++)
366 mii
.cbSize
= sizeof(MENUITEMINFOW
);
367 mii
.fMask
= MIIM_DATA
;
369 if (!GetMenuItemInfoW(hSubMenu
, i
, FALSE
, &mii
))
372 HeapFree(GetProcessHeap(), 0, (LPVOID
) mii
.dwItemData
);
376 static void Control_UpdateListViewStyle(CPanel
*panel
, UINT style
, UINT id
)
378 HMENU hMenu
, hSubMenu
;
380 SetWindowLongW(panel
->hWndListView
, GWL_STYLE
, LISTVIEW_DEFSTYLE
| style
);
382 /* update the menu */
383 hMenu
= GetMenu(panel
->hWnd
);
384 hSubMenu
= GetSubMenu(hMenu
, 1);
386 CheckMenuRadioItem(hSubMenu
, FCIDM_SHVIEW_BIGICON
, FCIDM_SHVIEW_REPORTVIEW
,
390 static CPlItem
* Control_GetCPlItem_From_MenuID(HWND hWnd
, UINT id
)
392 HMENU hMenu
, hSubMenu
;
395 /* retrieve the CPlItem structure from the menu item data */
396 hMenu
= GetMenu(hWnd
);
401 hSubMenu
= GetSubMenu(hMenu
, 0);
406 mii
.cbSize
= sizeof(MENUITEMINFOW
);
407 mii
.fMask
= MIIM_DATA
;
409 if (!GetMenuItemInfoW(hSubMenu
, id
, FALSE
, &mii
))
412 return (CPlItem
*) mii
.dwItemData
;
415 static CPlItem
* Control_GetCPlItem_From_ListView(CPanel
*panel
)
420 selitem
= SendMessageW(panel
->hWndListView
, LVM_GETNEXTITEM
, -1, LVNI_FOCUSED
425 lvItem
.iItem
= selitem
;
426 lvItem
.mask
= LVIF_PARAM
;
428 if (SendMessageW(panel
->hWndListView
, LVM_GETITEMW
, 0, (LPARAM
) &lvItem
))
429 return (CPlItem
*) lvItem
.lParam
;
435 static void Control_StartApplet(HWND hWnd
, CPlItem
*item
)
437 WCHAR verbOpen
[] = {'c','p','l','o','p','e','n',0};
438 WCHAR format
[] = {'@','%','d',0};
439 WCHAR param
[MAX_PATH
];
441 /* execute the applet if item is valid */
444 wsprintfW(param
, format
, item
->id
);
445 ShellExecuteW(hWnd
, verbOpen
, item
->applet
->cmd
, param
, NULL
, SW_SHOW
);
449 static LRESULT WINAPI
Control_WndProc(HWND hWnd
, UINT wMsg
,
450 WPARAM lParam1
, LPARAM lParam2
)
452 CPanel
* panel
= (CPanel
*)GetWindowLongPtrW(hWnd
, 0);
454 if (panel
|| wMsg
== WM_CREATE
) {
457 Control_WndProc_Create(hWnd
, (CREATESTRUCTW
*)lParam2
);
461 CPlApplet
* applet
= panel
->first
;
463 applet
= Control_UnloadApplet(applet
);
465 Control_FreeCPlItems(hWnd
, panel
);
469 switch (LOWORD(lParam1
))
471 case IDM_CPANEL_EXIT
:
472 SendMessageW(hWnd
, WM_CLOSE
, 0, 0);
475 case IDM_CPANEL_ABOUT
:
477 WCHAR appName
[MAX_STRING_LEN
];
479 LoadStringW(shell32_hInstance
, IDS_CPANEL_TITLE
, appName
,
480 sizeof(appName
) / sizeof(appName
[0]));
481 ShellAboutW(hWnd
, appName
, NULL
, NULL
);
486 case FCIDM_SHVIEW_BIGICON
:
487 Control_UpdateListViewStyle(panel
, LVS_ICON
, FCIDM_SHVIEW_BIGICON
);
490 case FCIDM_SHVIEW_SMALLICON
:
491 Control_UpdateListViewStyle(panel
, LVS_SMALLICON
, FCIDM_SHVIEW_SMALLICON
);
494 case FCIDM_SHVIEW_LISTVIEW
:
495 Control_UpdateListViewStyle(panel
, LVS_LIST
, FCIDM_SHVIEW_LISTVIEW
);
498 case FCIDM_SHVIEW_REPORTVIEW
:
499 Control_UpdateListViewStyle(panel
, LVS_REPORT
, FCIDM_SHVIEW_REPORTVIEW
);
503 /* check if this is an applet */
504 if ((LOWORD(lParam1
) >= IDM_CPANEL_APPLET_BASE
) &&
505 (LOWORD(lParam1
) <= IDM_CPANEL_APPLET_BASE
+ panel
->total_subprogs
))
507 Control_StartApplet(hWnd
, Control_GetCPlItem_From_MenuID(hWnd
, LOWORD(lParam1
)));
518 LPNMHDR nmh
= (LPNMHDR
) lParam2
;
528 Control_StartApplet(hWnd
, Control_GetCPlItem_From_ListView(panel
));
531 case LVN_ITEMCHANGED
:
533 CPlItem
*item
= Control_GetCPlItem_From_ListView(panel
);
535 /* update the status bar if item is valid */
537 SetWindowTextW(panel
->hWndStatusBar
,
538 item
->applet
->info
[item
->id
].szInfo
);
540 SetWindowTextW(panel
->hWndStatusBar
, NULL
);
553 /* check if this is an applet */
554 if ((LOWORD(lParam1
) >= IDM_CPANEL_APPLET_BASE
) &&
555 (LOWORD(lParam1
) <= IDM_CPANEL_APPLET_BASE
+ panel
->total_subprogs
))
557 CPlItem
*item
= Control_GetCPlItem_From_MenuID(hWnd
, LOWORD(lParam1
));
559 /* update the status bar if item is valid */
561 SetWindowTextW(panel
->hWndStatusBar
, item
->applet
->info
[item
->id
].szInfo
);
563 else if ((HIWORD(lParam1
) == 0xFFFF) && (lParam2
== 0))
565 /* reset status bar description to that of the selected icon */
566 CPlItem
*item
= Control_GetCPlItem_From_ListView(panel
);
569 SetWindowTextW(panel
->hWndStatusBar
, item
->applet
->info
[item
->id
].szInfo
);
571 SetWindowTextW(panel
->hWndStatusBar
, NULL
);
576 SetWindowTextW(panel
->hWndStatusBar
, NULL
);
585 hdwp
= BeginDeferWindowPos(2);
590 GetClientRect(panel
->hWndStatusBar
, &sb
);
592 hdwp
= DeferWindowPos(hdwp
, panel
->hWndListView
, NULL
, 0, 0,
593 LOWORD(lParam2
), HIWORD(lParam2
) - (sb
.bottom
- sb
.top
),
594 SWP_NOZORDER
| SWP_NOMOVE
);
599 hdwp
= DeferWindowPos(hdwp
, panel
->hWndStatusBar
, NULL
, 0, 0,
600 LOWORD(lParam2
), LOWORD(lParam1
), SWP_NOZORDER
| SWP_NOMOVE
);
603 EndDeferWindowPos(hdwp
);
610 return DefWindowProcW(hWnd
, wMsg
, lParam1
, lParam2
);
613 static void Control_DoInterface(CPanel
* panel
, HWND hWnd
, HINSTANCE hInst
)
617 WCHAR appName
[MAX_STRING_LEN
];
618 const WCHAR className
[] = {'S','h','e','l','l','_','C','o','n','t','r','o',
619 'l','_','W','n','d','C','l','a','s','s',0};
621 LoadStringW(shell32_hInstance
, IDS_CPANEL_TITLE
, appName
, sizeof(appName
) / sizeof(appName
[0]));
623 wc
.style
= CS_HREDRAW
|CS_VREDRAW
;
624 wc
.lpfnWndProc
= Control_WndProc
;
626 wc
.cbWndExtra
= sizeof(CPlApplet
*);
627 wc
.hInstance
= panel
->hInst
= hInst
;
629 wc
.hCursor
= LoadCursorW( 0, (LPWSTR
)IDC_ARROW
);
630 wc
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
631 wc
.lpszMenuName
= NULL
;
632 wc
.lpszClassName
= className
;
634 if (!RegisterClassW(&wc
)) return;
636 CreateWindowExW(0, wc
.lpszClassName
, appName
,
637 WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
638 CW_USEDEFAULT
, CW_USEDEFAULT
,
639 CW_USEDEFAULT
, CW_USEDEFAULT
,
640 hWnd
, NULL
, hInst
, panel
);
641 if (!panel
->hWnd
) return;
643 while (GetMessageW(&msg
, panel
->hWnd
, 0, 0)) {
644 TranslateMessage(&msg
);
645 DispatchMessageW(&msg
);
649 static void Control_RegisterRegistryApplets(HWND hWnd
, CPanel
*panel
, HKEY hkey_root
, LPCWSTR szRepPath
)
651 WCHAR name
[MAX_PATH
];
652 WCHAR value
[MAX_PATH
];
655 if (RegOpenKeyW(hkey_root
, szRepPath
, &hkey
) == ERROR_SUCCESS
)
661 DWORD nameLen
= MAX_PATH
;
662 DWORD valueLen
= MAX_PATH
;
664 if (RegEnumValueW(hkey
, idx
, name
, &nameLen
, NULL
, NULL
, (LPBYTE
)value
, &valueLen
) != ERROR_SUCCESS
)
667 Control_LoadApplet(hWnd
, value
, panel
);
673 static void Control_DoWindow(CPanel
* panel
, HWND hWnd
, HINSTANCE hInst
)
677 WCHAR buffer
[MAX_PATH
];
678 static const WCHAR wszAllCpl
[] = {'*','.','c','p','l',0};
679 static const WCHAR wszRegPath
[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t',
680 '\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
681 '\\','C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','C','p','l','s',0};
684 /* first add .cpl files in the system directory */
685 GetSystemDirectoryW( buffer
, MAX_PATH
);
686 p
= buffer
+ strlenW(buffer
);
688 lstrcpyW(p
, wszAllCpl
);
690 if ((h
= FindFirstFileW(buffer
, &fd
)) != INVALID_HANDLE_VALUE
) {
692 lstrcpyW(p
, fd
.cFileName
);
693 Control_LoadApplet(hWnd
, buffer
, panel
);
694 } while (FindNextFileW(h
, &fd
));
698 /* now check for cpls in the registry */
699 Control_RegisterRegistryApplets(hWnd
, panel
, HKEY_LOCAL_MACHINE
, wszRegPath
);
700 Control_RegisterRegistryApplets(hWnd
, panel
, HKEY_CURRENT_USER
, wszRegPath
);
702 Control_DoInterface(panel
, hWnd
, hInst
);
705 static void Control_DoLaunch(CPanel
* panel
, HWND hWnd
, LPCWSTR wszCmd
)
721 LPWSTR extraPmtsBuf
= NULL
;
722 LPWSTR extraPmts
= NULL
;
725 buffer
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(wszCmd
) + 1) * sizeof(*wszCmd
));
728 end
= lstrcpyW(buffer
, wszCmd
);
732 if (ch
== '"') quoted
= !quoted
;
733 if (!quoted
&& (ch
== ' ' || ch
== ',' || ch
== '\0')) {
738 } else if (*beg
== '\0') {
744 if (ch
== '\0') break;
746 if (ch
== ' ') while (end
[1] == ' ') end
++;
750 while ((ptr
= StrChrW(buffer
, '"')))
751 memmove(ptr
, ptr
+1, lstrlenW(ptr
)*sizeof(WCHAR
));
753 /* now check for any quotes in extraPmtsBuf and remove */
754 if (extraPmtsBuf
!= NULL
)
756 beg
= end
= extraPmtsBuf
;
761 if (ch
== '"') quoted
= !quoted
;
762 if (!quoted
&& (ch
== ' ' || ch
== ',' || ch
== '\0')) {
769 if (ch
== '\0') break;
771 if (ch
== ' ') while (end
[1] == ' ') end
++;
776 while ((ptr
= StrChrW(extraPmts
, '"')))
777 memmove(ptr
, ptr
+1, lstrlenW(ptr
)*sizeof(WCHAR
));
779 if (extraPmts
== NULL
)
780 extraPmts
= extraPmtsBuf
;
783 /* Now check if there had been a numerical value in the extra params */
784 if ((extraPmts
) && (*extraPmts
== '@') && (sp
== -1)) {
785 sp
= atoiW(extraPmts
+ 1);
788 TRACE("cmd %s, extra %s, sp %d\n", debugstr_w(buffer
), debugstr_w(extraPmts
), sp
);
790 Control_LoadApplet(hWnd
, buffer
, panel
);
793 CPlApplet
* applet
= panel
->first
;
795 assert(applet
&& applet
->next
== NULL
);
797 /* we've been given a textual parameter (or none at all) */
799 while ((++sp
) != applet
->count
) {
800 if (applet
->info
[sp
].dwSize
) {
801 TRACE("sp %d, name %s\n", sp
, debugstr_w(applet
->info
[sp
].szName
));
803 if (StrCmpIW(extraPmts
, applet
->info
[sp
].szName
) == 0)
809 if (sp
>= applet
->count
) {
810 WARN("Out of bounds (%u >= %u), setting to 0\n", sp
, applet
->count
);
814 if (applet
->info
[sp
].dwSize
) {
815 if (!applet
->proc(applet
->hWnd
, CPL_STARTWPARMSA
, sp
, (LPARAM
)extraPmts
))
816 applet
->proc(applet
->hWnd
, CPL_DBLCLK
, sp
, applet
->info
[sp
].lData
);
819 Control_UnloadApplet(applet
);
822 HeapFree(GetProcessHeap(), 0, buffer
);
825 /*************************************************************************
826 * Control_RunDLLW [SHELL32.@]
829 void WINAPI
Control_RunDLLW(HWND hWnd
, HINSTANCE hInst
, LPCWSTR cmd
, DWORD nCmdShow
)
833 TRACE("(%p, %p, %s, 0x%08x)\n",
834 hWnd
, hInst
, debugstr_w(cmd
), nCmdShow
);
836 memset(&panel
, 0, sizeof(panel
));
839 Control_DoWindow(&panel
, hWnd
, hInst
);
841 Control_DoLaunch(&panel
, hWnd
, cmd
);
845 /*************************************************************************
846 * Control_RunDLLA [SHELL32.@]
849 void WINAPI
Control_RunDLLA(HWND hWnd
, HINSTANCE hInst
, LPCSTR cmd
, DWORD nCmdShow
)
851 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, cmd
, -1, NULL
, 0 );
852 LPWSTR wszCmd
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
853 if (wszCmd
&& MultiByteToWideChar(CP_ACP
, 0, cmd
, -1, wszCmd
, len
))
855 Control_RunDLLW(hWnd
, hInst
, wszCmd
, nCmdShow
);
857 HeapFree(GetProcessHeap(), 0, wszCmd
);
860 /*************************************************************************
861 * Control_FillCache_RunDLLW [SHELL32.@]
864 HRESULT WINAPI
Control_FillCache_RunDLLW(HWND hWnd
, HANDLE hModule
, DWORD w
, DWORD x
)
866 FIXME("%p %p 0x%08x 0x%08x stub\n", hWnd
, hModule
, w
, x
);
870 /*************************************************************************
871 * Control_FillCache_RunDLLA [SHELL32.@]
874 HRESULT WINAPI
Control_FillCache_RunDLLA(HWND hWnd
, HANDLE hModule
, DWORD w
, DWORD x
)
876 return Control_FillCache_RunDLLW(hWnd
, hModule
, w
, x
);
879 /*************************************************************************
880 * CallCPLEntry16 [SHELL32.166]
882 * called by desk.cpl on "Advanced" with:
883 * hMod("DeskCp16.Dll"), pFunc("CplApplet"), 0, 1, 0xc, 0
886 DWORD WINAPI
CallCPLEntry16(HMODULE hMod
, FARPROC pFunc
, DWORD dw3
, DWORD dw4
, DWORD dw5
, DWORD dw6
)
888 FIXME("(%p, %p, %08x, %08x, %08x, %08x): stub.\n", hMod
, pFunc
, dw3
, dw4
, dw5
, dw6
);