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
);
66 CPlApplet
* Control_LoadApplet(HWND hWnd
, LPCWSTR cmd
, CPanel
* panel
)
73 if (!(applet
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*applet
))))
78 if (!(applet
->hModule
= LoadLibraryW(cmd
))) {
79 WARN("Cannot load control panel applet %s\n", debugstr_w(cmd
));
82 if (!(applet
->proc
= (APPLET_PROC
)GetProcAddress(applet
->hModule
, "CPlApplet"))) {
83 WARN("Not a valid control panel applet %s\n", debugstr_w(cmd
));
86 if (!applet
->proc(hWnd
, CPL_INIT
, 0L, 0L)) {
87 WARN("Init of applet has failed\n");
90 if ((applet
->count
= applet
->proc(hWnd
, CPL_GETCOUNT
, 0L, 0L)) == 0) {
91 WARN("No subprogram in applet\n");
95 applet
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, applet
,
96 sizeof(*applet
) + (applet
->count
- 1) * sizeof(NEWCPLINFOW
));
98 for (i
= 0; i
< applet
->count
; i
++) {
99 ZeroMemory(&newinfo
, sizeof(newinfo
));
100 newinfo
.dwSize
= sizeof(NEWCPLINFOA
);
101 applet
->info
[i
].dwSize
= sizeof(NEWCPLINFOW
);
102 applet
->info
[i
].dwFlags
= 0;
103 applet
->info
[i
].dwHelpContext
= 0;
104 applet
->info
[i
].szHelpFile
[0] = '\0';
105 /* proc is supposed to return a null value upon success for
106 * CPL_INQUIRE and CPL_NEWINQUIRE
107 * However, real drivers don't seem to behave like this
108 * So, use introspection rather than return value
110 applet
->proc(hWnd
, CPL_INQUIRE
, i
, (LPARAM
)&info
);
111 applet
->info
[i
].lData
= info
.lData
;
112 if (info
.idIcon
!= CPL_DYNAMIC_RES
)
113 applet
->info
[i
].hIcon
= LoadIconW(applet
->hModule
,
114 MAKEINTRESOURCEW(info
.idIcon
));
115 if (info
.idName
!= CPL_DYNAMIC_RES
)
116 LoadStringW(applet
->hModule
, info
.idName
,
117 applet
->info
[i
].szName
, sizeof(applet
->info
[i
].szName
) / sizeof(WCHAR
));
118 if (info
.idInfo
!= CPL_DYNAMIC_RES
)
119 LoadStringW(applet
->hModule
, info
.idInfo
,
120 applet
->info
[i
].szInfo
, sizeof(applet
->info
[i
].szInfo
) / sizeof(WCHAR
));
122 /* some broken control panels seem to return incorrect values in CPL_INQUIRE,
123 but proper data in CPL_NEWINQUIRE. if we get an empty string or a null
124 icon, see what we can get from CPL_NEWINQUIRE */
126 if ((applet
->info
[i
].szName
== 0) || (lstrlenW(applet
->info
[i
].szName
) == 0))
127 info
.idName
= CPL_DYNAMIC_RES
;
129 /* zero-length szInfo may not be a buggy applet, but it doesn't hurt for us
132 if ((applet
->info
[i
].szInfo
== 0) || (lstrlenW(applet
->info
[i
].szInfo
) == 0))
133 info
.idInfo
= CPL_DYNAMIC_RES
;
135 if (applet
->info
[i
].hIcon
== NULL
)
136 info
.idIcon
= CPL_DYNAMIC_RES
;
138 if ((info
.idIcon
== CPL_DYNAMIC_RES
) || (info
.idName
== CPL_DYNAMIC_RES
) ||
139 (info
.idInfo
== CPL_DYNAMIC_RES
)) {
140 applet
->proc(hWnd
, CPL_NEWINQUIRE
, i
, (LPARAM
)&newinfo
);
142 applet
->info
[i
].dwFlags
= newinfo
.dwFlags
;
143 applet
->info
[i
].dwHelpContext
= newinfo
.dwHelpContext
;
144 applet
->info
[i
].lData
= newinfo
.lData
;
145 if (info
.idIcon
== CPL_DYNAMIC_RES
) {
146 if (!newinfo
.hIcon
) WARN("couldn't get icon for applet %u\n", i
);
147 applet
->info
[i
].hIcon
= newinfo
.hIcon
;
149 if (newinfo
.dwSize
== sizeof(NEWCPLINFOW
)) {
150 if (info
.idName
== CPL_DYNAMIC_RES
)
151 memcpy(applet
->info
[i
].szName
, newinfo
.szName
, sizeof(newinfo
.szName
));
152 if (info
.idInfo
== CPL_DYNAMIC_RES
)
153 memcpy(applet
->info
[i
].szInfo
, newinfo
.szInfo
, sizeof(newinfo
.szInfo
));
154 memcpy(applet
->info
[i
].szHelpFile
, newinfo
.szHelpFile
, sizeof(newinfo
.szHelpFile
));
156 if (info
.idName
== CPL_DYNAMIC_RES
)
157 MultiByteToWideChar(CP_ACP
, 0, ((LPNEWCPLINFOA
)&newinfo
)->szName
,
158 sizeof(((LPNEWCPLINFOA
)&newinfo
)->szName
) / sizeof(CHAR
),
159 applet
->info
[i
].szName
,
160 sizeof(applet
->info
[i
].szName
) / sizeof(WCHAR
));
161 if (info
.idInfo
== CPL_DYNAMIC_RES
)
162 MultiByteToWideChar(CP_ACP
, 0, ((LPNEWCPLINFOA
)&newinfo
)->szInfo
,
163 sizeof(((LPNEWCPLINFOA
)&newinfo
)->szInfo
) / sizeof(CHAR
),
164 applet
->info
[i
].szInfo
,
165 sizeof(applet
->info
[i
].szInfo
) / sizeof(WCHAR
));
166 MultiByteToWideChar(CP_ACP
, 0, ((LPNEWCPLINFOA
)&newinfo
)->szHelpFile
,
167 sizeof(((LPNEWCPLINFOA
)&newinfo
)->szHelpFile
) / sizeof(CHAR
),
168 applet
->info
[i
].szHelpFile
,
169 sizeof(applet
->info
[i
].szHelpFile
) / sizeof(WCHAR
));
174 applet
->next
= panel
->first
;
175 panel
->first
= applet
;
180 Control_UnloadApplet(applet
);
184 #define IDC_LISTVIEW 1000
185 #define IDC_STATUSBAR 1001
187 #define NUM_COLUMNS 2
188 #define LISTVIEW_DEFSTYLE (WS_CHILD | WS_VISIBLE | WS_TABSTOP |\
189 LVS_SORTASCENDING | LVS_AUTOARRANGE | LVS_SINGLESEL)
191 static BOOL
Control_CreateListView (CPanel
*panel
)
194 WCHAR empty_string
[] = {0};
195 WCHAR buf
[MAX_STRING_LEN
];
198 /* Create list view */
199 GetClientRect(panel
->hWndStatusBar
, &sb
);
200 GetClientRect(panel
->hWnd
, &ws
);
202 panel
->hWndListView
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_LISTVIEWW
,
203 empty_string
, LISTVIEW_DEFSTYLE
| LVS_ICON
,
204 0, 0, ws
.right
- ws
.left
, ws
.bottom
- ws
.top
-
205 (sb
.bottom
- sb
.top
), panel
->hWnd
,
206 (HMENU
) IDC_LISTVIEW
, panel
->hInst
, NULL
);
208 if (!panel
->hWndListView
)
211 /* Create image lists for list view */
212 panel
->hImageListSmall
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
),
213 GetSystemMetrics(SM_CYSMICON
), ILC_MASK
, 1, 1);
214 panel
->hImageListLarge
= ImageList_Create(GetSystemMetrics(SM_CXICON
),
215 GetSystemMetrics(SM_CYICON
), ILC_MASK
, 1, 1);
217 (void) ListView_SetImageList(panel
->hWndListView
, panel
->hImageListSmall
, LVSIL_SMALL
);
218 (void) ListView_SetImageList(panel
->hWndListView
, panel
->hImageListLarge
, LVSIL_NORMAL
);
220 /* Create columns for list view */
221 lvc
.mask
= LVCF_FMT
| LVCF_TEXT
| LVCF_SUBITEM
| LVCF_WIDTH
;
223 lvc
.fmt
= LVCFMT_LEFT
;
227 lvc
.cx
= (ws
.right
- ws
.left
) / 3;
228 LoadStringW(shell32_hInstance
, IDS_CPANEL_NAME
, buf
, sizeof(buf
) / sizeof(buf
[0]));
230 if (ListView_InsertColumnW(panel
->hWndListView
, 0, &lvc
) == -1)
233 /* Description column */
235 lvc
.cx
= ((ws
.right
- ws
.left
) / 3) * 2;
236 LoadStringW(shell32_hInstance
, IDS_CPANEL_DESCRIPTION
, buf
, sizeof(buf
) /
239 if (ListView_InsertColumnW(panel
->hWndListView
, 1, &lvc
) == -1)
245 static void Control_WndProc_Create(HWND hWnd
, const CREATESTRUCTW
* cs
)
247 CPanel
* panel
= cs
->lpCreateParams
;
248 HMENU hMenu
, hSubMenu
;
252 int menucount
, index
;
255 INITCOMMONCONTROLSEX icex
;
259 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)panel
);
262 /* Initialise common control DLL */
263 icex
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
264 icex
.dwICC
= ICC_LISTVIEW_CLASSES
| ICC_BAR_CLASSES
;
265 InitCommonControlsEx(&icex
);
267 /* create the status bar */
268 if (!(panel
->hWndStatusBar
= CreateStatusWindowW(WS_CHILD
| WS_VISIBLE
| CCS_BOTTOM
| SBARS_SIZEGRIP
, NULL
, hWnd
, IDC_STATUSBAR
)))
272 SendMessageW(panel
->hWndStatusBar
, SB_SETPARTS
, 1, (LPARAM
) &sb_parts
);
274 /* create the list view */
275 if (!Control_CreateListView(panel
))
278 hMenu
= LoadMenuW(shell32_hInstance
, MAKEINTRESOURCEW(MENU_CPANEL
));
280 /* insert menu items for applets */
281 hSubMenu
= GetSubMenu(hMenu
, 0);
284 for (applet
= panel
->first
; applet
; applet
= applet
->next
) {
285 for (i
= 0; i
< applet
->count
; i
++) {
286 if (!applet
->info
[i
].dwSize
)
289 /* set up a CPlItem for this particular subprogram */
290 item
= HeapAlloc(GetProcessHeap(), 0, sizeof(CPlItem
));
295 item
->applet
= applet
;
298 mii
.cbSize
= sizeof(MENUITEMINFOW
);
299 mii
.fMask
= MIIM_ID
| MIIM_STRING
| MIIM_DATA
;
300 mii
.dwTypeData
= applet
->info
[i
].szName
;
301 mii
.cch
= sizeof(applet
->info
[i
].szName
) / sizeof(applet
->info
[i
].szName
[0]);
302 mii
.wID
= IDM_CPANEL_APPLET_BASE
+ menucount
;
303 mii
.dwItemData
= (ULONG_PTR
)item
;
305 if (InsertMenuItemW(hSubMenu
, menucount
, TRUE
, &mii
)) {
306 /* add the list view item */
307 index
= ImageList_AddIcon(panel
->hImageListLarge
, applet
->info
[i
].hIcon
);
308 ImageList_AddIcon(panel
->hImageListSmall
, applet
->info
[i
].hIcon
);
310 lvItem
.mask
= LVIF_IMAGE
| LVIF_TEXT
| LVIF_PARAM
;
311 lvItem
.iItem
= menucount
;
313 lvItem
.pszText
= applet
->info
[i
].szName
;
314 lvItem
.iImage
= index
;
315 lvItem
.lParam
= (LPARAM
) item
;
317 itemidx
= ListView_InsertItemW(panel
->hWndListView
, &lvItem
);
319 /* add the description */
320 ListView_SetItemTextW(panel
->hWndListView
, itemidx
, 1,
321 applet
->info
[i
].szInfo
);
323 /* update menu bar, increment count */
330 panel
->total_subprogs
= menucount
;
332 /* check the "large items" icon in the View menu */
333 hSubMenu
= GetSubMenu(hMenu
, 1);
334 CheckMenuRadioItem(hSubMenu
, FCIDM_SHVIEW_BIGICON
, FCIDM_SHVIEW_REPORTVIEW
,
335 FCIDM_SHVIEW_BIGICON
, MF_BYCOMMAND
);
337 SetMenu(hWnd
, hMenu
);
340 static void Control_FreeCPlItems(HWND hWnd
, CPanel
*panel
)
342 HMENU hMenu
, hSubMenu
;
346 /* get the File menu */
347 hMenu
= GetMenu(hWnd
);
352 hSubMenu
= GetSubMenu(hMenu
, 0);
357 /* loop and free the item data */
358 for (i
= IDM_CPANEL_APPLET_BASE
; i
<= IDM_CPANEL_APPLET_BASE
+ panel
->total_subprogs
; i
++)
360 mii
.cbSize
= sizeof(MENUITEMINFOW
);
361 mii
.fMask
= MIIM_DATA
;
363 if (!GetMenuItemInfoW(hSubMenu
, i
, FALSE
, &mii
))
366 HeapFree(GetProcessHeap(), 0, (LPVOID
) mii
.dwItemData
);
370 static void Control_UpdateListViewStyle(CPanel
*panel
, UINT style
, UINT id
)
372 HMENU hMenu
, hSubMenu
;
374 SetWindowLongW(panel
->hWndListView
, GWL_STYLE
, LISTVIEW_DEFSTYLE
| style
);
376 /* update the menu */
377 hMenu
= GetMenu(panel
->hWnd
);
378 hSubMenu
= GetSubMenu(hMenu
, 1);
380 CheckMenuRadioItem(hSubMenu
, FCIDM_SHVIEW_BIGICON
, FCIDM_SHVIEW_REPORTVIEW
,
384 static CPlItem
* Control_GetCPlItem_From_MenuID(HWND hWnd
, UINT id
)
386 HMENU hMenu
, hSubMenu
;
389 /* retrieve the CPlItem structure from the menu item data */
390 hMenu
= GetMenu(hWnd
);
395 hSubMenu
= GetSubMenu(hMenu
, 0);
400 mii
.cbSize
= sizeof(MENUITEMINFOW
);
401 mii
.fMask
= MIIM_DATA
;
403 if (!GetMenuItemInfoW(hSubMenu
, id
, FALSE
, &mii
))
406 return (CPlItem
*) mii
.dwItemData
;
409 static CPlItem
* Control_GetCPlItem_From_ListView(CPanel
*panel
)
414 selitem
= SendMessageW(panel
->hWndListView
, LVM_GETNEXTITEM
, -1, LVNI_FOCUSED
419 lvItem
.iItem
= selitem
;
420 lvItem
.mask
= LVIF_PARAM
;
422 if (SendMessageW(panel
->hWndListView
, LVM_GETITEMW
, 0, (LPARAM
) &lvItem
))
423 return (CPlItem
*) lvItem
.lParam
;
429 static LRESULT WINAPI
Control_WndProc(HWND hWnd
, UINT wMsg
,
430 WPARAM lParam1
, LPARAM lParam2
)
432 CPanel
* panel
= (CPanel
*)GetWindowLongPtrW(hWnd
, 0);
434 if (panel
|| wMsg
== WM_CREATE
) {
437 Control_WndProc_Create(hWnd
, (CREATESTRUCTW
*)lParam2
);
441 CPlApplet
* applet
= panel
->first
;
443 applet
= Control_UnloadApplet(applet
);
445 Control_FreeCPlItems(hWnd
, panel
);
449 switch (LOWORD(lParam1
))
451 case IDM_CPANEL_EXIT
:
452 SendMessageW(hWnd
, WM_CLOSE
, 0, 0);
455 case IDM_CPANEL_ABOUT
:
457 WCHAR appName
[MAX_STRING_LEN
];
459 LoadStringW(shell32_hInstance
, IDS_CPANEL_TITLE
, appName
,
460 sizeof(appName
) / sizeof(appName
[0]));
461 ShellAboutW(hWnd
, appName
, NULL
, NULL
);
466 case FCIDM_SHVIEW_BIGICON
:
467 Control_UpdateListViewStyle(panel
, LVS_ICON
, FCIDM_SHVIEW_BIGICON
);
470 case FCIDM_SHVIEW_SMALLICON
:
471 Control_UpdateListViewStyle(panel
, LVS_SMALLICON
, FCIDM_SHVIEW_SMALLICON
);
474 case FCIDM_SHVIEW_LISTVIEW
:
475 Control_UpdateListViewStyle(panel
, LVS_LIST
, FCIDM_SHVIEW_LISTVIEW
);
478 case FCIDM_SHVIEW_REPORTVIEW
:
479 Control_UpdateListViewStyle(panel
, LVS_REPORT
, FCIDM_SHVIEW_REPORTVIEW
);
483 /* check if this is an applet */
484 if ((LOWORD(lParam1
) >= IDM_CPANEL_APPLET_BASE
) &&
485 (LOWORD(lParam1
) <= IDM_CPANEL_APPLET_BASE
+ panel
->total_subprogs
))
487 CPlItem
*item
= Control_GetCPlItem_From_MenuID(hWnd
, LOWORD(lParam1
));
489 /* execute the applet if item is valid */
491 item
->applet
->proc(item
->applet
->hWnd
, CPL_DBLCLK
, item
->id
,
492 item
->applet
->info
[item
->id
].lData
);
504 LPNMHDR nmh
= (LPNMHDR
) lParam2
;
514 CPlItem
*item
= Control_GetCPlItem_From_ListView(panel
);
516 /* execute the applet if item is valid */
518 item
->applet
->proc(item
->applet
->hWnd
, CPL_DBLCLK
,
519 item
->id
, item
->applet
->info
[item
->id
].lData
);
523 case LVN_ITEMCHANGED
:
525 CPlItem
*item
= Control_GetCPlItem_From_ListView(panel
);
527 /* update the status bar if item is valid */
529 SetWindowTextW(panel
->hWndStatusBar
,
530 item
->applet
->info
[item
->id
].szInfo
);
532 SetWindowTextW(panel
->hWndStatusBar
, NULL
);
545 /* check if this is an applet */
546 if ((LOWORD(lParam1
) >= IDM_CPANEL_APPLET_BASE
) &&
547 (LOWORD(lParam1
) <= IDM_CPANEL_APPLET_BASE
+ panel
->total_subprogs
))
549 CPlItem
*item
= Control_GetCPlItem_From_MenuID(hWnd
, LOWORD(lParam1
));
551 /* update the status bar if item is valid */
553 SetWindowTextW(panel
->hWndStatusBar
, item
->applet
->info
[item
->id
].szInfo
);
555 else if ((HIWORD(lParam1
) == 0xFFFF) && (lParam2
== 0))
557 /* reset status bar description to that of the selected icon */
558 CPlItem
*item
= Control_GetCPlItem_From_ListView(panel
);
561 SetWindowTextW(panel
->hWndStatusBar
, item
->applet
->info
[item
->id
].szInfo
);
563 SetWindowTextW(panel
->hWndStatusBar
, NULL
);
568 SetWindowTextW(panel
->hWndStatusBar
, NULL
);
577 hdwp
= BeginDeferWindowPos(2);
582 GetClientRect(panel
->hWndStatusBar
, &sb
);
584 hdwp
= DeferWindowPos(hdwp
, panel
->hWndListView
, NULL
, 0, 0,
585 LOWORD(lParam2
), HIWORD(lParam2
) - (sb
.bottom
- sb
.top
),
586 SWP_NOZORDER
| SWP_NOMOVE
);
591 hdwp
= DeferWindowPos(hdwp
, panel
->hWndStatusBar
, NULL
, 0, 0,
592 LOWORD(lParam2
), LOWORD(lParam1
), SWP_NOZORDER
| SWP_NOMOVE
);
595 EndDeferWindowPos(hdwp
);
602 return DefWindowProcW(hWnd
, wMsg
, lParam1
, lParam2
);
605 static void Control_DoInterface(CPanel
* panel
, HWND hWnd
, HINSTANCE hInst
)
609 WCHAR appName
[MAX_STRING_LEN
];
610 const WCHAR className
[] = {'S','h','e','l','l','_','C','o','n','t','r','o',
611 'l','_','W','n','d','C','l','a','s','s',0};
613 LoadStringW(shell32_hInstance
, IDS_CPANEL_TITLE
, appName
, sizeof(appName
) / sizeof(appName
[0]));
615 wc
.style
= CS_HREDRAW
|CS_VREDRAW
;
616 wc
.lpfnWndProc
= Control_WndProc
;
618 wc
.cbWndExtra
= sizeof(CPlApplet
*);
619 wc
.hInstance
= panel
->hInst
= hInst
;
621 wc
.hCursor
= LoadCursorW( 0, (LPWSTR
)IDC_ARROW
);
622 wc
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
623 wc
.lpszMenuName
= NULL
;
624 wc
.lpszClassName
= className
;
626 if (!RegisterClassW(&wc
)) return;
628 CreateWindowExW(0, wc
.lpszClassName
, appName
,
629 WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
630 CW_USEDEFAULT
, CW_USEDEFAULT
,
631 CW_USEDEFAULT
, CW_USEDEFAULT
,
632 hWnd
, NULL
, hInst
, panel
);
633 if (!panel
->hWnd
) return;
635 while (GetMessageW(&msg
, panel
->hWnd
, 0, 0)) {
636 TranslateMessage(&msg
);
637 DispatchMessageW(&msg
);
641 static void Control_RegisterRegistryApplets(HWND hWnd
, CPanel
*panel
, HKEY hkey_root
, LPCWSTR szRepPath
)
643 WCHAR name
[MAX_PATH
];
644 WCHAR value
[MAX_PATH
];
647 if (RegOpenKeyW(hkey_root
, szRepPath
, &hkey
) == ERROR_SUCCESS
)
653 DWORD nameLen
= MAX_PATH
;
654 DWORD valueLen
= MAX_PATH
;
656 if (RegEnumValueW(hkey
, idx
, name
, &nameLen
, NULL
, NULL
, (LPBYTE
)value
, &valueLen
) != ERROR_SUCCESS
)
659 Control_LoadApplet(hWnd
, value
, panel
);
665 static void Control_DoWindow(CPanel
* panel
, HWND hWnd
, HINSTANCE hInst
)
669 WCHAR buffer
[MAX_PATH
];
670 static const WCHAR wszAllCpl
[] = {'*','.','c','p','l',0};
671 static const WCHAR wszRegPath
[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t',
672 '\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
673 '\\','C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','C','p','l','s',0};
676 /* first add .cpl files in the system directory */
677 GetSystemDirectoryW( buffer
, MAX_PATH
);
678 p
= buffer
+ strlenW(buffer
);
680 lstrcpyW(p
, wszAllCpl
);
682 if ((h
= FindFirstFileW(buffer
, &fd
)) != INVALID_HANDLE_VALUE
) {
684 lstrcpyW(p
, fd
.cFileName
);
685 Control_LoadApplet(hWnd
, buffer
, panel
);
686 } while (FindNextFileW(h
, &fd
));
690 /* now check for cpls in the registry */
691 Control_RegisterRegistryApplets(hWnd
, panel
, HKEY_LOCAL_MACHINE
, wszRegPath
);
692 Control_RegisterRegistryApplets(hWnd
, panel
, HKEY_CURRENT_USER
, wszRegPath
);
694 Control_DoInterface(panel
, hWnd
, hInst
);
697 static void Control_DoLaunch(CPanel
* panel
, HWND hWnd
, LPCWSTR wszCmd
)
713 LPWSTR extraPmtsBuf
= NULL
;
714 LPWSTR extraPmts
= NULL
;
717 buffer
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(wszCmd
) + 1) * sizeof(*wszCmd
));
720 end
= lstrcpyW(buffer
, wszCmd
);
724 if (ch
== '"') quoted
= !quoted
;
725 if (!quoted
&& (ch
== ' ' || ch
== ',' || ch
== '\0')) {
730 } else if (*beg
== '\0') {
736 if (ch
== '\0') break;
738 if (ch
== ' ') while (end
[1] == ' ') end
++;
742 while ((ptr
= StrChrW(buffer
, '"')))
743 memmove(ptr
, ptr
+1, lstrlenW(ptr
)*sizeof(WCHAR
));
745 /* now check for any quotes in extraPmtsBuf and remove */
746 if (extraPmtsBuf
!= NULL
)
748 beg
= end
= extraPmtsBuf
;
753 if (ch
== '"') quoted
= !quoted
;
754 if (!quoted
&& (ch
== ' ' || ch
== ',' || ch
== '\0')) {
761 if (ch
== '\0') break;
763 if (ch
== ' ') while (end
[1] == ' ') end
++;
768 while ((ptr
= StrChrW(extraPmts
, '"')))
769 memmove(ptr
, ptr
+1, lstrlenW(ptr
)*sizeof(WCHAR
));
771 if (extraPmts
== NULL
)
772 extraPmts
= extraPmtsBuf
;
775 TRACE("cmd %s, extra %s, sp %d\n", debugstr_w(buffer
), debugstr_w(extraPmts
), sp
);
777 Control_LoadApplet(hWnd
, buffer
, panel
);
780 CPlApplet
* applet
= panel
->first
;
782 assert(applet
&& applet
->next
== NULL
);
784 /* we've been given a textual parameter (or none at all) */
786 while ((++sp
) != applet
->count
) {
787 if (applet
->info
[sp
].dwSize
) {
788 TRACE("sp %d, name %s\n", sp
, debugstr_w(applet
->info
[sp
].szName
));
790 if (StrCmpIW(extraPmts
, applet
->info
[sp
].szName
) == 0)
796 if (sp
>= applet
->count
) {
797 WARN("Out of bounds (%u >= %u), setting to 0\n", sp
, applet
->count
);
801 if (applet
->info
[sp
].dwSize
) {
802 if (!applet
->proc(applet
->hWnd
, CPL_STARTWPARMSA
, sp
, (LPARAM
)extraPmts
))
803 applet
->proc(applet
->hWnd
, CPL_DBLCLK
, sp
, applet
->info
[sp
].lData
);
806 Control_UnloadApplet(applet
);
809 HeapFree(GetProcessHeap(), 0, buffer
);
812 /*************************************************************************
813 * Control_RunDLLW [SHELL32.@]
816 void WINAPI
Control_RunDLLW(HWND hWnd
, HINSTANCE hInst
, LPCWSTR cmd
, DWORD nCmdShow
)
820 TRACE("(%p, %p, %s, 0x%08x)\n",
821 hWnd
, hInst
, debugstr_w(cmd
), nCmdShow
);
823 memset(&panel
, 0, sizeof(panel
));
826 Control_DoWindow(&panel
, hWnd
, hInst
);
828 Control_DoLaunch(&panel
, hWnd
, cmd
);
832 /*************************************************************************
833 * Control_RunDLLA [SHELL32.@]
836 void WINAPI
Control_RunDLLA(HWND hWnd
, HINSTANCE hInst
, LPCSTR cmd
, DWORD nCmdShow
)
838 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, cmd
, -1, NULL
, 0 );
839 LPWSTR wszCmd
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
840 if (wszCmd
&& MultiByteToWideChar(CP_ACP
, 0, cmd
, -1, wszCmd
, len
))
842 Control_RunDLLW(hWnd
, hInst
, wszCmd
, nCmdShow
);
844 HeapFree(GetProcessHeap(), 0, wszCmd
);
847 /*************************************************************************
848 * Control_FillCache_RunDLLW [SHELL32.@]
851 HRESULT WINAPI
Control_FillCache_RunDLLW(HWND hWnd
, HANDLE hModule
, DWORD w
, DWORD x
)
853 FIXME("%p %p 0x%08x 0x%08x stub\n", hWnd
, hModule
, w
, x
);
857 /*************************************************************************
858 * Control_FillCache_RunDLLA [SHELL32.@]
861 HRESULT WINAPI
Control_FillCache_RunDLLA(HWND hWnd
, HANDLE hModule
, DWORD w
, DWORD x
)
863 return Control_FillCache_RunDLLW(hWnd
, hModule
, w
, x
);
867 /*************************************************************************
868 * RunDLL_CallEntry16 [SHELL32.122]
869 * the name is probably wrong
871 void WINAPI
RunDLL_CallEntry16( DWORD proc
, HWND hwnd
, HINSTANCE inst
,
872 LPCSTR cmdline
, INT cmdshow
)
877 TRACE( "proc %x hwnd %p inst %p cmdline %s cmdshow %d\n",
878 proc
, hwnd
, inst
, debugstr_a(cmdline
), cmdshow
);
880 cmdline_seg
= MapLS( cmdline
);
881 args
[4] = HWND_16(hwnd
);
882 args
[3] = MapHModuleLS(inst
);
883 args
[2] = SELECTOROF(cmdline_seg
);
884 args
[1] = OFFSETOF(cmdline_seg
);
886 WOWCallback16Ex( proc
, WCB16_PASCAL
, sizeof(args
), args
, NULL
);
887 UnMapLS( cmdline_seg
);
890 /*************************************************************************
891 * CallCPLEntry16 [SHELL32.166]
893 * called by desk.cpl on "Advanced" with:
894 * hMod("DeskCp16.Dll"), pFunc("CplApplet"), 0, 1, 0xc, 0
897 DWORD WINAPI
CallCPLEntry16(HMODULE hMod
, FARPROC pFunc
, DWORD dw3
, DWORD dw4
, DWORD dw5
, DWORD dw6
)
899 FIXME("(%p, %p, %08x, %08x, %08x, %08x): stub.\n", hMod
, pFunc
, dw3
, dw4
, dw5
, dw6
);