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>
34 #include "wine/unicode.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(shlctrl
);
38 void Control_UnloadApplet(CPlApplet
* applet
)
42 for (i
= 0; i
< applet
->count
; i
++)
43 applet
->proc(applet
->hWnd
, CPL_STOP
, i
, applet
->info
[i
].data
);
45 if (applet
->proc
) applet
->proc(applet
->hWnd
, CPL_EXIT
, 0L, 0L);
46 FreeLibrary(applet
->hModule
);
48 list_remove( &applet
->entry
);
50 HeapFree(GetProcessHeap(), 0, applet
->cmd
);
51 HeapFree(GetProcessHeap(), 0, applet
);
54 CPlApplet
* Control_LoadApplet(HWND hWnd
, LPCWSTR cmd
, CPanel
* panel
)
62 if (!(applet
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*applet
))))
65 len
= ExpandEnvironmentStringsW(cmd
, NULL
, 0);
68 if (!(applet
->cmd
= HeapAlloc(GetProcessHeap(), 0, (len
+1) * sizeof(WCHAR
))))
70 WARN("Cannot allocate memory for applet path\n");
73 ExpandEnvironmentStringsW(cmd
, applet
->cmd
, len
+1);
77 WARN("Cannot expand applet path\n");
83 if (!(applet
->hModule
= LoadLibraryW(applet
->cmd
))) {
84 WARN("Cannot load control panel applet %s\n", debugstr_w(applet
->cmd
));
87 if (!(applet
->proc
= (APPLET_PROC
)GetProcAddress(applet
->hModule
, "CPlApplet"))) {
88 WARN("Not a valid control panel applet %s\n", debugstr_w(applet
->cmd
));
91 if (!applet
->proc(hWnd
, CPL_INIT
, 0L, 0L)) {
92 WARN("Init of applet has failed\n");
95 if ((applet
->count
= applet
->proc(hWnd
, CPL_GETCOUNT
, 0L, 0L)) == 0) {
96 WARN("No subprogram in applet\n");
97 applet
->proc(applet
->hWnd
, CPL_EXIT
, 0, 0);
101 applet
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, applet
,
102 FIELD_OFFSET( CPlApplet
, info
[applet
->count
] ));
104 for (i
= 0; i
< applet
->count
; i
++) {
105 ZeroMemory(&newinfo
, sizeof(newinfo
));
106 newinfo
.dwSize
= sizeof(NEWCPLINFOA
);
107 applet
->info
[i
].helpfile
[0] = 0;
108 /* proc is supposed to return a null value upon success for
109 * CPL_INQUIRE and CPL_NEWINQUIRE
110 * However, real drivers don't seem to behave like this
111 * So, use introspection rather than return value
113 applet
->proc(hWnd
, CPL_INQUIRE
, i
, (LPARAM
)&info
);
114 applet
->info
[i
].data
= info
.lData
;
116 applet
->info
[i
].idIcon
= info
.idIcon
;
119 if (info
.idIcon
!= CPL_DYNAMIC_RES
)
120 applet
->info
[i
].icon
= LoadIconW(applet
->hModule
, MAKEINTRESOURCEW(info
.idIcon
));
121 if (info
.idName
!= CPL_DYNAMIC_RES
)
122 LoadStringW(applet
->hModule
, info
.idName
,
123 applet
->info
[i
].name
, sizeof(applet
->info
[i
].name
) / sizeof(WCHAR
));
124 if (info
.idInfo
!= CPL_DYNAMIC_RES
)
125 LoadStringW(applet
->hModule
, info
.idInfo
,
126 applet
->info
[i
].info
, sizeof(applet
->info
[i
].info
) / 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
].name
[0]) info
.idName
= CPL_DYNAMIC_RES
;
134 /* zero-length szInfo may not be a buggy applet, but it doesn't hurt for us
137 if (!applet
->info
[i
].info
[0]) info
.idInfo
= CPL_DYNAMIC_RES
;
139 if (applet
->info
[i
].icon
== NULL
)
140 info
.idIcon
= CPL_DYNAMIC_RES
;
142 if ((info
.idIcon
== CPL_DYNAMIC_RES
) || (info
.idName
== CPL_DYNAMIC_RES
) ||
143 (info
.idInfo
== CPL_DYNAMIC_RES
)) {
144 applet
->proc(hWnd
, CPL_NEWINQUIRE
, i
, (LPARAM
)&newinfo
);
146 applet
->info
[i
].data
= newinfo
.lData
;
147 if (info
.idIcon
== CPL_DYNAMIC_RES
) {
148 if (!newinfo
.hIcon
) WARN("couldn't get icon for applet %u\n", i
);
149 applet
->info
[i
].icon
= newinfo
.hIcon
;
151 if (newinfo
.dwSize
== sizeof(NEWCPLINFOW
)) {
152 if (info
.idName
== CPL_DYNAMIC_RES
)
153 memcpy(applet
->info
[i
].name
, newinfo
.szName
, sizeof(newinfo
.szName
));
154 if (info
.idInfo
== CPL_DYNAMIC_RES
)
155 memcpy(applet
->info
[i
].info
, newinfo
.szInfo
, sizeof(newinfo
.szInfo
));
156 memcpy(applet
->info
[i
].helpfile
, newinfo
.szHelpFile
, sizeof(newinfo
.szHelpFile
));
158 if (info
.idName
== CPL_DYNAMIC_RES
)
159 MultiByteToWideChar(CP_ACP
, 0, ((LPNEWCPLINFOA
)&newinfo
)->szName
,
160 sizeof(((LPNEWCPLINFOA
)&newinfo
)->szName
) / sizeof(CHAR
),
161 applet
->info
[i
].name
, sizeof(applet
->info
[i
].name
) / sizeof(WCHAR
));
162 if (info
.idInfo
== CPL_DYNAMIC_RES
)
163 MultiByteToWideChar(CP_ACP
, 0, ((LPNEWCPLINFOA
)&newinfo
)->szInfo
,
164 sizeof(((LPNEWCPLINFOA
)&newinfo
)->szInfo
) / sizeof(CHAR
),
165 applet
->info
[i
].info
, sizeof(applet
->info
[i
].info
) / sizeof(WCHAR
));
166 MultiByteToWideChar(CP_ACP
, 0, ((LPNEWCPLINFOA
)&newinfo
)->szHelpFile
,
167 sizeof(((LPNEWCPLINFOA
)&newinfo
)->szHelpFile
) / sizeof(CHAR
),
168 applet
->info
[i
].helpfile
,
169 sizeof(applet
->info
[i
].helpfile
) / sizeof(WCHAR
));
175 list_add_head( &panel
->applets
, &applet
->entry
);
181 FreeLibrary(applet
->hModule
);
182 HeapFree(GetProcessHeap(), 0, applet
->cmd
);
183 HeapFree(GetProcessHeap(), 0, applet
);
189 #define IDC_LISTVIEW 1000
190 #define IDC_STATUSBAR 1001
192 #define NUM_COLUMNS 2
193 #define LISTVIEW_DEFSTYLE (WS_CHILD | WS_VISIBLE | WS_TABSTOP |\
194 LVS_SORTASCENDING | LVS_AUTOARRANGE | LVS_SINGLESEL)
196 static BOOL
Control_CreateListView (CPanel
*panel
)
199 WCHAR empty_string
[] = {0};
200 WCHAR buf
[MAX_STRING_LEN
];
203 /* Create list view */
204 GetClientRect(panel
->hWndStatusBar
, &sb
);
205 GetClientRect(panel
->hWnd
, &ws
);
207 panel
->hWndListView
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_LISTVIEWW
,
208 empty_string
, LISTVIEW_DEFSTYLE
| LVS_ICON
,
209 0, 0, ws
.right
- ws
.left
, ws
.bottom
- ws
.top
-
210 (sb
.bottom
- sb
.top
), panel
->hWnd
,
211 (HMENU
) IDC_LISTVIEW
, panel
->hInst
, NULL
);
213 if (!panel
->hWndListView
)
216 /* Create image lists for list view */
217 panel
->hImageListSmall
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
),
218 GetSystemMetrics(SM_CYSMICON
), ILC_COLOR32
| ILC_MASK
, 1, 1);
219 panel
->hImageListLarge
= ImageList_Create(GetSystemMetrics(SM_CXICON
),
220 GetSystemMetrics(SM_CYICON
), ILC_COLOR32
| ILC_MASK
, 1, 1);
222 SendMessageW(panel
->hWndListView
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)panel
->hImageListSmall
);
223 SendMessageW(panel
->hWndListView
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)panel
->hImageListLarge
);
225 /* Create columns for list view */
226 lvc
.mask
= LVCF_FMT
| LVCF_TEXT
| LVCF_SUBITEM
| LVCF_WIDTH
;
228 lvc
.fmt
= LVCFMT_LEFT
;
232 lvc
.cx
= (ws
.right
- ws
.left
) / 3;
233 LoadStringW(shell32_hInstance
, IDS_CPANEL_NAME
, buf
, sizeof(buf
) / sizeof(buf
[0]));
235 if (ListView_InsertColumnW(panel
->hWndListView
, 0, &lvc
) == -1)
238 /* Description column */
240 lvc
.cx
= ((ws
.right
- ws
.left
) / 3) * 2;
241 LoadStringW(shell32_hInstance
, IDS_CPANEL_DESCRIPTION
, buf
, sizeof(buf
) /
244 if (ListView_InsertColumnW(panel
->hWndListView
, 1, &lvc
) == -1)
250 static void Control_WndProc_Create(HWND hWnd
, const CREATESTRUCTW
* cs
)
252 CPanel
* panel
= cs
->lpCreateParams
;
253 HMENU hMenu
, hSubMenu
;
257 int menucount
, index
;
260 INITCOMMONCONTROLSEX icex
;
264 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)panel
);
267 /* Initialise common control DLL */
268 icex
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
269 icex
.dwICC
= ICC_LISTVIEW_CLASSES
| ICC_BAR_CLASSES
;
270 InitCommonControlsEx(&icex
);
272 /* create the status bar */
273 if (!(panel
->hWndStatusBar
= CreateStatusWindowW(WS_CHILD
| WS_VISIBLE
| CCS_BOTTOM
| SBARS_SIZEGRIP
, NULL
, hWnd
, IDC_STATUSBAR
)))
277 SendMessageW(panel
->hWndStatusBar
, SB_SETPARTS
, 1, (LPARAM
) &sb_parts
);
279 /* create the list view */
280 if (!Control_CreateListView(panel
))
283 hMenu
= LoadMenuW(shell32_hInstance
, MAKEINTRESOURCEW(MENU_CPANEL
));
285 /* insert menu items for applets */
286 hSubMenu
= GetSubMenu(hMenu
, 0);
289 LIST_FOR_EACH_ENTRY( applet
, &panel
->applets
, CPlApplet
, entry
)
291 for (i
= 0; i
< applet
->count
; i
++) {
292 /* set up a CPlItem for this particular subprogram */
293 item
= HeapAlloc(GetProcessHeap(), 0, sizeof(CPlItem
));
298 item
->applet
= applet
;
301 mii
.cbSize
= sizeof(MENUITEMINFOW
);
302 mii
.fMask
= MIIM_ID
| MIIM_STRING
| MIIM_DATA
;
303 mii
.dwTypeData
= applet
->info
[i
].name
;
304 mii
.cch
= sizeof(applet
->info
[i
].name
) / sizeof(WCHAR
);
305 mii
.wID
= IDM_CPANEL_APPLET_BASE
+ menucount
;
306 mii
.dwItemData
= (ULONG_PTR
)item
;
308 if (InsertMenuItemW(hSubMenu
, menucount
, TRUE
, &mii
)) {
309 /* add the list view item */
310 HICON icon
= applet
->info
[i
].icon
;
311 if (!icon
) icon
= LoadImageW( 0, (LPCWSTR
)IDI_WINLOGO
, IMAGE_ICON
, 0, 0, LR_SHARED
);
312 index
= ImageList_AddIcon(panel
->hImageListLarge
, icon
);
313 ImageList_AddIcon(panel
->hImageListSmall
, icon
);
315 lvItem
.mask
= LVIF_IMAGE
| LVIF_TEXT
| LVIF_PARAM
;
316 lvItem
.iItem
= menucount
;
318 lvItem
.pszText
= applet
->info
[i
].name
;
319 lvItem
.iImage
= index
;
320 lvItem
.lParam
= (LPARAM
) item
;
322 itemidx
= ListView_InsertItemW(panel
->hWndListView
, &lvItem
);
324 /* add the description */
325 ListView_SetItemTextW(panel
->hWndListView
, itemidx
, 1, applet
->info
[i
].info
);
327 /* update menu bar, increment count */
334 panel
->total_subprogs
= menucount
;
336 /* check the "large items" icon in the View menu */
337 hSubMenu
= GetSubMenu(hMenu
, 1);
338 CheckMenuRadioItem(hSubMenu
, FCIDM_SHVIEW_BIGICON
, FCIDM_SHVIEW_REPORTVIEW
,
339 FCIDM_SHVIEW_BIGICON
, MF_BYCOMMAND
);
341 SetMenu(hWnd
, hMenu
);
344 static void Control_FreeCPlItems(HWND hWnd
, CPanel
*panel
)
346 HMENU hMenu
, hSubMenu
;
350 /* get the File menu */
351 hMenu
= GetMenu(hWnd
);
356 hSubMenu
= GetSubMenu(hMenu
, 0);
361 /* loop and free the item data */
362 for (i
= IDM_CPANEL_APPLET_BASE
; i
<= IDM_CPANEL_APPLET_BASE
+ panel
->total_subprogs
; i
++)
364 mii
.cbSize
= sizeof(MENUITEMINFOW
);
365 mii
.fMask
= MIIM_DATA
;
367 if (!GetMenuItemInfoW(hSubMenu
, i
, FALSE
, &mii
))
370 HeapFree(GetProcessHeap(), 0, (LPVOID
) mii
.dwItemData
);
374 static void Control_UpdateListViewStyle(CPanel
*panel
, UINT style
, UINT id
)
376 HMENU hMenu
, hSubMenu
;
378 SetWindowLongW(panel
->hWndListView
, GWL_STYLE
, LISTVIEW_DEFSTYLE
| style
);
380 /* update the menu */
381 hMenu
= GetMenu(panel
->hWnd
);
382 hSubMenu
= GetSubMenu(hMenu
, 1);
384 CheckMenuRadioItem(hSubMenu
, FCIDM_SHVIEW_BIGICON
, FCIDM_SHVIEW_REPORTVIEW
,
388 static CPlItem
* Control_GetCPlItem_From_MenuID(HWND hWnd
, UINT id
)
390 HMENU hMenu
, hSubMenu
;
393 /* retrieve the CPlItem structure from the menu item data */
394 hMenu
= GetMenu(hWnd
);
399 hSubMenu
= GetSubMenu(hMenu
, 0);
404 mii
.cbSize
= sizeof(MENUITEMINFOW
);
405 mii
.fMask
= MIIM_DATA
;
407 if (!GetMenuItemInfoW(hSubMenu
, id
, FALSE
, &mii
))
410 return (CPlItem
*) mii
.dwItemData
;
413 static CPlItem
* Control_GetCPlItem_From_ListView(CPanel
*panel
)
418 selitem
= SendMessageW(panel
->hWndListView
, LVM_GETNEXTITEM
, -1, LVNI_FOCUSED
423 lvItem
.iItem
= selitem
;
424 lvItem
.mask
= LVIF_PARAM
;
426 if (SendMessageW(panel
->hWndListView
, LVM_GETITEMW
, 0, (LPARAM
) &lvItem
))
427 return (CPlItem
*) lvItem
.lParam
;
433 static void Control_StartApplet(HWND hWnd
, CPlItem
*item
)
435 WCHAR verbOpen
[] = {'c','p','l','o','p','e','n',0};
436 WCHAR format
[] = {'@','%','d',0};
437 WCHAR param
[MAX_PATH
];
439 /* execute the applet if item is valid */
442 wsprintfW(param
, format
, item
->id
);
443 ShellExecuteW(hWnd
, verbOpen
, item
->applet
->cmd
, param
, NULL
, SW_SHOW
);
447 static LRESULT WINAPI
Control_WndProc(HWND hWnd
, UINT wMsg
,
448 WPARAM lParam1
, LPARAM lParam2
)
450 CPanel
* panel
= (CPanel
*)GetWindowLongPtrW(hWnd
, 0);
452 if (panel
|| wMsg
== WM_CREATE
) {
455 Control_WndProc_Create(hWnd
, (CREATESTRUCTW
*)lParam2
);
459 CPlApplet
*applet
, *next
;
460 LIST_FOR_EACH_ENTRY_SAFE( applet
, next
, &panel
->applets
, CPlApplet
, entry
)
461 Control_UnloadApplet(applet
);
463 Control_FreeCPlItems(hWnd
, panel
);
467 switch (LOWORD(lParam1
))
469 case IDM_CPANEL_EXIT
:
470 SendMessageW(hWnd
, WM_CLOSE
, 0, 0);
473 case IDM_CPANEL_ABOUT
:
475 WCHAR appName
[MAX_STRING_LEN
];
476 HICON icon
= LoadImageW(shell32_hInstance
, MAKEINTRESOURCEW(IDI_SHELL_CONTROL_PANEL
),
477 IMAGE_ICON
, 48, 48, LR_SHARED
);
479 LoadStringW(shell32_hInstance
, IDS_CPANEL_TITLE
, appName
,
480 sizeof(appName
) / sizeof(appName
[0]));
481 ShellAboutW(hWnd
, appName
, NULL
, icon
);
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
, item
->applet
->info
[item
->id
].info
);
539 SetWindowTextW(panel
->hWndStatusBar
, NULL
);
552 /* check if this is an applet */
553 if ((LOWORD(lParam1
) >= IDM_CPANEL_APPLET_BASE
) &&
554 (LOWORD(lParam1
) <= IDM_CPANEL_APPLET_BASE
+ panel
->total_subprogs
))
556 CPlItem
*item
= Control_GetCPlItem_From_MenuID(hWnd
, LOWORD(lParam1
));
558 /* update the status bar if item is valid */
560 SetWindowTextW(panel
->hWndStatusBar
, item
->applet
->info
[item
->id
].info
);
562 else if ((HIWORD(lParam1
) == 0xFFFF) && (lParam2
== 0))
564 /* reset status bar description to that of the selected icon */
565 CPlItem
*item
= Control_GetCPlItem_From_ListView(panel
);
568 SetWindowTextW(panel
->hWndStatusBar
, item
->applet
->info
[item
->id
].info
);
570 SetWindowTextW(panel
->hWndStatusBar
, NULL
);
575 SetWindowTextW(panel
->hWndStatusBar
, NULL
);
584 hdwp
= BeginDeferWindowPos(2);
589 GetClientRect(panel
->hWndStatusBar
, &sb
);
591 hdwp
= DeferWindowPos(hdwp
, panel
->hWndListView
, NULL
, 0, 0,
592 LOWORD(lParam2
), HIWORD(lParam2
) - (sb
.bottom
- sb
.top
),
593 SWP_NOZORDER
| SWP_NOMOVE
);
598 hdwp
= DeferWindowPos(hdwp
, panel
->hWndStatusBar
, NULL
, 0, 0,
599 LOWORD(lParam2
), LOWORD(lParam1
), SWP_NOZORDER
| SWP_NOMOVE
);
602 EndDeferWindowPos(hdwp
);
609 return DefWindowProcW(hWnd
, wMsg
, lParam1
, lParam2
);
612 static void Control_DoInterface(CPanel
* panel
, HWND hWnd
, HINSTANCE hInst
)
616 WCHAR appName
[MAX_STRING_LEN
];
617 const WCHAR className
[] = {'S','h','e','l','l','_','C','o','n','t','r','o',
618 'l','_','W','n','d','C','l','a','s','s',0};
620 LoadStringW(shell32_hInstance
, IDS_CPANEL_TITLE
, appName
, sizeof(appName
) / sizeof(appName
[0]));
622 wc
.cbSize
= sizeof(wc
);
623 wc
.style
= CS_HREDRAW
|CS_VREDRAW
;
624 wc
.lpfnWndProc
= Control_WndProc
;
626 wc
.cbWndExtra
= sizeof(CPlApplet
*);
627 wc
.hInstance
= panel
->hInst
= hInst
;
628 wc
.hIcon
= LoadIconW( shell32_hInstance
, MAKEINTRESOURCEW(IDI_SHELL_CONTROL_PANEL
) );
629 wc
.hCursor
= LoadCursorW( 0, (LPWSTR
)IDC_ARROW
);
630 wc
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
631 wc
.lpszMenuName
= NULL
;
632 wc
.lpszClassName
= className
;
633 wc
.hIconSm
= LoadImageW( shell32_hInstance
, MAKEINTRESOURCEW(IDI_SHELL_CONTROL_PANEL
), IMAGE_ICON
,
634 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
636 if (!RegisterClassExW(&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
);
708 static void Control_DoWindow(CPanel
* panel
, HWND hWnd
, HINSTANCE hInst
)
713 L
"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}",
719 static void Control_DoLaunch(CPanel
* panel
, HWND hWnd
, LPCWSTR wszCmd
)
735 LPWSTR extraPmtsBuf
= NULL
;
736 LPWSTR extraPmts
= NULL
;
740 buffer
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(wszCmd
) + 1) * sizeof(*wszCmd
));
743 end
= lstrcpyW(buffer
, wszCmd
);
747 if (ch
== '"') quoted
= !quoted
;
748 if (!quoted
&& (ch
== ' ' || ch
== ',' || ch
== '\0')) {
753 } else if (*beg
== '\0') {
759 if (ch
== '\0') break;
761 if (ch
== ' ') while (end
[1] == ' ') end
++;
765 while ((ptr
= StrChrW(buffer
, '"')))
766 memmove(ptr
, ptr
+1, lstrlenW(ptr
)*sizeof(WCHAR
));
768 /* now check for any quotes in extraPmtsBuf and remove */
769 if (extraPmtsBuf
!= NULL
)
771 beg
= end
= extraPmtsBuf
;
776 if (ch
== '"') quoted
= !quoted
;
777 if (!quoted
&& (ch
== ' ' || ch
== ',' || ch
== '\0')) {
784 if (ch
== '\0') break;
786 if (ch
== ' ') while (end
[1] == ' ') end
++;
791 while ((ptr
= StrChrW(extraPmts
, '"')))
792 memmove(ptr
, ptr
+1, lstrlenW(ptr
)*sizeof(WCHAR
));
794 if (extraPmts
== NULL
)
795 extraPmts
= extraPmtsBuf
;
798 /* Now check if there had been a numerical value in the extra params */
799 if ((extraPmts
) && (*extraPmts
== '@') && (sp
== -1)) {
800 sp
= atoiW(extraPmts
+ 1);
803 TRACE("cmd %s, extra %s, sp %d\n", debugstr_w(buffer
), debugstr_w(extraPmts
), sp
);
805 applet
= Control_LoadApplet(hWnd
, buffer
, panel
);
808 /* we've been given a textual parameter (or none at all) */
810 while ((++sp
) != applet
->count
) {
811 TRACE("sp %d, name %s\n", sp
, debugstr_w(applet
->info
[sp
].name
));
813 if (StrCmpIW(extraPmts
, applet
->info
[sp
].name
) == 0)
818 if (sp
>= applet
->count
) {
819 WARN("Out of bounds (%u >= %u), setting to 0\n", sp
, applet
->count
);
823 if (!applet
->proc(applet
->hWnd
, CPL_STARTWPARMSW
, sp
, (LPARAM
)extraPmts
))
824 applet
->proc(applet
->hWnd
, CPL_DBLCLK
, sp
, applet
->info
[sp
].data
);
826 Control_UnloadApplet(applet
);
829 HeapFree(GetProcessHeap(), 0, buffer
);
832 /*************************************************************************
833 * Control_RunDLLW [SHELL32.@]
836 void WINAPI
Control_RunDLLW(HWND hWnd
, HINSTANCE hInst
, LPCWSTR cmd
, DWORD nCmdShow
)
840 TRACE("(%p, %p, %s, 0x%08x)\n",
841 hWnd
, hInst
, debugstr_w(cmd
), nCmdShow
);
844 memset(&panel
, 0, sizeof(panel
));
845 list_init( &panel
.applets
);
849 Control_DoWindow(&panel
, hWnd
, hInst
);
851 Control_DoLaunch(&panel
, hWnd
, cmd
);
855 /*************************************************************************
856 * Control_RunDLLA [SHELL32.@]
859 void WINAPI
Control_RunDLLA(HWND hWnd
, HINSTANCE hInst
, LPCSTR cmd
, DWORD nCmdShow
)
861 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, cmd
, -1, NULL
, 0 );
862 LPWSTR wszCmd
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
863 if (wszCmd
&& MultiByteToWideChar(CP_ACP
, 0, cmd
, -1, wszCmd
, len
))
865 Control_RunDLLW(hWnd
, hInst
, wszCmd
, nCmdShow
);
867 HeapFree(GetProcessHeap(), 0, wszCmd
);
870 /*************************************************************************
871 * Control_FillCache_RunDLLW [SHELL32.@]
874 HRESULT WINAPI
Control_FillCache_RunDLLW(HWND hWnd
, HANDLE hModule
, DWORD w
, DWORD x
)
876 FIXME("%p %p 0x%08x 0x%08x stub\n", hWnd
, hModule
, w
, x
);
880 /*************************************************************************
881 * Control_FillCache_RunDLLA [SHELL32.@]
884 HRESULT WINAPI
Control_FillCache_RunDLLA(HWND hWnd
, HANDLE hModule
, DWORD w
, DWORD x
)
886 return Control_FillCache_RunDLLW(hWnd
, hModule
, w
, x
);
891 /*************************************************************************
892 * RunDll_CallEntry16 [SHELL32.122]
893 * the name is OK (when written with Dll, and not DLL as in Wine!)
895 void WINAPI
RunDll_CallEntry16( DWORD proc
, HWND hwnd
, HINSTANCE inst
,
896 LPCSTR cmdline
, INT cmdshow
)
898 FIXME( "proc %lx hwnd %p inst %p cmdline %s cmdshow %d\n",
899 proc
, hwnd
, inst
, debugstr_a(cmdline
), cmdshow
);
903 /*************************************************************************
904 * CallCPLEntry16 [SHELL32.166]
906 * called by desk.cpl on "Advanced" with:
907 * hMod("DeskCp16.Dll"), pFunc("CplApplet"), 0, 1, 0xc, 0
910 DWORD WINAPI
CallCPLEntry16(HMODULE hMod
, FARPROC pFunc
, DWORD dw3
, DWORD dw4
, DWORD dw5
, DWORD dw6
)
912 FIXME("(%p, %p, %08x, %08x, %08x, %08x): stub.\n", hMod
, pFunc
, dw3
, dw4
, dw5
, dw6
);