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/winbase16.h"
34 #include "wine/debug.h"
36 #include "wine/unicode.h"
39 #define NO_SHLWAPI_REG
44 #include "shell32_main.h"
46 #define MAX_STRING_LEN 1024
48 WINE_DEFAULT_DEBUG_CHANNEL(shlctrl);
50 CPlApplet* Control_UnloadApplet(CPlApplet* applet)
55 for (i = 0; i < applet->count; i++) {
56 if (!applet->info[i].dwSize) continue;
57 applet->proc(applet->hWnd, CPL_STOP, i, applet->info[i].lData);
59 if (applet->proc) applet->proc(applet->hWnd, CPL_EXIT, 0L, 0L);
60 FreeLibrary(applet->hModule);
62 HeapFree(GetProcessHeap(), 0, applet->cmd);
63 HeapFree(GetProcessHeap(), 0, applet);
67 CPlApplet* Control_LoadApplet(HWND hWnd, LPCWSTR cmd, CPanel* panel)
74 if (!(applet = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*applet))))
79 if (!(applet->hModule = LoadLibraryW(cmd))) {
80 WARN("Cannot load control panel applet %s\n", debugstr_w(cmd));
83 if (!(applet->proc = (APPLET_PROC)GetProcAddress(applet->hModule, "CPlApplet"))) {
84 WARN("Not a valid control panel applet %s\n", debugstr_w(cmd));
87 if (!applet->proc(hWnd, CPL_INIT, 0L, 0L)) {
88 WARN("Init of applet has failed\n");
91 if ((applet->count = applet->proc(hWnd, CPL_GETCOUNT, 0L, 0L)) == 0) {
92 WARN("No subprogram in applet\n");
96 applet = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, applet,
97 sizeof(*applet) + (applet->count - 1) * sizeof(NEWCPLINFOW));
99 if (!(applet->cmd = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmd)+1) * sizeof(WCHAR)))) {
100 WARN("Cannot allocate memory for applet path\n");
104 lstrcpyW(applet->cmd, cmd);
106 for (i = 0; i < applet->count; i++) {
107 ZeroMemory(&newinfo, sizeof(newinfo));
108 newinfo.dwSize = sizeof(NEWCPLINFOA);
109 applet->info[i].dwSize = sizeof(NEWCPLINFOW);
110 applet->info[i].dwFlags = 0;
111 applet->info[i].dwHelpContext = 0;
112 applet->info[i].szHelpFile[0] = '\0';
113 /* proc is supposed to return a null value upon success for
114 * CPL_INQUIRE and CPL_NEWINQUIRE
115 * However, real drivers don't seem to behave like this
116 * So, use introspection rather than return value
118 applet->proc(hWnd, CPL_INQUIRE, i, (LPARAM)&info);
119 applet->info[i].lData = info.lData;
120 if (info.idIcon != CPL_DYNAMIC_RES)
121 applet->info[i].hIcon = LoadIconW(applet->hModule,
122 MAKEINTRESOURCEW(info.idIcon));
123 if (info.idName != CPL_DYNAMIC_RES)
124 LoadStringW(applet->hModule, info.idName,
125 applet->info[i].szName, sizeof(applet->info[i].szName) / sizeof(WCHAR));
126 if (info.idInfo != CPL_DYNAMIC_RES)
127 LoadStringW(applet->hModule, info.idInfo,
128 applet->info[i].szInfo, sizeof(applet->info[i].szInfo) / sizeof(WCHAR));
130 /* some broken control panels seem to return incorrect values in CPL_INQUIRE,
131 but proper data in CPL_NEWINQUIRE. if we get an empty string or a null
132 icon, see what we can get from CPL_NEWINQUIRE */
134 if ((applet->info[i].szName == 0) || (lstrlenW(applet->info[i].szName) == 0))
135 info.idName = CPL_DYNAMIC_RES;
137 /* zero-length szInfo may not be a buggy applet, but it doesn't hurt for us
140 if ((applet->info[i].szInfo == 0) || (lstrlenW(applet->info[i].szInfo) == 0))
141 info.idInfo = CPL_DYNAMIC_RES;
143 if (applet->info[i].hIcon == NULL)
144 info.idIcon = CPL_DYNAMIC_RES;
146 if ((info.idIcon == CPL_DYNAMIC_RES) || (info.idName == CPL_DYNAMIC_RES) ||
147 (info.idInfo == CPL_DYNAMIC_RES)) {
148 applet->proc(hWnd, CPL_NEWINQUIRE, i, (LPARAM)&newinfo);
150 applet->info[i].dwFlags = newinfo.dwFlags;
151 applet->info[i].dwHelpContext = newinfo.dwHelpContext;
152 applet->info[i].lData = newinfo.lData;
153 if (info.idIcon == CPL_DYNAMIC_RES) {
154 if (!newinfo.hIcon) WARN("couldn't get icon for applet %u\n", i);
155 applet->info[i].hIcon = newinfo.hIcon;
157 if (newinfo.dwSize == sizeof(NEWCPLINFOW)) {
158 if (info.idName == CPL_DYNAMIC_RES)
159 memcpy(applet->info[i].szName, newinfo.szName, sizeof(newinfo.szName));
160 if (info.idInfo == CPL_DYNAMIC_RES)
161 memcpy(applet->info[i].szInfo, newinfo.szInfo, sizeof(newinfo.szInfo));
162 memcpy(applet->info[i].szHelpFile, newinfo.szHelpFile, sizeof(newinfo.szHelpFile));
164 if (info.idName == CPL_DYNAMIC_RES)
165 MultiByteToWideChar(CP_ACP, 0, ((LPNEWCPLINFOA)&newinfo)->szName,
166 sizeof(((LPNEWCPLINFOA)&newinfo)->szName) / sizeof(CHAR),
167 applet->info[i].szName,
168 sizeof(applet->info[i].szName) / sizeof(WCHAR));
169 if (info.idInfo == CPL_DYNAMIC_RES)
170 MultiByteToWideChar(CP_ACP, 0, ((LPNEWCPLINFOA)&newinfo)->szInfo,
171 sizeof(((LPNEWCPLINFOA)&newinfo)->szInfo) / sizeof(CHAR),
172 applet->info[i].szInfo,
173 sizeof(applet->info[i].szInfo) / sizeof(WCHAR));
174 MultiByteToWideChar(CP_ACP, 0, ((LPNEWCPLINFOA)&newinfo)->szHelpFile,
175 sizeof(((LPNEWCPLINFOA)&newinfo)->szHelpFile) / sizeof(CHAR),
176 applet->info[i].szHelpFile,
177 sizeof(applet->info[i].szHelpFile) / sizeof(WCHAR));
182 applet->next = panel->first;
183 panel->first = applet;
188 Control_UnloadApplet(applet);
192 #define IDC_LISTVIEW 1000
193 #define IDC_STATUSBAR 1001
195 #define NUM_COLUMNS 2
196 #define LISTVIEW_DEFSTYLE (WS_CHILD | WS_VISIBLE | WS_TABSTOP |\
197 LVS_SORTASCENDING | LVS_AUTOARRANGE | LVS_SINGLESEL)
199 static BOOL Control_CreateListView (CPanel *panel)
202 WCHAR empty_string[] = {0};
203 WCHAR buf[MAX_STRING_LEN];
206 /* Create list view */
207 GetClientRect(panel->hWndStatusBar, &sb);
208 GetClientRect(panel->hWnd, &ws);
210 panel->hWndListView = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW,
211 empty_string, LISTVIEW_DEFSTYLE | LVS_ICON,
212 0, 0, ws.right - ws.left, ws.bottom - ws.top -
213 (sb.bottom - sb.top), panel->hWnd,
214 (HMENU) IDC_LISTVIEW, panel->hInst, NULL);
216 if (!panel->hWndListView)
219 /* Create image lists for list view */
220 panel->hImageListSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
221 GetSystemMetrics(SM_CYSMICON), ILC_MASK, 1, 1);
222 panel->hImageListLarge = ImageList_Create(GetSystemMetrics(SM_CXICON),
223 GetSystemMetrics(SM_CYICON), ILC_MASK, 1, 1);
225 SendMessageW(panel->hWndListView, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)panel->hImageListSmall);
226 SendMessageW(panel->hWndListView, LVM_SETIMAGELIST, LVSIL_NORMAL, (LPARAM)panel->hImageListLarge);
228 /* Create columns for list view */
229 lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
231 lvc.fmt = LVCFMT_LEFT;
235 lvc.cx = (ws.right - ws.left) / 3;
236 LoadStringW(shell32_hInstance, IDS_CPANEL_NAME, buf, sizeof(buf) / sizeof(buf[0]));
238 if (ListView_InsertColumnW(panel->hWndListView, 0, &lvc) == -1)
241 /* Description column */
243 lvc.cx = ((ws.right - ws.left) / 3) * 2;
244 LoadStringW(shell32_hInstance, IDS_CPANEL_DESCRIPTION, buf, sizeof(buf) /
247 if (ListView_InsertColumnW(panel->hWndListView, 1, &lvc) == -1)
253 static void Control_WndProc_Create(HWND hWnd, const CREATESTRUCTW* cs)
255 CPanel* panel = cs->lpCreateParams;
256 HMENU hMenu, hSubMenu;
260 int menucount, index;
263 INITCOMMONCONTROLSEX icex;
267 SetWindowLongPtrW(hWnd, 0, (LONG_PTR)panel);
270 /* Initialise common control DLL */
271 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
272 icex.dwICC = ICC_LISTVIEW_CLASSES | ICC_BAR_CLASSES;
273 InitCommonControlsEx(&icex);
275 /* create the status bar */
276 if (!(panel->hWndStatusBar = CreateStatusWindowW(WS_CHILD | WS_VISIBLE | CCS_BOTTOM | SBARS_SIZEGRIP, NULL, hWnd, IDC_STATUSBAR)))
280 SendMessageW(panel->hWndStatusBar, SB_SETPARTS, 1, (LPARAM) &sb_parts);
282 /* create the list view */
283 if (!Control_CreateListView(panel))
286 hMenu = LoadMenuW(shell32_hInstance, MAKEINTRESOURCEW(MENU_CPANEL));
288 /* insert menu items for applets */
289 hSubMenu = GetSubMenu(hMenu, 0);
292 for (applet = panel->first; applet; applet = applet->next) {
293 for (i = 0; i < applet->count; i++) {
294 if (!applet->info[i].dwSize)
297 /* set up a CPlItem for this particular subprogram */
298 item = HeapAlloc(GetProcessHeap(), 0, sizeof(CPlItem));
303 item->applet = applet;
306 mii.cbSize = sizeof(MENUITEMINFOW);
307 mii.fMask = MIIM_ID | MIIM_STRING | MIIM_DATA;
308 mii.dwTypeData = applet->info[i].szName;
309 mii.cch = sizeof(applet->info[i].szName) / sizeof(applet->info[i].szName[0]);
310 mii.wID = IDM_CPANEL_APPLET_BASE + menucount;
311 mii.dwItemData = (ULONG_PTR)item;
313 if (InsertMenuItemW(hSubMenu, menucount, TRUE, &mii)) {
314 /* add the list view item */
315 index = ImageList_AddIcon(panel->hImageListLarge, applet->info[i].hIcon);
316 ImageList_AddIcon(panel->hImageListSmall, applet->info[i].hIcon);
318 lvItem.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_PARAM;
319 lvItem.iItem = menucount;
321 lvItem.pszText = applet->info[i].szName;
322 lvItem.iImage = index;
323 lvItem.lParam = (LPARAM) item;
325 itemidx = ListView_InsertItemW(panel->hWndListView, &lvItem);
327 /* add the description */
328 ListView_SetItemTextW(panel->hWndListView, itemidx, 1,
329 applet->info[i].szInfo);
331 /* update menu bar, increment count */
338 panel->total_subprogs = menucount;
340 /* check the "large items" icon in the View menu */
341 hSubMenu = GetSubMenu(hMenu, 1);
342 CheckMenuRadioItem(hSubMenu, FCIDM_SHVIEW_BIGICON, FCIDM_SHVIEW_REPORTVIEW,
343 FCIDM_SHVIEW_BIGICON, MF_BYCOMMAND);
345 SetMenu(hWnd, hMenu);
348 static void Control_FreeCPlItems(HWND hWnd, CPanel *panel)
350 HMENU hMenu, hSubMenu;
354 /* get the File menu */
355 hMenu = GetMenu(hWnd);
360 hSubMenu = GetSubMenu(hMenu, 0);
365 /* loop and free the item data */
366 for (i = IDM_CPANEL_APPLET_BASE; i <= IDM_CPANEL_APPLET_BASE + panel->total_subprogs; i++)
368 mii.cbSize = sizeof(MENUITEMINFOW);
369 mii.fMask = MIIM_DATA;
371 if (!GetMenuItemInfoW(hSubMenu, i, FALSE, &mii))
374 HeapFree(GetProcessHeap(), 0, (LPVOID) mii.dwItemData);
378 static void Control_UpdateListViewStyle(CPanel *panel, UINT style, UINT id)
380 HMENU hMenu, hSubMenu;
382 SetWindowLongW(panel->hWndListView, GWL_STYLE, LISTVIEW_DEFSTYLE | style);
384 /* update the menu */
385 hMenu = GetMenu(panel->hWnd);
386 hSubMenu = GetSubMenu(hMenu, 1);
388 CheckMenuRadioItem(hSubMenu, FCIDM_SHVIEW_BIGICON, FCIDM_SHVIEW_REPORTVIEW,
392 static CPlItem* Control_GetCPlItem_From_MenuID(HWND hWnd, UINT id)
394 HMENU hMenu, hSubMenu;
397 /* retrieve the CPlItem structure from the menu item data */
398 hMenu = GetMenu(hWnd);
403 hSubMenu = GetSubMenu(hMenu, 0);
408 mii.cbSize = sizeof(MENUITEMINFOW);
409 mii.fMask = MIIM_DATA;
411 if (!GetMenuItemInfoW(hSubMenu, id, FALSE, &mii))
414 return (CPlItem *) mii.dwItemData;
417 static CPlItem* Control_GetCPlItem_From_ListView(CPanel *panel)
422 selitem = SendMessageW(panel->hWndListView, LVM_GETNEXTITEM, -1, LVNI_FOCUSED
427 lvItem.iItem = selitem;
428 lvItem.mask = LVIF_PARAM;
430 if (SendMessageW(panel->hWndListView, LVM_GETITEMW, 0, (LPARAM) &lvItem))
431 return (CPlItem *) lvItem.lParam;
437 static void Control_StartApplet(HWND hWnd, CPlItem *item)
439 WCHAR verbOpen[] = {'c','p','l','o','p','e','n',0};
440 WCHAR format[] = {'@','%','d',0};
441 WCHAR param[MAX_PATH];
443 /* execute the applet if item is valid */
446 wsprintfW(param, format, item->id);
447 ShellExecuteW(hWnd, verbOpen, item->applet->cmd, param, NULL, SW_SHOW);
451 static LRESULT WINAPI Control_WndProc(HWND hWnd, UINT wMsg,
452 WPARAM lParam1, LPARAM lParam2)
454 CPanel* panel = (CPanel*)GetWindowLongPtrW(hWnd, 0);
456 if (panel || wMsg == WM_CREATE) {
459 Control_WndProc_Create(hWnd, (CREATESTRUCTW*)lParam2);
463 CPlApplet* applet = panel->first;
465 applet = Control_UnloadApplet(applet);
467 Control_FreeCPlItems(hWnd, panel);
471 switch (LOWORD(lParam1))
473 case IDM_CPANEL_EXIT:
474 SendMessageW(hWnd, WM_CLOSE, 0, 0);
477 case IDM_CPANEL_ABOUT:
479 WCHAR appName[MAX_STRING_LEN];
481 LoadStringW(shell32_hInstance, IDS_CPANEL_TITLE, appName,
482 sizeof(appName) / sizeof(appName[0]));
483 ShellAboutW(hWnd, appName, NULL, NULL);
488 case FCIDM_SHVIEW_BIGICON:
489 Control_UpdateListViewStyle(panel, LVS_ICON, FCIDM_SHVIEW_BIGICON);
492 case FCIDM_SHVIEW_SMALLICON:
493 Control_UpdateListViewStyle(panel, LVS_SMALLICON, FCIDM_SHVIEW_SMALLICON);
496 case FCIDM_SHVIEW_LISTVIEW:
497 Control_UpdateListViewStyle(panel, LVS_LIST, FCIDM_SHVIEW_LISTVIEW);
500 case FCIDM_SHVIEW_REPORTVIEW:
501 Control_UpdateListViewStyle(panel, LVS_REPORT, FCIDM_SHVIEW_REPORTVIEW);
505 /* check if this is an applet */
506 if ((LOWORD(lParam1) >= IDM_CPANEL_APPLET_BASE) &&
507 (LOWORD(lParam1) <= IDM_CPANEL_APPLET_BASE + panel->total_subprogs))
509 Control_StartApplet(hWnd, Control_GetCPlItem_From_MenuID(hWnd, LOWORD(lParam1)));
520 LPNMHDR nmh = (LPNMHDR) lParam2;
530 Control_StartApplet(hWnd, Control_GetCPlItem_From_ListView(panel));
533 case LVN_ITEMCHANGED:
535 CPlItem *item = Control_GetCPlItem_From_ListView(panel);
537 /* update the status bar if item is valid */
539 SetWindowTextW(panel->hWndStatusBar,
540 item->applet->info[item->id].szInfo);
542 SetWindowTextW(panel->hWndStatusBar, NULL);
555 /* check if this is an applet */
556 if ((LOWORD(lParam1) >= IDM_CPANEL_APPLET_BASE) &&
557 (LOWORD(lParam1) <= IDM_CPANEL_APPLET_BASE + panel->total_subprogs))
559 CPlItem *item = Control_GetCPlItem_From_MenuID(hWnd, LOWORD(lParam1));
561 /* update the status bar if item is valid */
563 SetWindowTextW(panel->hWndStatusBar, item->applet->info[item->id].szInfo);
565 else if ((HIWORD(lParam1) == 0xFFFF) && (lParam2 == 0))
567 /* reset status bar description to that of the selected icon */
568 CPlItem *item = Control_GetCPlItem_From_ListView(panel);
571 SetWindowTextW(panel->hWndStatusBar, item->applet->info[item->id].szInfo);
573 SetWindowTextW(panel->hWndStatusBar, NULL);
578 SetWindowTextW(panel->hWndStatusBar, NULL);
587 hdwp = BeginDeferWindowPos(2);
592 GetClientRect(panel->hWndStatusBar, &sb);
594 hdwp = DeferWindowPos(hdwp, panel->hWndListView, NULL, 0, 0,
595 LOWORD(lParam2), HIWORD(lParam2) - (sb.bottom - sb.top),
596 SWP_NOZORDER | SWP_NOMOVE);
601 hdwp = DeferWindowPos(hdwp, panel->hWndStatusBar, NULL, 0, 0,
602 LOWORD(lParam2), LOWORD(lParam1), SWP_NOZORDER | SWP_NOMOVE);
605 EndDeferWindowPos(hdwp);
612 return DefWindowProcW(hWnd, wMsg, lParam1, lParam2);
615 static void Control_DoInterface(CPanel* panel, HWND hWnd, HINSTANCE hInst)
619 WCHAR appName[MAX_STRING_LEN];
620 const WCHAR className[] = {'S','h','e','l','l','_','C','o','n','t','r','o',
621 'l','_','W','n','d','C','l','a','s','s',0};
623 LoadStringW(shell32_hInstance, IDS_CPANEL_TITLE, appName, sizeof(appName) / sizeof(appName[0]));
625 wc.style = CS_HREDRAW|CS_VREDRAW;
626 wc.lpfnWndProc = Control_WndProc;
628 wc.cbWndExtra = sizeof(CPlApplet*);
629 wc.hInstance = panel->hInst = hInst;
631 wc.hCursor = LoadCursorW( 0, (LPWSTR)IDC_ARROW );
632 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
633 wc.lpszMenuName = NULL;
634 wc.lpszClassName = className;
636 if (!RegisterClassW(&wc)) return;
638 CreateWindowExW(0, wc.lpszClassName, appName,
639 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
640 CW_USEDEFAULT, CW_USEDEFAULT,
641 CW_USEDEFAULT, CW_USEDEFAULT,
642 hWnd, NULL, hInst, panel);
643 if (!panel->hWnd) return;
645 while (GetMessageW(&msg, panel->hWnd, 0, 0)) {
646 TranslateMessage(&msg);
647 DispatchMessageW(&msg);
651 static void Control_RegisterRegistryApplets(HWND hWnd, CPanel *panel, HKEY hkey_root, LPCWSTR szRepPath)
653 WCHAR name[MAX_PATH];
654 WCHAR value[MAX_PATH];
657 if (RegOpenKeyW(hkey_root, szRepPath, &hkey) == ERROR_SUCCESS)
663 DWORD nameLen = MAX_PATH;
664 DWORD valueLen = MAX_PATH;
666 if (RegEnumValueW(hkey, idx, name, &nameLen, NULL, NULL, (LPBYTE)value, &valueLen) != ERROR_SUCCESS)
669 Control_LoadApplet(hWnd, value, panel);
675 static void Control_DoWindow(CPanel* panel, HWND hWnd, HINSTANCE hInst)
679 WCHAR buffer[MAX_PATH];
680 static const WCHAR wszAllCpl[] = {'*','.','c','p','l',0};
681 static const WCHAR wszRegPath[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t',
682 '\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
683 '\\','C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','C','p','l','s',0};
686 /* first add .cpl files in the system directory */
687 GetSystemDirectoryW( buffer, MAX_PATH );
688 p = buffer + strlenW(buffer);
690 lstrcpyW(p, wszAllCpl);
692 if ((h = FindFirstFileW(buffer, &fd)) != INVALID_HANDLE_VALUE) {
694 lstrcpyW(p, fd.cFileName);
695 Control_LoadApplet(hWnd, buffer, panel);
696 } while (FindNextFileW(h, &fd));
700 /* now check for cpls in the registry */
701 Control_RegisterRegistryApplets(hWnd, panel, HKEY_LOCAL_MACHINE, wszRegPath);
702 Control_RegisterRegistryApplets(hWnd, panel, HKEY_CURRENT_USER, wszRegPath);
704 Control_DoInterface(panel, hWnd, hInst);
707 static void Control_DoLaunch(CPanel* panel, HWND hWnd, LPCWSTR wszCmd)
723 LPWSTR extraPmtsBuf = NULL;
724 LPWSTR extraPmts = NULL;
727 buffer = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(wszCmd) + 1) * sizeof(*wszCmd));
730 end = lstrcpyW(buffer, wszCmd);
734 if (ch == '"') quoted = !quoted;
735 if (!quoted && (ch == ' ' || ch == ',' || ch == '\0')) {
740 } else if (*beg == '\0') {
746 if (ch == '\0') break;
748 if (ch == ' ') while (end[1] == ' ') end++;
752 while ((ptr = StrChrW(buffer, '"')))
753 memmove(ptr, ptr+1, lstrlenW(ptr)*sizeof(WCHAR));
755 /* now check for any quotes in extraPmtsBuf and remove */
756 if (extraPmtsBuf != NULL)
758 beg = end = extraPmtsBuf;
763 if (ch == '"') quoted = !quoted;
764 if (!quoted && (ch == ' ' || ch == ',' || ch == '\0')) {
771 if (ch == '\0') break;
773 if (ch == ' ') while (end[1] == ' ') end++;
778 while ((ptr = StrChrW(extraPmts, '"')))
779 memmove(ptr, ptr+1, lstrlenW(ptr)*sizeof(WCHAR));
781 if (extraPmts == NULL)
782 extraPmts = extraPmtsBuf;
785 /* Now check if there had been a numerical value in the extra params */
786 if ((extraPmts) && (*extraPmts == '@') && (sp == -1)) {
787 sp = atoiW(extraPmts + 1);
790 TRACE("cmd %s, extra %s, sp %d\n", debugstr_w(buffer), debugstr_w(extraPmts), sp);
792 Control_LoadApplet(hWnd, buffer, panel);
795 CPlApplet* applet = panel->first;
797 assert(applet && applet->next == NULL);
799 /* we've been given a textual parameter (or none at all) */
801 while ((++sp) != applet->count) {
802 if (applet->info[sp].dwSize) {
803 TRACE("sp %d, name %s\n", sp, debugstr_w(applet->info[sp].szName));
805 if (StrCmpIW(extraPmts, applet->info[sp].szName) == 0)
811 if (sp >= applet->count) {
812 WARN("Out of bounds (%u >= %u), setting to 0\n", sp, applet->count);
816 if (applet->info[sp].dwSize) {
817 if (!applet->proc(applet->hWnd, CPL_STARTWPARMSA, sp, (LPARAM)extraPmts))
818 applet->proc(applet->hWnd, CPL_DBLCLK, sp, applet->info[sp].lData);
821 Control_UnloadApplet(applet);
824 HeapFree(GetProcessHeap(), 0, buffer);
827 /*************************************************************************
828 * Control_RunDLLW [SHELL32.@]
831 void WINAPI Control_RunDLLW(HWND hWnd, HINSTANCE hInst, LPCWSTR cmd, DWORD nCmdShow)
835 TRACE("(%p, %p, %s, 0x%08x)\n",
836 hWnd, hInst, debugstr_w(cmd), nCmdShow);
838 memset(&panel, 0, sizeof(panel));
841 Control_DoWindow(&panel, hWnd, hInst);
843 Control_DoLaunch(&panel, hWnd, cmd);
847 /*************************************************************************
848 * Control_RunDLLA [SHELL32.@]
851 void WINAPI Control_RunDLLA(HWND hWnd, HINSTANCE hInst, LPCSTR cmd, DWORD nCmdShow)
853 DWORD len = MultiByteToWideChar(CP_ACP, 0, cmd, -1, NULL, 0 );
854 LPWSTR wszCmd = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
855 if (wszCmd && MultiByteToWideChar(CP_ACP, 0, cmd, -1, wszCmd, len ))
857 Control_RunDLLW(hWnd, hInst, wszCmd, nCmdShow);
859 HeapFree(GetProcessHeap(), 0, wszCmd);
862 /*************************************************************************
863 * Control_FillCache_RunDLLW [SHELL32.@]
866 HRESULT WINAPI Control_FillCache_RunDLLW(HWND hWnd, HANDLE hModule, DWORD w, DWORD x)
868 FIXME("%p %p 0x%08x 0x%08x stub\n", hWnd, hModule, w, x);
872 /*************************************************************************
873 * Control_FillCache_RunDLLA [SHELL32.@]
876 HRESULT WINAPI Control_FillCache_RunDLLA(HWND hWnd, HANDLE hModule, DWORD w, DWORD x)
878 return Control_FillCache_RunDLLW(hWnd, hModule, w, x);
882 /*************************************************************************
883 * RunDLL_CallEntry16 [SHELL32.122]
884 * the name is probably wrong
886 void WINAPI RunDLL_CallEntry16( DWORD proc, HWND hwnd, HINSTANCE inst,
887 LPCSTR cmdline, INT cmdshow )
892 TRACE( "proc %x hwnd %p inst %p cmdline %s cmdshow %d\n",
893 proc, hwnd, inst, debugstr_a(cmdline), cmdshow );
895 cmdline_seg = MapLS( cmdline );
896 args[4] = HWND_16(hwnd);
897 args[3] = MapHModuleLS(inst);
898 args[2] = SELECTOROF(cmdline_seg);
899 args[1] = OFFSETOF(cmdline_seg);
901 WOWCallback16Ex( proc, WCB16_PASCAL, sizeof(args), args, NULL );
902 UnMapLS( cmdline_seg );
905 /*************************************************************************
906 * CallCPLEntry16 [SHELL32.166]
908 * called by desk.cpl on "Advanced" with:
909 * hMod("DeskCp16.Dll"), pFunc("CplApplet"), 0, 1, 0xc, 0
912 DWORD WINAPI CallCPLEntry16(HMODULE hMod, FARPROC pFunc, DWORD dw3, DWORD dw4, DWORD dw5, DWORD dw6)
914 FIXME("(%p, %p, %08x, %08x, %08x, %08x): stub.\n", hMod, pFunc, dw3, dw4, dw5, dw6);