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].valid) continue;
55 applet->proc(applet->hWnd, CPL_STOP, i, applet->info[i].data);
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].valid = TRUE;
108 applet->info[i].helpfile[0] = 0;
109 /* proc is supposed to return a null value upon success for
110 * CPL_INQUIRE and CPL_NEWINQUIRE
111 * However, real drivers don't seem to behave like this
112 * So, use introspection rather than return value
114 applet->proc(hWnd, CPL_INQUIRE, i, (LPARAM)&info);
115 applet->info[i].data = info.lData;
116 if (info.idIcon != CPL_DYNAMIC_RES)
117 applet->info[i].icon = LoadIconW(applet->hModule, MAKEINTRESOURCEW(info.idIcon));
118 if (info.idName != CPL_DYNAMIC_RES)
119 LoadStringW(applet->hModule, info.idName,
120 applet->info[i].name, sizeof(applet->info[i].name) / sizeof(WCHAR));
121 if (info.idInfo != CPL_DYNAMIC_RES)
122 LoadStringW(applet->hModule, info.idInfo,
123 applet->info[i].info, sizeof(applet->info[i].info) / sizeof(WCHAR));
125 /* some broken control panels seem to return incorrect values in CPL_INQUIRE,
126 but proper data in CPL_NEWINQUIRE. if we get an empty string or a null
127 icon, see what we can get from CPL_NEWINQUIRE */
129 if (!applet->info[i].name[0]) info.idName = CPL_DYNAMIC_RES;
131 /* zero-length szInfo may not be a buggy applet, but it doesn't hurt for us
134 if (!applet->info[i].info[0]) info.idInfo = CPL_DYNAMIC_RES;
136 if (applet->info[i].icon == NULL)
137 info.idIcon = CPL_DYNAMIC_RES;
139 if ((info.idIcon == CPL_DYNAMIC_RES) || (info.idName == CPL_DYNAMIC_RES) ||
140 (info.idInfo == CPL_DYNAMIC_RES)) {
141 applet->proc(hWnd, CPL_NEWINQUIRE, i, (LPARAM)&newinfo);
143 applet->info[i].data = newinfo.lData;
144 if (info.idIcon == CPL_DYNAMIC_RES) {
145 if (!newinfo.hIcon) WARN("couldn't get icon for applet %u\n", i);
146 applet->info[i].icon = newinfo.hIcon;
148 if (newinfo.dwSize == sizeof(NEWCPLINFOW)) {
149 if (info.idName == CPL_DYNAMIC_RES)
150 memcpy(applet->info[i].name, newinfo.szName, sizeof(newinfo.szName));
151 if (info.idInfo == CPL_DYNAMIC_RES)
152 memcpy(applet->info[i].info, newinfo.szInfo, sizeof(newinfo.szInfo));
153 memcpy(applet->info[i].helpfile, newinfo.szHelpFile, sizeof(newinfo.szHelpFile));
155 if (info.idName == CPL_DYNAMIC_RES)
156 MultiByteToWideChar(CP_ACP, 0, ((LPNEWCPLINFOA)&newinfo)->szName,
157 sizeof(((LPNEWCPLINFOA)&newinfo)->szName) / sizeof(CHAR),
158 applet->info[i].name, sizeof(applet->info[i].name) / sizeof(WCHAR));
159 if (info.idInfo == CPL_DYNAMIC_RES)
160 MultiByteToWideChar(CP_ACP, 0, ((LPNEWCPLINFOA)&newinfo)->szInfo,
161 sizeof(((LPNEWCPLINFOA)&newinfo)->szInfo) / sizeof(CHAR),
162 applet->info[i].info, sizeof(applet->info[i].info) / sizeof(WCHAR));
163 MultiByteToWideChar(CP_ACP, 0, ((LPNEWCPLINFOA)&newinfo)->szHelpFile,
164 sizeof(((LPNEWCPLINFOA)&newinfo)->szHelpFile) / sizeof(CHAR),
165 applet->info[i].helpfile,
166 sizeof(applet->info[i].helpfile) / sizeof(WCHAR));
171 applet->next = panel->first;
172 panel->first = applet;
177 Control_UnloadApplet(applet);
181 #define IDC_LISTVIEW 1000
182 #define IDC_STATUSBAR 1001
184 #define NUM_COLUMNS 2
185 #define LISTVIEW_DEFSTYLE (WS_CHILD | WS_VISIBLE | WS_TABSTOP |\
186 LVS_SORTASCENDING | LVS_AUTOARRANGE | LVS_SINGLESEL)
188 static BOOL Control_CreateListView (CPanel *panel)
191 WCHAR empty_string[] = {0};
192 WCHAR buf[MAX_STRING_LEN];
195 /* Create list view */
196 GetClientRect(panel->hWndStatusBar, &sb);
197 GetClientRect(panel->hWnd, &ws);
199 panel->hWndListView = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW,
200 empty_string, LISTVIEW_DEFSTYLE | LVS_ICON,
201 0, 0, ws.right - ws.left, ws.bottom - ws.top -
202 (sb.bottom - sb.top), panel->hWnd,
203 (HMENU) IDC_LISTVIEW, panel->hInst, NULL);
205 if (!panel->hWndListView)
208 /* Create image lists for list view */
209 panel->hImageListSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
210 GetSystemMetrics(SM_CYSMICON), ILC_COLOR32 | ILC_MASK, 1, 1);
211 panel->hImageListLarge = ImageList_Create(GetSystemMetrics(SM_CXICON),
212 GetSystemMetrics(SM_CYICON), ILC_COLOR32 | ILC_MASK, 1, 1);
214 SendMessageW(panel->hWndListView, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)panel->hImageListSmall);
215 SendMessageW(panel->hWndListView, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)panel->hImageListLarge);
217 /* Create columns for list view */
218 lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
220 lvc.fmt = LVCFMT_LEFT;
224 lvc.cx = (ws.right - ws.left) / 3;
225 LoadStringW(shell32_hInstance, IDS_CPANEL_NAME, buf, sizeof(buf) / sizeof(buf[0]));
227 if (ListView_InsertColumnW(panel->hWndListView, 0, &lvc) == -1)
230 /* Description column */
232 lvc.cx = ((ws.right - ws.left) / 3) * 2;
233 LoadStringW(shell32_hInstance, IDS_CPANEL_DESCRIPTION, buf, sizeof(buf) /
236 if (ListView_InsertColumnW(panel->hWndListView, 1, &lvc) == -1)
242 static void Control_WndProc_Create(HWND hWnd, const CREATESTRUCTW* cs)
244 CPanel* panel = cs->lpCreateParams;
245 HMENU hMenu, hSubMenu;
249 int menucount, index;
252 INITCOMMONCONTROLSEX icex;
256 SetWindowLongPtrW(hWnd, 0, (LONG_PTR)panel);
259 /* Initialise common control DLL */
260 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
261 icex.dwICC = ICC_LISTVIEW_CLASSES | ICC_BAR_CLASSES;
262 InitCommonControlsEx(&icex);
264 /* create the status bar */
265 if (!(panel->hWndStatusBar = CreateStatusWindowW(WS_CHILD | WS_VISIBLE | CCS_BOTTOM | SBARS_SIZEGRIP, NULL, hWnd, IDC_STATUSBAR)))
269 SendMessageW(panel->hWndStatusBar, SB_SETPARTS, 1, (LPARAM) &sb_parts);
271 /* create the list view */
272 if (!Control_CreateListView(panel))
275 hMenu = LoadMenuW(shell32_hInstance, MAKEINTRESOURCEW(MENU_CPANEL));
277 /* insert menu items for applets */
278 hSubMenu = GetSubMenu(hMenu, 0);
281 for (applet = panel->first; applet; applet = applet->next) {
282 for (i = 0; i < applet->count; i++) {
283 if (!applet->info[i].valid)
286 /* set up a CPlItem for this particular subprogram */
287 item = HeapAlloc(GetProcessHeap(), 0, sizeof(CPlItem));
292 item->applet = applet;
295 mii.cbSize = sizeof(MENUITEMINFOW);
296 mii.fMask = MIIM_ID | MIIM_STRING | MIIM_DATA;
297 mii.dwTypeData = applet->info[i].name;
298 mii.cch = sizeof(applet->info[i].name) / sizeof(WCHAR);
299 mii.wID = IDM_CPANEL_APPLET_BASE + menucount;
300 mii.dwItemData = (ULONG_PTR)item;
302 if (InsertMenuItemW(hSubMenu, menucount, TRUE, &mii)) {
303 /* add the list view item */
304 HICON icon = applet->info[i].icon;
305 if (!icon) icon = LoadImageW( 0, (LPCWSTR)IDI_WINLOGO, IMAGE_ICON, 0, 0, LR_SHARED );
306 index = ImageList_AddIcon(panel->hImageListLarge, icon);
307 ImageList_AddIcon(panel->hImageListSmall, icon);
309 lvItem.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_PARAM;
310 lvItem.iItem = menucount;
312 lvItem.pszText = applet->info[i].name;
313 lvItem.iImage = index;
314 lvItem.lParam = (LPARAM) item;
316 itemidx = ListView_InsertItemW(panel->hWndListView, &lvItem);
318 /* add the description */
319 ListView_SetItemTextW(panel->hWndListView, itemidx, 1, applet->info[i].info);
321 /* update menu bar, increment count */
328 panel->total_subprogs = menucount;
330 /* check the "large items" icon in the View menu */
331 hSubMenu = GetSubMenu(hMenu, 1);
332 CheckMenuRadioItem(hSubMenu, FCIDM_SHVIEW_BIGICON, FCIDM_SHVIEW_REPORTVIEW,
333 FCIDM_SHVIEW_BIGICON, MF_BYCOMMAND);
335 SetMenu(hWnd, hMenu);
338 static void Control_FreeCPlItems(HWND hWnd, CPanel *panel)
340 HMENU hMenu, hSubMenu;
344 /* get the File menu */
345 hMenu = GetMenu(hWnd);
350 hSubMenu = GetSubMenu(hMenu, 0);
355 /* loop and free the item data */
356 for (i = IDM_CPANEL_APPLET_BASE; i <= IDM_CPANEL_APPLET_BASE + panel->total_subprogs; i++)
358 mii.cbSize = sizeof(MENUITEMINFOW);
359 mii.fMask = MIIM_DATA;
361 if (!GetMenuItemInfoW(hSubMenu, i, FALSE, &mii))
364 HeapFree(GetProcessHeap(), 0, (LPVOID) mii.dwItemData);
368 static void Control_UpdateListViewStyle(CPanel *panel, UINT style, UINT id)
370 HMENU hMenu, hSubMenu;
372 SetWindowLongW(panel->hWndListView, GWL_STYLE, LISTVIEW_DEFSTYLE | style);
374 /* update the menu */
375 hMenu = GetMenu(panel->hWnd);
376 hSubMenu = GetSubMenu(hMenu, 1);
378 CheckMenuRadioItem(hSubMenu, FCIDM_SHVIEW_BIGICON, FCIDM_SHVIEW_REPORTVIEW,
382 static CPlItem* Control_GetCPlItem_From_MenuID(HWND hWnd, UINT id)
384 HMENU hMenu, hSubMenu;
387 /* retrieve the CPlItem structure from the menu item data */
388 hMenu = GetMenu(hWnd);
393 hSubMenu = GetSubMenu(hMenu, 0);
398 mii.cbSize = sizeof(MENUITEMINFOW);
399 mii.fMask = MIIM_DATA;
401 if (!GetMenuItemInfoW(hSubMenu, id, FALSE, &mii))
404 return (CPlItem *) mii.dwItemData;
407 static CPlItem* Control_GetCPlItem_From_ListView(CPanel *panel)
412 selitem = SendMessageW(panel->hWndListView, LVM_GETNEXTITEM, -1, LVNI_FOCUSED
417 lvItem.iItem = selitem;
418 lvItem.mask = LVIF_PARAM;
420 if (SendMessageW(panel->hWndListView, LVM_GETITEMW, 0, (LPARAM) &lvItem))
421 return (CPlItem *) lvItem.lParam;
427 static void Control_StartApplet(HWND hWnd, CPlItem *item)
429 WCHAR verbOpen[] = {'c','p','l','o','p','e','n',0};
430 WCHAR format[] = {'@','%','d',0};
431 WCHAR param[MAX_PATH];
433 /* execute the applet if item is valid */
436 wsprintfW(param, format, item->id);
437 ShellExecuteW(hWnd, verbOpen, item->applet->cmd, param, NULL, SW_SHOW);
441 static LRESULT WINAPI Control_WndProc(HWND hWnd, UINT wMsg,
442 WPARAM lParam1, LPARAM lParam2)
444 CPanel* panel = (CPanel*)GetWindowLongPtrW(hWnd, 0);
446 if (panel || wMsg == WM_CREATE) {
449 Control_WndProc_Create(hWnd, (CREATESTRUCTW*)lParam2);
453 CPlApplet* applet = panel->first;
455 applet = Control_UnloadApplet(applet);
457 Control_FreeCPlItems(hWnd, panel);
461 switch (LOWORD(lParam1))
463 case IDM_CPANEL_EXIT:
464 SendMessageW(hWnd, WM_CLOSE, 0, 0);
467 case IDM_CPANEL_ABOUT:
469 WCHAR appName[MAX_STRING_LEN];
470 HICON icon = LoadImageW(shell32_hInstance, MAKEINTRESOURCEW(IDI_SHELL_CONTROL_PANEL),
471 IMAGE_ICON, 48, 48, LR_SHARED);
473 LoadStringW(shell32_hInstance, IDS_CPANEL_TITLE, appName,
474 sizeof(appName) / sizeof(appName[0]));
475 ShellAboutW(hWnd, appName, NULL, icon);
480 case FCIDM_SHVIEW_BIGICON:
481 Control_UpdateListViewStyle(panel, LVS_ICON, FCIDM_SHVIEW_BIGICON);
484 case FCIDM_SHVIEW_SMALLICON:
485 Control_UpdateListViewStyle(panel, LVS_SMALLICON, FCIDM_SHVIEW_SMALLICON);
488 case FCIDM_SHVIEW_LISTVIEW:
489 Control_UpdateListViewStyle(panel, LVS_LIST, FCIDM_SHVIEW_LISTVIEW);
492 case FCIDM_SHVIEW_REPORTVIEW:
493 Control_UpdateListViewStyle(panel, LVS_REPORT, FCIDM_SHVIEW_REPORTVIEW);
497 /* check if this is an applet */
498 if ((LOWORD(lParam1) >= IDM_CPANEL_APPLET_BASE) &&
499 (LOWORD(lParam1) <= IDM_CPANEL_APPLET_BASE + panel->total_subprogs))
501 Control_StartApplet(hWnd, Control_GetCPlItem_From_MenuID(hWnd, LOWORD(lParam1)));
512 LPNMHDR nmh = (LPNMHDR) lParam2;
522 Control_StartApplet(hWnd, Control_GetCPlItem_From_ListView(panel));
525 case LVN_ITEMCHANGED:
527 CPlItem *item = Control_GetCPlItem_From_ListView(panel);
529 /* update the status bar if item is valid */
531 SetWindowTextW(panel->hWndStatusBar, item->applet->info[item->id].info);
533 SetWindowTextW(panel->hWndStatusBar, NULL);
546 /* check if this is an applet */
547 if ((LOWORD(lParam1) >= IDM_CPANEL_APPLET_BASE) &&
548 (LOWORD(lParam1) <= IDM_CPANEL_APPLET_BASE + panel->total_subprogs))
550 CPlItem *item = Control_GetCPlItem_From_MenuID(hWnd, LOWORD(lParam1));
552 /* update the status bar if item is valid */
554 SetWindowTextW(panel->hWndStatusBar, item->applet->info[item->id].info);
556 else if ((HIWORD(lParam1) == 0xFFFF) && (lParam2 == 0))
558 /* reset status bar description to that of the selected icon */
559 CPlItem *item = Control_GetCPlItem_From_ListView(panel);
562 SetWindowTextW(panel->hWndStatusBar, item->applet->info[item->id].info);
564 SetWindowTextW(panel->hWndStatusBar, NULL);
569 SetWindowTextW(panel->hWndStatusBar, NULL);
578 hdwp = BeginDeferWindowPos(2);
583 GetClientRect(panel->hWndStatusBar, &sb);
585 hdwp = DeferWindowPos(hdwp, panel->hWndListView, NULL, 0, 0,
586 LOWORD(lParam2), HIWORD(lParam2) - (sb.bottom - sb.top),
587 SWP_NOZORDER | SWP_NOMOVE);
592 hdwp = DeferWindowPos(hdwp, panel->hWndStatusBar, NULL, 0, 0,
593 LOWORD(lParam2), LOWORD(lParam1), SWP_NOZORDER | SWP_NOMOVE);
596 EndDeferWindowPos(hdwp);
603 return DefWindowProcW(hWnd, wMsg, lParam1, lParam2);
606 static void Control_DoInterface(CPanel* panel, HWND hWnd, HINSTANCE hInst)
610 WCHAR appName[MAX_STRING_LEN];
611 const WCHAR className[] = {'S','h','e','l','l','_','C','o','n','t','r','o',
612 'l','_','W','n','d','C','l','a','s','s',0};
614 LoadStringW(shell32_hInstance, IDS_CPANEL_TITLE, appName, sizeof(appName) / sizeof(appName[0]));
616 wc.cbSize = sizeof(wc);
617 wc.style = CS_HREDRAW|CS_VREDRAW;
618 wc.lpfnWndProc = Control_WndProc;
620 wc.cbWndExtra = sizeof(CPlApplet*);
621 wc.hInstance = panel->hInst = hInst;
622 wc.hIcon = LoadIconW( shell32_hInstance, MAKEINTRESOURCEW(IDI_SHELL_CONTROL_PANEL) );
623 wc.hCursor = LoadCursorW( 0, (LPWSTR)IDC_ARROW );
624 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
625 wc.lpszMenuName = NULL;
626 wc.lpszClassName = className;
627 wc.hIconSm = LoadImageW( shell32_hInstance, MAKEINTRESOURCEW(IDI_SHELL_CONTROL_PANEL), IMAGE_ICON,
628 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
630 if (!RegisterClassExW(&wc)) return;
632 CreateWindowExW(0, wc.lpszClassName, appName,
633 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
634 CW_USEDEFAULT, CW_USEDEFAULT,
635 CW_USEDEFAULT, CW_USEDEFAULT,
636 hWnd, NULL, hInst, panel);
637 if (!panel->hWnd) return;
639 while (GetMessageW(&msg, panel->hWnd, 0, 0)) {
640 TranslateMessage(&msg);
641 DispatchMessageW(&msg);
645 static void Control_RegisterRegistryApplets(HWND hWnd, CPanel *panel, HKEY hkey_root, LPCWSTR szRepPath)
647 WCHAR name[MAX_PATH];
648 WCHAR value[MAX_PATH];
651 if (RegOpenKeyW(hkey_root, szRepPath, &hkey) == ERROR_SUCCESS)
657 DWORD nameLen = MAX_PATH;
658 DWORD valueLen = MAX_PATH;
660 if (RegEnumValueW(hkey, idx, name, &nameLen, NULL, NULL, (LPBYTE)value, &valueLen) != ERROR_SUCCESS)
663 Control_LoadApplet(hWnd, value, panel);
669 static void Control_DoWindow(CPanel* panel, HWND hWnd, HINSTANCE hInst)
673 WCHAR buffer[MAX_PATH];
674 static const WCHAR wszAllCpl[] = {'*','.','c','p','l',0};
675 static const WCHAR wszRegPath[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t',
676 '\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
677 '\\','C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','C','p','l','s',0};
680 /* first add .cpl files in the system directory */
681 GetSystemDirectoryW( buffer, MAX_PATH );
682 p = buffer + strlenW(buffer);
684 lstrcpyW(p, wszAllCpl);
686 if ((h = FindFirstFileW(buffer, &fd)) != INVALID_HANDLE_VALUE) {
688 lstrcpyW(p, fd.cFileName);
689 Control_LoadApplet(hWnd, buffer, panel);
690 } while (FindNextFileW(h, &fd));
694 /* now check for cpls in the registry */
695 Control_RegisterRegistryApplets(hWnd, panel, HKEY_LOCAL_MACHINE, wszRegPath);
696 Control_RegisterRegistryApplets(hWnd, panel, HKEY_CURRENT_USER, wszRegPath);
698 Control_DoInterface(panel, hWnd, hInst);
701 static void Control_DoLaunch(CPanel* panel, HWND hWnd, LPCWSTR wszCmd)
717 LPWSTR extraPmtsBuf = NULL;
718 LPWSTR extraPmts = NULL;
721 buffer = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(wszCmd) + 1) * sizeof(*wszCmd));
724 end = lstrcpyW(buffer, wszCmd);
728 if (ch == '"') quoted = !quoted;
729 if (!quoted && (ch == ' ' || ch == ',' || ch == '\0')) {
734 } else if (*beg == '\0') {
740 if (ch == '\0') break;
742 if (ch == ' ') while (end[1] == ' ') end++;
746 while ((ptr = StrChrW(buffer, '"')))
747 memmove(ptr, ptr+1, lstrlenW(ptr)*sizeof(WCHAR));
749 /* now check for any quotes in extraPmtsBuf and remove */
750 if (extraPmtsBuf != NULL)
752 beg = end = extraPmtsBuf;
757 if (ch == '"') quoted = !quoted;
758 if (!quoted && (ch == ' ' || ch == ',' || ch == '\0')) {
765 if (ch == '\0') break;
767 if (ch == ' ') while (end[1] == ' ') end++;
772 while ((ptr = StrChrW(extraPmts, '"')))
773 memmove(ptr, ptr+1, lstrlenW(ptr)*sizeof(WCHAR));
775 if (extraPmts == NULL)
776 extraPmts = extraPmtsBuf;
779 /* Now check if there had been a numerical value in the extra params */
780 if ((extraPmts) && (*extraPmts == '@') && (sp == -1)) {
781 sp = atoiW(extraPmts + 1);
784 TRACE("cmd %s, extra %s, sp %d\n", debugstr_w(buffer), debugstr_w(extraPmts), sp);
786 Control_LoadApplet(hWnd, buffer, panel);
789 CPlApplet* applet = panel->first;
791 assert(applet && applet->next == NULL);
793 /* we've been given a textual parameter (or none at all) */
795 while ((++sp) != applet->count) {
796 if (applet->info[sp].valid) {
797 TRACE("sp %d, name %s\n", sp, debugstr_w(applet->info[sp].name));
799 if (StrCmpIW(extraPmts, applet->info[sp].name) == 0)
805 if (sp >= applet->count) {
806 WARN("Out of bounds (%u >= %u), setting to 0\n", sp, applet->count);
810 if (applet->info[sp].valid) {
811 if (!applet->proc(applet->hWnd, CPL_STARTWPARMSW, sp, (LPARAM)extraPmts))
812 applet->proc(applet->hWnd, CPL_DBLCLK, sp, applet->info[sp].data);
815 Control_UnloadApplet(applet);
818 HeapFree(GetProcessHeap(), 0, buffer);
821 /*************************************************************************
822 * Control_RunDLLW [SHELL32.@]
825 void WINAPI Control_RunDLLW(HWND hWnd, HINSTANCE hInst, LPCWSTR cmd, DWORD nCmdShow)
829 TRACE("(%p, %p, %s, 0x%08x)\n",
830 hWnd, hInst, debugstr_w(cmd), nCmdShow);
832 memset(&panel, 0, sizeof(panel));
835 Control_DoWindow(&panel, hWnd, hInst);
837 Control_DoLaunch(&panel, hWnd, cmd);
841 /*************************************************************************
842 * Control_RunDLLA [SHELL32.@]
845 void WINAPI Control_RunDLLA(HWND hWnd, HINSTANCE hInst, LPCSTR cmd, DWORD nCmdShow)
847 DWORD len = MultiByteToWideChar(CP_ACP, 0, cmd, -1, NULL, 0 );
848 LPWSTR wszCmd = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
849 if (wszCmd && MultiByteToWideChar(CP_ACP, 0, cmd, -1, wszCmd, len ))
851 Control_RunDLLW(hWnd, hInst, wszCmd, nCmdShow);
853 HeapFree(GetProcessHeap(), 0, wszCmd);
856 /*************************************************************************
857 * Control_FillCache_RunDLLW [SHELL32.@]
860 HRESULT WINAPI Control_FillCache_RunDLLW(HWND hWnd, HANDLE hModule, DWORD w, DWORD x)
862 FIXME("%p %p 0x%08x 0x%08x stub\n", hWnd, hModule, w, x);
866 /*************************************************************************
867 * Control_FillCache_RunDLLA [SHELL32.@]
870 HRESULT WINAPI Control_FillCache_RunDLLA(HWND hWnd, HANDLE hModule, DWORD w, DWORD x)
872 return Control_FillCache_RunDLLW(hWnd, hModule, w, x);
875 /*************************************************************************
876 * CallCPLEntry16 [SHELL32.166]
878 * called by desk.cpl on "Advanced" with:
879 * hMod("DeskCp16.Dll"), pFunc("CplApplet"), 0, 1, 0xc, 0
882 DWORD WINAPI CallCPLEntry16(HMODULE hMod, FARPROC pFunc, DWORD dw3, DWORD dw4, DWORD dw5, DWORD dw6)
884 FIXME("(%p, %p, %08x, %08x, %08x, %08x): stub.\n", hMod, pFunc, dw3, dw4, dw5, dw6);