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 void Control_UnloadApplet(CPlApplet
* applet
)
52 for (i
= 0; i
< applet
->count
; i
++)
53 applet
->proc(applet
->hWnd
, CPL_STOP
, i
, applet
->info
[i
].data
);
55 if (applet
->proc
) applet
->proc(applet
->hWnd
, CPL_EXIT
, 0L, 0L);
56 FreeLibrary(applet
->hModule
);
57 list_remove( &applet
->entry
);
58 HeapFree(GetProcessHeap(), 0, applet
->cmd
);
59 HeapFree(GetProcessHeap(), 0, applet
);
62 CPlApplet
* Control_LoadApplet(HWND hWnd
, LPCWSTR cmd
, CPanel
* panel
)
70 if (!(applet
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*applet
))))
73 len
= ExpandEnvironmentStringsW(cmd
, NULL
, 0);
76 if (!(applet
->cmd
= HeapAlloc(GetProcessHeap(), 0, (len
+1) * sizeof(WCHAR
))))
78 WARN("Cannot allocate memory for applet path\n");
81 ExpandEnvironmentStringsW(cmd
, applet
->cmd
, len
+1);
85 WARN("Cannot expand applet path\n");
91 if (!(applet
->hModule
= LoadLibraryW(applet
->cmd
))) {
92 WARN("Cannot load control panel applet %s\n", debugstr_w(applet
->cmd
));
95 if (!(applet
->proc
= (APPLET_PROC
)GetProcAddress(applet
->hModule
, "CPlApplet"))) {
96 WARN("Not a valid control panel applet %s\n", debugstr_w(applet
->cmd
));
99 if (!applet
->proc(hWnd
, CPL_INIT
, 0L, 0L)) {
100 WARN("Init of applet has failed\n");
103 if ((applet
->count
= applet
->proc(hWnd
, CPL_GETCOUNT
, 0L, 0L)) == 0) {
104 WARN("No subprogram in applet\n");
105 applet
->proc(applet
->hWnd
, CPL_EXIT
, 0, 0);
109 applet
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, applet
,
110 FIELD_OFFSET( CPlApplet
, info
[applet
->count
] ));
112 for (i
= 0; i
< applet
->count
; i
++) {
113 ZeroMemory(&newinfo
, sizeof(newinfo
));
114 newinfo
.dwSize
= sizeof(NEWCPLINFOA
);
115 applet
->info
[i
].helpfile
[0] = 0;
116 /* proc is supposed to return a null value upon success for
117 * CPL_INQUIRE and CPL_NEWINQUIRE
118 * However, real drivers don't seem to behave like this
119 * So, use introspection rather than return value
121 applet
->proc(hWnd
, CPL_INQUIRE
, i
, (LPARAM
)&info
);
122 applet
->info
[i
].data
= info
.lData
;
123 if (info
.idIcon
!= CPL_DYNAMIC_RES
)
124 applet
->info
[i
].icon
= LoadIconW(applet
->hModule
, MAKEINTRESOURCEW(info
.idIcon
));
125 if (info
.idName
!= CPL_DYNAMIC_RES
)
126 LoadStringW(applet
->hModule
, info
.idName
,
127 applet
->info
[i
].name
, sizeof(applet
->info
[i
].name
) / sizeof(WCHAR
));
128 if (info
.idInfo
!= CPL_DYNAMIC_RES
)
129 LoadStringW(applet
->hModule
, info
.idInfo
,
130 applet
->info
[i
].info
, sizeof(applet
->info
[i
].info
) / sizeof(WCHAR
));
132 /* some broken control panels seem to return incorrect values in CPL_INQUIRE,
133 but proper data in CPL_NEWINQUIRE. if we get an empty string or a null
134 icon, see what we can get from CPL_NEWINQUIRE */
136 if (!applet
->info
[i
].name
[0]) info
.idName
= CPL_DYNAMIC_RES
;
138 /* zero-length szInfo may not be a buggy applet, but it doesn't hurt for us
141 if (!applet
->info
[i
].info
[0]) info
.idInfo
= CPL_DYNAMIC_RES
;
143 if (applet
->info
[i
].icon
== 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
].data
= 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
].icon
= newinfo
.hIcon
;
155 if (newinfo
.dwSize
== sizeof(NEWCPLINFOW
)) {
156 if (info
.idName
== CPL_DYNAMIC_RES
)
157 memcpy(applet
->info
[i
].name
, newinfo
.szName
, sizeof(newinfo
.szName
));
158 if (info
.idInfo
== CPL_DYNAMIC_RES
)
159 memcpy(applet
->info
[i
].info
, newinfo
.szInfo
, sizeof(newinfo
.szInfo
));
160 memcpy(applet
->info
[i
].helpfile
, 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
].name
, sizeof(applet
->info
[i
].name
) / sizeof(WCHAR
));
166 if (info
.idInfo
== CPL_DYNAMIC_RES
)
167 MultiByteToWideChar(CP_ACP
, 0, ((LPNEWCPLINFOA
)&newinfo
)->szInfo
,
168 sizeof(((LPNEWCPLINFOA
)&newinfo
)->szInfo
) / sizeof(CHAR
),
169 applet
->info
[i
].info
, sizeof(applet
->info
[i
].info
) / sizeof(WCHAR
));
170 MultiByteToWideChar(CP_ACP
, 0, ((LPNEWCPLINFOA
)&newinfo
)->szHelpFile
,
171 sizeof(((LPNEWCPLINFOA
)&newinfo
)->szHelpFile
) / sizeof(CHAR
),
172 applet
->info
[i
].helpfile
,
173 sizeof(applet
->info
[i
].helpfile
) / sizeof(WCHAR
));
178 list_add_head( &panel
->applets
, &applet
->entry
);
182 FreeLibrary(applet
->hModule
);
183 HeapFree(GetProcessHeap(), 0, applet
->cmd
);
184 HeapFree(GetProcessHeap(), 0, applet
);
188 #define IDC_LISTVIEW 1000
189 #define IDC_STATUSBAR 1001
191 #define NUM_COLUMNS 2
192 #define LISTVIEW_DEFSTYLE (WS_CHILD | WS_VISIBLE | WS_TABSTOP |\
193 LVS_SORTASCENDING | LVS_AUTOARRANGE | LVS_SINGLESEL)
195 static BOOL
Control_CreateListView (CPanel
*panel
)
198 WCHAR empty_string
[] = {0};
199 WCHAR buf
[MAX_STRING_LEN
];
202 /* Create list view */
203 GetClientRect(panel
->hWndStatusBar
, &sb
);
204 GetClientRect(panel
->hWnd
, &ws
);
206 panel
->hWndListView
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_LISTVIEWW
,
207 empty_string
, LISTVIEW_DEFSTYLE
| LVS_ICON
,
208 0, 0, ws
.right
- ws
.left
, ws
.bottom
- ws
.top
-
209 (sb
.bottom
- sb
.top
), panel
->hWnd
,
210 (HMENU
) IDC_LISTVIEW
, panel
->hInst
, NULL
);
212 if (!panel
->hWndListView
)
215 /* Create image lists for list view */
216 panel
->hImageListSmall
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
),
217 GetSystemMetrics(SM_CYSMICON
), ILC_COLOR32
| ILC_MASK
, 1, 1);
218 panel
->hImageListLarge
= ImageList_Create(GetSystemMetrics(SM_CXICON
),
219 GetSystemMetrics(SM_CYICON
), ILC_COLOR32
| ILC_MASK
, 1, 1);
221 SendMessageW(panel
->hWndListView
, LVM_SETIMAGELIST
, LVSIL_SMALL
, (LPARAM
)panel
->hImageListSmall
);
222 SendMessageW(panel
->hWndListView
, LVM_SETIMAGELIST
, LVSIL_NORMAL
, (LPARAM
)panel
->hImageListLarge
);
224 /* Create columns for list view */
225 lvc
.mask
= LVCF_FMT
| LVCF_TEXT
| LVCF_SUBITEM
| LVCF_WIDTH
;
227 lvc
.fmt
= LVCFMT_LEFT
;
231 lvc
.cx
= (ws
.right
- ws
.left
) / 3;
232 LoadStringW(shell32_hInstance
, IDS_CPANEL_NAME
, buf
, sizeof(buf
) / sizeof(buf
[0]));
234 if (ListView_InsertColumnW(panel
->hWndListView
, 0, &lvc
) == -1)
237 /* Description column */
239 lvc
.cx
= ((ws
.right
- ws
.left
) / 3) * 2;
240 LoadStringW(shell32_hInstance
, IDS_CPANEL_DESCRIPTION
, buf
, sizeof(buf
) /
243 if (ListView_InsertColumnW(panel
->hWndListView
, 1, &lvc
) == -1)
249 static void Control_WndProc_Create(HWND hWnd
, const CREATESTRUCTW
* cs
)
251 CPanel
* panel
= cs
->lpCreateParams
;
252 HMENU hMenu
, hSubMenu
;
256 int menucount
, index
;
259 INITCOMMONCONTROLSEX icex
;
263 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)panel
);
266 /* Initialise common control DLL */
267 icex
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
268 icex
.dwICC
= ICC_LISTVIEW_CLASSES
| ICC_BAR_CLASSES
;
269 InitCommonControlsEx(&icex
);
271 /* create the status bar */
272 if (!(panel
->hWndStatusBar
= CreateStatusWindowW(WS_CHILD
| WS_VISIBLE
| CCS_BOTTOM
| SBARS_SIZEGRIP
, NULL
, hWnd
, IDC_STATUSBAR
)))
276 SendMessageW(panel
->hWndStatusBar
, SB_SETPARTS
, 1, (LPARAM
) &sb_parts
);
278 /* create the list view */
279 if (!Control_CreateListView(panel
))
282 hMenu
= LoadMenuW(shell32_hInstance
, MAKEINTRESOURCEW(MENU_CPANEL
));
284 /* insert menu items for applets */
285 hSubMenu
= GetSubMenu(hMenu
, 0);
288 LIST_FOR_EACH_ENTRY( applet
, &panel
->applets
, CPlApplet
, entry
)
290 for (i
= 0; i
< applet
->count
; i
++) {
291 /* set up a CPlItem for this particular subprogram */
292 item
= HeapAlloc(GetProcessHeap(), 0, sizeof(CPlItem
));
297 item
->applet
= applet
;
300 mii
.cbSize
= sizeof(MENUITEMINFOW
);
301 mii
.fMask
= MIIM_ID
| MIIM_STRING
| MIIM_DATA
;
302 mii
.dwTypeData
= applet
->info
[i
].name
;
303 mii
.cch
= sizeof(applet
->info
[i
].name
) / sizeof(WCHAR
);
304 mii
.wID
= IDM_CPANEL_APPLET_BASE
+ menucount
;
305 mii
.dwItemData
= (ULONG_PTR
)item
;
307 if (InsertMenuItemW(hSubMenu
, menucount
, TRUE
, &mii
)) {
308 /* add the list view item */
309 HICON icon
= applet
->info
[i
].icon
;
310 if (!icon
) icon
= LoadImageW( 0, (LPCWSTR
)IDI_WINLOGO
, IMAGE_ICON
, 0, 0, LR_SHARED
);
311 index
= ImageList_AddIcon(panel
->hImageListLarge
, icon
);
312 ImageList_AddIcon(panel
->hImageListSmall
, icon
);
314 lvItem
.mask
= LVIF_IMAGE
| LVIF_TEXT
| LVIF_PARAM
;
315 lvItem
.iItem
= menucount
;
317 lvItem
.pszText
= applet
->info
[i
].name
;
318 lvItem
.iImage
= index
;
319 lvItem
.lParam
= (LPARAM
) item
;
321 itemidx
= ListView_InsertItemW(panel
->hWndListView
, &lvItem
);
323 /* add the description */
324 ListView_SetItemTextW(panel
->hWndListView
, itemidx
, 1, applet
->info
[i
].info
);
326 /* update menu bar, increment count */
333 panel
->total_subprogs
= menucount
;
335 /* check the "large items" icon in the View menu */
336 hSubMenu
= GetSubMenu(hMenu
, 1);
337 CheckMenuRadioItem(hSubMenu
, FCIDM_SHVIEW_BIGICON
, FCIDM_SHVIEW_REPORTVIEW
,
338 FCIDM_SHVIEW_BIGICON
, MF_BYCOMMAND
);
340 SetMenu(hWnd
, hMenu
);
343 static void Control_FreeCPlItems(HWND hWnd
, CPanel
*panel
)
345 HMENU hMenu
, hSubMenu
;
349 /* get the File menu */
350 hMenu
= GetMenu(hWnd
);
355 hSubMenu
= GetSubMenu(hMenu
, 0);
360 /* loop and free the item data */
361 for (i
= IDM_CPANEL_APPLET_BASE
; i
<= IDM_CPANEL_APPLET_BASE
+ panel
->total_subprogs
; i
++)
363 mii
.cbSize
= sizeof(MENUITEMINFOW
);
364 mii
.fMask
= MIIM_DATA
;
366 if (!GetMenuItemInfoW(hSubMenu
, i
, FALSE
, &mii
))
369 HeapFree(GetProcessHeap(), 0, (LPVOID
) mii
.dwItemData
);
373 static void Control_UpdateListViewStyle(CPanel
*panel
, UINT style
, UINT id
)
375 HMENU hMenu
, hSubMenu
;
377 SetWindowLongW(panel
->hWndListView
, GWL_STYLE
, LISTVIEW_DEFSTYLE
| style
);
379 /* update the menu */
380 hMenu
= GetMenu(panel
->hWnd
);
381 hSubMenu
= GetSubMenu(hMenu
, 1);
383 CheckMenuRadioItem(hSubMenu
, FCIDM_SHVIEW_BIGICON
, FCIDM_SHVIEW_REPORTVIEW
,
387 static CPlItem
* Control_GetCPlItem_From_MenuID(HWND hWnd
, UINT id
)
389 HMENU hMenu
, hSubMenu
;
392 /* retrieve the CPlItem structure from the menu item data */
393 hMenu
= GetMenu(hWnd
);
398 hSubMenu
= GetSubMenu(hMenu
, 0);
403 mii
.cbSize
= sizeof(MENUITEMINFOW
);
404 mii
.fMask
= MIIM_DATA
;
406 if (!GetMenuItemInfoW(hSubMenu
, id
, FALSE
, &mii
))
409 return (CPlItem
*) mii
.dwItemData
;
412 static CPlItem
* Control_GetCPlItem_From_ListView(CPanel
*panel
)
417 selitem
= SendMessageW(panel
->hWndListView
, LVM_GETNEXTITEM
, -1, LVNI_FOCUSED
422 lvItem
.iItem
= selitem
;
423 lvItem
.mask
= LVIF_PARAM
;
425 if (SendMessageW(panel
->hWndListView
, LVM_GETITEMW
, 0, (LPARAM
) &lvItem
))
426 return (CPlItem
*) lvItem
.lParam
;
432 static void Control_StartApplet(HWND hWnd
, CPlItem
*item
)
434 WCHAR verbOpen
[] = {'c','p','l','o','p','e','n',0};
435 WCHAR format
[] = {'@','%','d',0};
436 WCHAR param
[MAX_PATH
];
438 /* execute the applet if item is valid */
441 wsprintfW(param
, format
, item
->id
);
442 ShellExecuteW(hWnd
, verbOpen
, item
->applet
->cmd
, param
, NULL
, SW_SHOW
);
446 static LRESULT WINAPI
Control_WndProc(HWND hWnd
, UINT wMsg
,
447 WPARAM lParam1
, LPARAM lParam2
)
449 CPanel
* panel
= (CPanel
*)GetWindowLongPtrW(hWnd
, 0);
451 if (panel
|| wMsg
== WM_CREATE
) {
454 Control_WndProc_Create(hWnd
, (CREATESTRUCTW
*)lParam2
);
458 CPlApplet
*applet
, *next
;
459 LIST_FOR_EACH_ENTRY_SAFE( applet
, next
, &panel
->applets
, CPlApplet
, entry
)
460 Control_UnloadApplet(applet
);
462 Control_FreeCPlItems(hWnd
, panel
);
466 switch (LOWORD(lParam1
))
468 case IDM_CPANEL_EXIT
:
469 SendMessageW(hWnd
, WM_CLOSE
, 0, 0);
472 case IDM_CPANEL_ABOUT
:
474 WCHAR appName
[MAX_STRING_LEN
];
475 HICON icon
= LoadImageW(shell32_hInstance
, MAKEINTRESOURCEW(IDI_SHELL_CONTROL_PANEL
),
476 IMAGE_ICON
, 48, 48, LR_SHARED
);
478 LoadStringW(shell32_hInstance
, IDS_CPANEL_TITLE
, appName
,
479 sizeof(appName
) / sizeof(appName
[0]));
480 ShellAboutW(hWnd
, appName
, NULL
, icon
);
485 case FCIDM_SHVIEW_BIGICON
:
486 Control_UpdateListViewStyle(panel
, LVS_ICON
, FCIDM_SHVIEW_BIGICON
);
489 case FCIDM_SHVIEW_SMALLICON
:
490 Control_UpdateListViewStyle(panel
, LVS_SMALLICON
, FCIDM_SHVIEW_SMALLICON
);
493 case FCIDM_SHVIEW_LISTVIEW
:
494 Control_UpdateListViewStyle(panel
, LVS_LIST
, FCIDM_SHVIEW_LISTVIEW
);
497 case FCIDM_SHVIEW_REPORTVIEW
:
498 Control_UpdateListViewStyle(panel
, LVS_REPORT
, FCIDM_SHVIEW_REPORTVIEW
);
502 /* check if this is an applet */
503 if ((LOWORD(lParam1
) >= IDM_CPANEL_APPLET_BASE
) &&
504 (LOWORD(lParam1
) <= IDM_CPANEL_APPLET_BASE
+ panel
->total_subprogs
))
506 Control_StartApplet(hWnd
, Control_GetCPlItem_From_MenuID(hWnd
, LOWORD(lParam1
)));
517 LPNMHDR nmh
= (LPNMHDR
) lParam2
;
527 Control_StartApplet(hWnd
, Control_GetCPlItem_From_ListView(panel
));
530 case LVN_ITEMCHANGED
:
532 CPlItem
*item
= Control_GetCPlItem_From_ListView(panel
);
534 /* update the status bar if item is valid */
536 SetWindowTextW(panel
->hWndStatusBar
, item
->applet
->info
[item
->id
].info
);
538 SetWindowTextW(panel
->hWndStatusBar
, NULL
);
551 /* check if this is an applet */
552 if ((LOWORD(lParam1
) >= IDM_CPANEL_APPLET_BASE
) &&
553 (LOWORD(lParam1
) <= IDM_CPANEL_APPLET_BASE
+ panel
->total_subprogs
))
555 CPlItem
*item
= Control_GetCPlItem_From_MenuID(hWnd
, LOWORD(lParam1
));
557 /* update the status bar if item is valid */
559 SetWindowTextW(panel
->hWndStatusBar
, item
->applet
->info
[item
->id
].info
);
561 else if ((HIWORD(lParam1
) == 0xFFFF) && (lParam2
== 0))
563 /* reset status bar description to that of the selected icon */
564 CPlItem
*item
= Control_GetCPlItem_From_ListView(panel
);
567 SetWindowTextW(panel
->hWndStatusBar
, item
->applet
->info
[item
->id
].info
);
569 SetWindowTextW(panel
->hWndStatusBar
, NULL
);
574 SetWindowTextW(panel
->hWndStatusBar
, NULL
);
583 hdwp
= BeginDeferWindowPos(2);
588 GetClientRect(panel
->hWndStatusBar
, &sb
);
590 hdwp
= DeferWindowPos(hdwp
, panel
->hWndListView
, NULL
, 0, 0,
591 LOWORD(lParam2
), HIWORD(lParam2
) - (sb
.bottom
- sb
.top
),
592 SWP_NOZORDER
| SWP_NOMOVE
);
597 hdwp
= DeferWindowPos(hdwp
, panel
->hWndStatusBar
, NULL
, 0, 0,
598 LOWORD(lParam2
), LOWORD(lParam1
), SWP_NOZORDER
| SWP_NOMOVE
);
601 EndDeferWindowPos(hdwp
);
608 return DefWindowProcW(hWnd
, wMsg
, lParam1
, lParam2
);
611 static void Control_DoInterface(CPanel
* panel
, HWND hWnd
, HINSTANCE hInst
)
615 WCHAR appName
[MAX_STRING_LEN
];
616 const WCHAR className
[] = {'S','h','e','l','l','_','C','o','n','t','r','o',
617 'l','_','W','n','d','C','l','a','s','s',0};
619 LoadStringW(shell32_hInstance
, IDS_CPANEL_TITLE
, appName
, sizeof(appName
) / sizeof(appName
[0]));
621 wc
.cbSize
= sizeof(wc
);
622 wc
.style
= CS_HREDRAW
|CS_VREDRAW
;
623 wc
.lpfnWndProc
= Control_WndProc
;
625 wc
.cbWndExtra
= sizeof(CPlApplet
*);
626 wc
.hInstance
= panel
->hInst
= hInst
;
627 wc
.hIcon
= LoadIconW( shell32_hInstance
, MAKEINTRESOURCEW(IDI_SHELL_CONTROL_PANEL
) );
628 wc
.hCursor
= LoadCursorW( 0, (LPWSTR
)IDC_ARROW
);
629 wc
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
630 wc
.lpszMenuName
= NULL
;
631 wc
.lpszClassName
= className
;
632 wc
.hIconSm
= LoadImageW( shell32_hInstance
, MAKEINTRESOURCEW(IDI_SHELL_CONTROL_PANEL
), IMAGE_ICON
,
633 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
635 if (!RegisterClassExW(&wc
)) return;
637 CreateWindowExW(0, wc
.lpszClassName
, appName
,
638 WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
639 CW_USEDEFAULT
, CW_USEDEFAULT
,
640 CW_USEDEFAULT
, CW_USEDEFAULT
,
641 hWnd
, NULL
, hInst
, panel
);
642 if (!panel
->hWnd
) return;
644 while (GetMessageW(&msg
, panel
->hWnd
, 0, 0)) {
645 TranslateMessage(&msg
);
646 DispatchMessageW(&msg
);
650 static void Control_RegisterRegistryApplets(HWND hWnd
, CPanel
*panel
, HKEY hkey_root
, LPCWSTR szRepPath
)
652 WCHAR name
[MAX_PATH
];
653 WCHAR value
[MAX_PATH
];
656 if (RegOpenKeyW(hkey_root
, szRepPath
, &hkey
) == ERROR_SUCCESS
)
662 DWORD nameLen
= MAX_PATH
;
663 DWORD valueLen
= MAX_PATH
;
665 if (RegEnumValueW(hkey
, idx
, name
, &nameLen
, NULL
, NULL
, (LPBYTE
)value
, &valueLen
) != ERROR_SUCCESS
)
668 Control_LoadApplet(hWnd
, value
, panel
);
674 static void Control_DoWindow(CPanel
* panel
, HWND hWnd
, HINSTANCE hInst
)
678 WCHAR buffer
[MAX_PATH
];
679 static const WCHAR wszAllCpl
[] = {'*','.','c','p','l',0};
680 static const WCHAR wszRegPath
[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t',
681 '\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n',
682 '\\','C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','C','p','l','s',0};
685 /* first add .cpl files in the system directory */
686 GetSystemDirectoryW( buffer
, MAX_PATH
);
687 p
= buffer
+ strlenW(buffer
);
689 lstrcpyW(p
, wszAllCpl
);
691 if ((h
= FindFirstFileW(buffer
, &fd
)) != INVALID_HANDLE_VALUE
) {
693 lstrcpyW(p
, fd
.cFileName
);
694 Control_LoadApplet(hWnd
, buffer
, panel
);
695 } while (FindNextFileW(h
, &fd
));
699 /* now check for cpls in the registry */
700 Control_RegisterRegistryApplets(hWnd
, panel
, HKEY_LOCAL_MACHINE
, wszRegPath
);
701 Control_RegisterRegistryApplets(hWnd
, panel
, HKEY_CURRENT_USER
, wszRegPath
);
703 Control_DoInterface(panel
, hWnd
, hInst
);
706 static void Control_DoLaunch(CPanel
* panel
, HWND hWnd
, LPCWSTR wszCmd
)
722 LPWSTR extraPmtsBuf
= NULL
;
723 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 applet
= Control_LoadApplet(hWnd
, buffer
, panel
);
795 /* we've been given a textual parameter (or none at all) */
797 while ((++sp
) != applet
->count
) {
798 TRACE("sp %d, name %s\n", sp
, debugstr_w(applet
->info
[sp
].name
));
800 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
->proc(applet
->hWnd
, CPL_STARTWPARMSW
, sp
, (LPARAM
)extraPmts
))
811 applet
->proc(applet
->hWnd
, CPL_DBLCLK
, sp
, applet
->info
[sp
].data
);
813 Control_UnloadApplet(applet
);
816 HeapFree(GetProcessHeap(), 0, buffer
);
819 /*************************************************************************
820 * Control_RunDLLW [SHELL32.@]
823 void WINAPI
Control_RunDLLW(HWND hWnd
, HINSTANCE hInst
, LPCWSTR cmd
, DWORD nCmdShow
)
827 TRACE("(%p, %p, %s, 0x%08x)\n",
828 hWnd
, hInst
, debugstr_w(cmd
), nCmdShow
);
830 memset(&panel
, 0, sizeof(panel
));
831 list_init( &panel
.applets
);
834 Control_DoWindow(&panel
, hWnd
, hInst
);
836 Control_DoLaunch(&panel
, hWnd
, cmd
);
840 /*************************************************************************
841 * Control_RunDLLA [SHELL32.@]
844 void WINAPI
Control_RunDLLA(HWND hWnd
, HINSTANCE hInst
, LPCSTR cmd
, DWORD nCmdShow
)
846 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, cmd
, -1, NULL
, 0 );
847 LPWSTR wszCmd
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
848 if (wszCmd
&& MultiByteToWideChar(CP_ACP
, 0, cmd
, -1, wszCmd
, len
))
850 Control_RunDLLW(hWnd
, hInst
, wszCmd
, nCmdShow
);
852 HeapFree(GetProcessHeap(), 0, wszCmd
);
855 /*************************************************************************
856 * Control_FillCache_RunDLLW [SHELL32.@]
859 HRESULT WINAPI
Control_FillCache_RunDLLW(HWND hWnd
, HANDLE hModule
, DWORD w
, DWORD x
)
861 FIXME("%p %p 0x%08x 0x%08x stub\n", hWnd
, hModule
, w
, x
);
865 /*************************************************************************
866 * Control_FillCache_RunDLLA [SHELL32.@]
869 HRESULT WINAPI
Control_FillCache_RunDLLA(HWND hWnd
, HANDLE hModule
, DWORD w
, DWORD x
)
871 return Control_FillCache_RunDLLW(hWnd
, hModule
, w
, x
);
874 /*************************************************************************
875 * CallCPLEntry16 [SHELL32.166]
877 * called by desk.cpl on "Advanced" with:
878 * hMod("DeskCp16.Dll"), pFunc("CplApplet"), 0, 1, 0xc, 0
881 DWORD WINAPI
CallCPLEntry16(HMODULE hMod
, FARPROC pFunc
, DWORD dw3
, DWORD dw4
, DWORD dw5
, DWORD dw6
)
883 FIXME("(%p, %p, %08x, %08x, %08x, %08x): stub.\n", hMod
, pFunc
, dw3
, dw4
, dw5
, dw6
);