appwiz.cpl: Read modification path from registry.
[wine/multimedia.git] / dlls / appwiz.cpl / appwiz.c
blob5ad4863b7642265d81925d6aa06b793fe5cc5775
1 /*
2 * Add/Remove Programs applet
3 * Partially based on Wine Uninstaller
5 * Copyright 2000 Andreas Mohr
6 * Copyright 2004 Hannu Valtonen
7 * Copyright 2005 Jonathan Ernst
8 * Copyright 2001-2002, 2008 Owen Rudge
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define NONAMELESSUNION
28 #include "config.h"
29 #include "wine/port.h"
30 #include "wine/unicode.h"
31 #include "wine/debug.h"
33 #include <string.h>
34 #include <stdlib.h>
35 #include <stdarg.h>
36 #include <stdio.h>
37 #include <windef.h>
38 #include <winbase.h>
39 #include <winuser.h>
40 #include <wingdi.h>
41 #include <winreg.h>
42 #include <shellapi.h>
43 #include <commctrl.h>
44 #include <commdlg.h>
45 #include <cpl.h>
47 #include "res.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(appwizcpl);
51 /* define a maximum length for various buffers we use */
52 #define MAX_STRING_LEN 1024
54 typedef struct APPINFO {
55 int id;
57 LPWSTR title;
58 LPWSTR path;
59 LPWSTR path_modify;
61 LPWSTR icon;
62 int iconIdx;
64 LPWSTR publisher;
65 LPWSTR version;
67 HKEY regroot;
68 WCHAR regkey[MAX_STRING_LEN];
70 struct APPINFO *next;
71 } APPINFO;
73 static struct APPINFO *AppInfo = NULL;
74 static HINSTANCE hInst;
76 static const WCHAR openW[] = {'o','p','e','n',0};
78 /* names of registry keys */
79 static const WCHAR BackSlashW[] = { '\\', 0 };
80 static const WCHAR DisplayNameW[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
81 static const WCHAR DisplayIconW[] = {'D','i','s','p','l','a','y','I','c','o','n',0};
82 static const WCHAR DisplayVersionW[] = {'D','i','s','p','l','a','y','V','e','r',
83 's','i','o','n',0};
84 static const WCHAR PublisherW[] = {'P','u','b','l','i','s','h','e','r',0};
85 static const WCHAR ContactW[] = {'C','o','n','t','a','c','t',0};
86 static const WCHAR HelpLinkW[] = {'H','e','l','p','L','i','n','k',0};
87 static const WCHAR HelpTelephoneW[] = {'H','e','l','p','T','e','l','e','p','h',
88 'o','n','e',0};
89 static const WCHAR ModifyPathW[] = {'M','o','d','i','f','y','P','a','t','h',0};
90 static const WCHAR NoModifyW[] = {'N','o','M','o','d','i','f','y',0};
91 static const WCHAR ReadmeW[] = {'R','e','a','d','m','e',0};
92 static const WCHAR URLUpdateInfoW[] = {'U','R','L','U','p','d','a','t','e','I',
93 'n','f','o',0};
94 static const WCHAR CommentsW[] = {'C','o','m','m','e','n','t','s',0};
95 static const WCHAR UninstallCommandlineW[] = {'U','n','i','n','s','t','a','l','l',
96 'S','t','r','i','n','g',0};
98 static const WCHAR PathUninstallW[] = {
99 'S','o','f','t','w','a','r','e','\\',
100 'M','i','c','r','o','s','o','f','t','\\',
101 'W','i','n','d','o','w','s','\\',
102 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
103 'U','n','i','n','s','t','a','l','l',0 };
105 /******************************************************************************
106 * Name : DllMain
107 * Description: Entry point for DLL file
109 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
110 LPVOID lpvReserved)
112 TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
114 switch (fdwReason)
116 case DLL_PROCESS_ATTACH:
117 hInst = hinstDLL;
118 break;
120 return TRUE;
123 /******************************************************************************
124 * Name : FreeAppInfo
125 * Description: Frees memory used by an AppInfo structure, and any children.
127 static void FreeAppInfo(APPINFO *info)
129 while (info)
131 APPINFO *next_info = info->next;
133 HeapFree(GetProcessHeap(), 0, info->title);
134 HeapFree(GetProcessHeap(), 0, info->path);
135 HeapFree(GetProcessHeap(), 0, info->path_modify);
136 HeapFree(GetProcessHeap(), 0, info->icon);
137 HeapFree(GetProcessHeap(), 0, info->publisher);
138 HeapFree(GetProcessHeap(), 0, info->version);
139 HeapFree(GetProcessHeap(), 0, info);
140 info = next_info;
144 /******************************************************************************
145 * Name : ReadApplicationsFromRegistry
146 * Description: Creates a linked list of uninstallable applications from the
147 * registry.
148 * Parameters : root - Which registry root to read from (HKCU/HKLM)
149 * Returns : TRUE if successful, FALSE otherwise
151 static BOOL ReadApplicationsFromRegistry(HKEY root)
153 HKEY hkeyUninst, hkeyApp;
154 int i, id = 0;
155 DWORD sizeOfSubKeyName, displen, uninstlen;
156 DWORD dwNoModify, dwType;
157 WCHAR subKeyName[256];
158 WCHAR key_app[MAX_STRING_LEN];
159 WCHAR *p;
160 APPINFO *iter = AppInfo;
161 LPWSTR iconPtr;
162 BOOL ret = FALSE;
164 if (RegOpenKeyExW(root, PathUninstallW, 0, KEY_READ, &hkeyUninst) !=
165 ERROR_SUCCESS)
166 return FALSE;
168 lstrcpyW(key_app, PathUninstallW);
169 lstrcatW(key_app, BackSlashW);
170 p = key_app+lstrlenW(PathUninstallW)+1;
172 sizeOfSubKeyName = sizeof(subKeyName) / sizeof(subKeyName[0]);
174 if (iter)
176 /* find the end of the list */
177 for (iter = AppInfo; iter->next; iter = iter->next);
180 for (i = 0; RegEnumKeyExW(hkeyUninst, i, subKeyName, &sizeOfSubKeyName, NULL,
181 NULL, NULL, NULL) != ERROR_NO_MORE_ITEMS; ++i)
183 lstrcpyW(p, subKeyName);
184 RegOpenKeyExW(root, key_app, 0, KEY_READ, &hkeyApp);
186 displen = 0;
187 uninstlen = 0;
189 if ((RegQueryValueExW(hkeyApp, DisplayNameW, 0, 0, NULL, &displen) ==
190 ERROR_SUCCESS) && (RegQueryValueExW(hkeyApp, UninstallCommandlineW,
191 0, 0, NULL, &uninstlen) == ERROR_SUCCESS))
193 /* if we already have iter, allocate the next entry */
194 if (iter)
196 iter->next = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
197 sizeof(struct APPINFO));
199 if (!iter->next)
200 goto err;
202 iter = iter->next;
204 else
206 /* if not, start the list */
207 iter = AppInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
208 sizeof(struct APPINFO));
210 if (!iter)
211 goto err;
214 iter->title = HeapAlloc(GetProcessHeap(), 0, displen);
216 if (!iter->title)
217 goto err;
219 RegQueryValueExW(hkeyApp, DisplayNameW, 0, 0, (LPBYTE)iter->title,
220 &displen);
222 /* now get DisplayIcon */
223 displen = 0;
224 RegQueryValueExW(hkeyApp, DisplayIconW, 0, 0, NULL, &displen);
226 if (displen == 0)
227 iter->icon = 0;
228 else
230 iter->icon = HeapAlloc(GetProcessHeap(), 0, displen);
232 if (!iter->icon)
233 goto err;
235 RegQueryValueExW(hkeyApp, DisplayIconW, 0, 0, (LPBYTE)iter->icon,
236 &displen);
238 /* separate the index from the icon name, if supplied */
239 iconPtr = strchrW(iter->icon, ',');
241 if (iconPtr)
243 *iconPtr++ = 0;
244 iter->iconIdx = atoiW(iconPtr);
248 iter->path = HeapAlloc(GetProcessHeap(), 0, uninstlen);
250 if (!iter->path)
251 goto err;
253 RegQueryValueExW(hkeyApp, UninstallCommandlineW, 0, 0,
254 (LPBYTE)iter->path, &uninstlen);
256 /* publisher, version */
257 if (RegQueryValueExW(hkeyApp, PublisherW, 0, 0, NULL, &displen) ==
258 ERROR_SUCCESS)
260 iter->publisher = HeapAlloc(GetProcessHeap(), 0, displen);
262 if (!iter->publisher)
263 goto err;
265 RegQueryValueExW(hkeyApp, PublisherW, 0, 0, (LPBYTE)iter->publisher,
266 &displen);
269 if (RegQueryValueExW(hkeyApp, DisplayVersionW, 0, 0, NULL, &displen) ==
270 ERROR_SUCCESS)
272 iter->version = HeapAlloc(GetProcessHeap(), 0, displen);
274 if (!iter->version)
275 goto err;
277 RegQueryValueExW(hkeyApp, DisplayVersionW, 0, 0, (LPBYTE)iter->version,
278 &displen);
281 /* Check if NoModify is set */
282 dwType = REG_DWORD;
283 dwNoModify = 0;
284 displen = sizeof(DWORD);
286 if (RegQueryValueExW(hkeyApp, NoModifyW, NULL, &dwType, (LPBYTE)&dwNoModify, &displen)
287 != ERROR_SUCCESS)
289 dwNoModify = 0;
292 /* Some installers incorrectly create a REG_SZ instead of a REG_DWORD - check for
293 ASCII 49, which equals 1 */
294 if (dwType == REG_SZ)
295 dwNoModify = (dwNoModify == 49) ? 1 : 0;
297 /* Fetch the modify path */
298 if ((dwNoModify == 0) && (RegQueryValueExW(hkeyApp, ModifyPathW, 0, 0, NULL, &displen)
299 == ERROR_SUCCESS))
301 iter->path_modify = HeapAlloc(GetProcessHeap(), 0, displen);
303 if (!iter->path_modify)
304 goto err;
306 RegQueryValueExW(hkeyApp, ModifyPathW, 0, 0, (LPBYTE)iter->path_modify, &displen);
309 /* registry key */
310 iter->regroot = root;
311 lstrcpyW(iter->regkey, subKeyName);
313 iter->id = id++;
316 RegCloseKey(hkeyApp);
317 sizeOfSubKeyName = sizeof(subKeyName) / sizeof(subKeyName[0]);
320 ret = TRUE;
321 goto end;
323 err:
324 RegCloseKey(hkeyApp);
325 FreeAppInfo(iter);
327 end:
328 RegCloseKey(hkeyUninst);
329 return ret;
333 /******************************************************************************
334 * Name : AddApplicationsToList
335 * Description: Populates the list box with applications.
336 * Parameters : hWnd - Handle of the dialog box
338 static void AddApplicationsToList(HWND hWnd, HIMAGELIST hList)
340 APPINFO *iter = AppInfo;
341 LVITEMW lvItem;
342 HICON hIcon;
343 int index;
345 while (iter)
347 /* get the icon */
348 index = 0;
350 if (iter->icon)
352 if (ExtractIconExW(iter->icon, iter->iconIdx, NULL, &hIcon, 1) == 1)
354 index = ImageList_AddIcon(hList, hIcon);
355 DestroyIcon(hIcon);
359 lvItem.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_PARAM;
360 lvItem.iItem = iter->id;
361 lvItem.iSubItem = 0;
362 lvItem.pszText = iter->title;
363 lvItem.iImage = index;
364 lvItem.lParam = iter->id;
366 index = ListView_InsertItemW(hWnd, &lvItem);
368 /* now add the subitems (columns) */
369 ListView_SetItemTextW(hWnd, index, 1, iter->publisher);
370 ListView_SetItemTextW(hWnd, index, 2, iter->version);
372 iter = iter->next;
376 /******************************************************************************
377 * Name : RemoveItemsFromList
378 * Description: Clears the application list box.
379 * Parameters : hWnd - Handle of the dialog box
381 static void RemoveItemsFromList(HWND hWnd)
383 SendDlgItemMessageW(hWnd, IDL_PROGRAMS, LVM_DELETEALLITEMS, 0, 0);
386 /******************************************************************************
387 * Name : EmptyList
388 * Description: Frees memory used by the application linked list.
390 static inline void EmptyList(void)
392 FreeAppInfo(AppInfo);
393 AppInfo = NULL;
396 /******************************************************************************
397 * Name : UpdateButtons
398 * Description: Enables/disables the Add/Remove button depending on current
399 * selection in list box.
400 * Parameters : hWnd - Handle of the dialog box
402 static void UpdateButtons(HWND hWnd)
404 BOOL sel = SendMessageW(GetDlgItem(hWnd, IDL_PROGRAMS), LVM_GETSELECTEDCOUNT, 0, 0) != 0;
406 EnableWindow(GetDlgItem(hWnd, IDC_ADDREMOVE), sel);
407 EnableWindow(GetDlgItem(hWnd, IDC_SUPPORT_INFO), sel);
410 /******************************************************************************
411 * Name : InstallProgram
412 * Description: Search for potential Installer and execute it.
413 * Parameters : hWnd - Handle of the dialog box
415 static void InstallProgram(HWND hWnd)
417 OPENFILENAMEW ofn;
418 WCHAR titleW[MAX_STRING_LEN];
419 WCHAR FilterBufferW[MAX_STRING_LEN];
420 WCHAR FileNameBufferW[MAX_PATH];
422 LoadStringW(hInst, IDS_CPL_TITLE, titleW, sizeof(titleW)/sizeof(WCHAR));
423 LoadStringW(hInst, IDS_INSTALL_FILTER, FilterBufferW, sizeof(FilterBufferW)/sizeof(WCHAR));
425 memset(&ofn, 0, sizeof(OPENFILENAMEW));
426 ofn.lStructSize = sizeof(OPENFILENAMEW);
427 ofn.hwndOwner = hWnd;
428 ofn.hInstance = hInst;
429 ofn.lpstrFilter = FilterBufferW;
430 ofn.nFilterIndex = 0;
431 ofn.lpstrFile = FileNameBufferW;
432 ofn.nMaxFile = MAX_PATH;
433 ofn.lpstrFileTitle = NULL;
434 ofn.nMaxFileTitle = 0;
435 ofn.lpstrTitle = titleW;
436 ofn.Flags = OFN_HIDEREADONLY | OFN_ENABLESIZING;
437 FileNameBufferW[0] = 0;
439 if (GetOpenFileNameW(&ofn))
441 SHELLEXECUTEINFOW sei;
442 memset(&sei, 0, sizeof(sei));
443 sei.cbSize = sizeof(sei);
444 sei.lpVerb = openW;
445 sei.nShow = SW_SHOWDEFAULT;
446 sei.fMask = SEE_MASK_NO_CONSOLE;
447 sei.lpFile = ofn.lpstrFile;
449 ShellExecuteExW(&sei);
453 /******************************************************************************
454 * Name : UninstallProgram
455 * Description: Executes the specified program's installer.
456 * Parameters : id - the internal ID of the installer to remove
458 static void UninstallProgram(int id)
460 APPINFO *iter;
461 STARTUPINFOW si;
462 PROCESS_INFORMATION info;
463 WCHAR errormsg[MAX_STRING_LEN];
464 WCHAR sUninstallFailed[MAX_STRING_LEN];
465 HKEY hkey;
466 BOOL res;
468 LoadStringW(hInst, IDS_UNINSTALL_FAILED, sUninstallFailed,
469 sizeof(sUninstallFailed) / sizeof(sUninstallFailed[0]));
471 for (iter = AppInfo; iter; iter = iter->next)
473 if (iter->id == id)
475 TRACE("Uninstalling %s (%s)\n", wine_dbgstr_w(iter->title),
476 wine_dbgstr_w(iter->path));
478 memset(&si, 0, sizeof(STARTUPINFOW));
479 si.cb = sizeof(STARTUPINFOW);
480 si.wShowWindow = SW_NORMAL;
481 res = CreateProcessW(NULL, iter->path, NULL, NULL, FALSE, 0, NULL,
482 NULL, &si, &info);
484 if (res)
486 CloseHandle(info.hThread);
488 /* wait for the process to exit */
489 WaitForSingleObject(info.hProcess, INFINITE);
490 CloseHandle(info.hProcess);
492 else
494 wsprintfW(errormsg, sUninstallFailed, iter->path);
496 if (MessageBoxW(0, errormsg, iter->title, MB_YESNO |
497 MB_ICONQUESTION) == IDYES)
499 /* delete the application's uninstall entry */
500 RegOpenKeyExW(iter->regroot, PathUninstallW, 0, KEY_READ, &hkey);
501 RegDeleteKeyW(hkey, iter->regkey);
502 RegCloseKey(hkey);
506 break;
511 /**********************************************************************************
512 * Name : SetInfoDialogText
513 * Description: Sets the text of a label in a window, based upon a registry entry
514 * or string passed to the function.
515 * Parameters : hKey - registry entry to read from, NULL if not reading
516 * from registry
517 * lpKeyName - key to read from, or string to check if hKey is NULL
518 * lpAltMessage - alternative message if entry not found
519 * hWnd - handle of dialog box
520 * iDlgItem - ID of label in dialog box
522 static void SetInfoDialogText(HKEY hKey, LPWSTR lpKeyName, LPWSTR lpAltMessage,
523 HWND hWnd, int iDlgItem)
525 WCHAR buf[MAX_STRING_LEN];
526 DWORD buflen;
527 HWND hWndDlgItem;
529 hWndDlgItem = GetDlgItem(hWnd, iDlgItem);
531 /* if hKey is null, lpKeyName contains the string we want to check */
532 if (hKey == NULL)
534 if ((lpKeyName) && (lstrlenW(lpKeyName) > 0))
535 SetWindowTextW(hWndDlgItem, lpKeyName);
536 else
537 SetWindowTextW(hWndDlgItem, lpAltMessage);
539 else
541 buflen = MAX_STRING_LEN;
543 if ((RegQueryValueExW(hKey, lpKeyName, 0, 0, (LPBYTE) buf, &buflen) ==
544 ERROR_SUCCESS) && (lstrlenW(buf) > 0))
545 SetWindowTextW(hWndDlgItem, buf);
546 else
547 SetWindowTextW(hWndDlgItem, lpAltMessage);
551 /******************************************************************************
552 * Name : SupportInfoDlgProc
553 * Description: Callback procedure for support info dialog
554 * Parameters : hWnd - hWnd of the window
555 * msg - reason for calling function
556 * wParam - additional parameter
557 * lParam - additional parameter
558 * Returns : Dependant on message
560 static BOOL CALLBACK SupportInfoDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
562 APPINFO *iter;
563 HKEY hkey;
564 WCHAR oldtitle[MAX_STRING_LEN];
565 WCHAR buf[MAX_STRING_LEN];
566 WCHAR key[MAX_STRING_LEN];
567 WCHAR notfound[MAX_STRING_LEN];
569 switch(msg)
571 case WM_INITDIALOG:
572 for (iter = AppInfo; iter; iter = iter->next)
574 if (iter->id == (int) lParam)
576 lstrcpyW(key, PathUninstallW);
577 lstrcatW(key, BackSlashW);
578 lstrcatW(key, iter->regkey);
580 /* check the application's registry entries */
581 RegOpenKeyExW(iter->regroot, key, 0, KEY_READ, &hkey);
583 /* Load our "not specified" string */
584 LoadStringW(hInst, IDS_NOT_SPECIFIED, notfound,
585 sizeof(notfound) / sizeof(notfound[0]));
587 /* Update the data for items already read into the structure */
588 SetInfoDialogText(NULL, iter->publisher, notfound, hWnd,
589 IDC_INFO_PUBLISHER);
590 SetInfoDialogText(NULL, iter->version, notfound, hWnd,
591 IDC_INFO_VERSION);
593 /* And now update the data for those items in the registry */
594 SetInfoDialogText(hkey, (LPWSTR) ContactW, notfound, hWnd,
595 IDC_INFO_CONTACT);
596 SetInfoDialogText(hkey, (LPWSTR) HelpLinkW, notfound, hWnd,
597 IDC_INFO_SUPPORT);
598 SetInfoDialogText(hkey, (LPWSTR) HelpTelephoneW, notfound, hWnd,
599 IDC_INFO_PHONE);
600 SetInfoDialogText(hkey, (LPWSTR) ReadmeW, notfound, hWnd,
601 IDC_INFO_README);
602 SetInfoDialogText(hkey, (LPWSTR) URLUpdateInfoW, notfound, hWnd,
603 IDC_INFO_UPDATES);
604 SetInfoDialogText(hkey, (LPWSTR) CommentsW, notfound, hWnd,
605 IDC_INFO_COMMENTS);
607 /* Update the main label with the app name */
608 if (GetWindowTextW(GetDlgItem(hWnd, IDC_INFO_LABEL), oldtitle,
609 MAX_STRING_LEN) != 0)
611 wsprintfW(buf, oldtitle, iter->title);
612 SetWindowTextW(GetDlgItem(hWnd, IDC_INFO_LABEL), buf);
615 RegCloseKey(hkey);
617 break;
621 return TRUE;
623 case WM_DESTROY:
624 return 0;
626 case WM_COMMAND:
627 switch (LOWORD(wParam))
629 case IDOK:
630 EndDialog(hWnd, TRUE);
631 break;
635 return TRUE;
638 return FALSE;
641 /******************************************************************************
642 * Name : SupportInfo
643 * Description: Displays the Support Information dialog
644 * Parameters : hWnd - Handle of the main dialog
645 * id - ID of the application to display information for
647 static void SupportInfo(HWND hWnd, int id)
649 DialogBoxParamW(hInst, MAKEINTRESOURCEW(IDD_INFO), hWnd, (DLGPROC)
650 SupportInfoDlgProc, (LPARAM) id);
653 /* Definition of column headers for AddListViewColumns function */
654 typedef struct AppWizColumn {
655 int width;
656 int fmt;
657 int title;
658 } AppWizColumn;
660 static const AppWizColumn columns[] = {
661 {200, LVCFMT_LEFT, IDS_COLUMN_NAME},
662 {150, LVCFMT_LEFT, IDS_COLUMN_PUBLISHER},
663 {100, LVCFMT_LEFT, IDS_COLUMN_VERSION},
666 /******************************************************************************
667 * Name : AddListViewColumns
668 * Description: Adds column headers to the list view control.
669 * Parameters : hWnd - Handle of the list view control.
670 * Returns : TRUE if completed successfully, FALSE otherwise.
672 static BOOL AddListViewColumns(HWND hWnd)
674 WCHAR buf[MAX_STRING_LEN];
675 LVCOLUMNW lvc;
676 UINT i;
678 lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
680 /* Add the columns */
681 for (i = 0; i < sizeof(columns) / sizeof(columns[0]); i++)
683 lvc.iSubItem = i;
684 lvc.pszText = buf;
686 /* set width and format */
687 lvc.cx = columns[i].width;
688 lvc.fmt = columns[i].fmt;
690 LoadStringW(hInst, columns[i].title, buf, sizeof(buf) / sizeof(buf[0]));
692 if (ListView_InsertColumnW(hWnd, i, &lvc) == -1)
693 return FALSE;
696 return TRUE;
699 /******************************************************************************
700 * Name : AddListViewImageList
701 * Description: Creates an ImageList for the list view control.
702 * Parameters : hWnd - Handle of the list view control.
703 * Returns : Handle of the image list.
705 static HIMAGELIST AddListViewImageList(HWND hWnd)
707 HIMAGELIST hSmall;
708 HICON hDefaultIcon;
710 hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
711 ILC_MASK, 1, 1);
713 /* Add default icon to image list */
714 hDefaultIcon = LoadIconW(hInst, MAKEINTRESOURCEW(ICO_MAIN));
715 ImageList_AddIcon(hSmall, hDefaultIcon);
716 DestroyIcon(hDefaultIcon);
718 SendMessageW(hWnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)hSmall);
720 return hSmall;
723 /******************************************************************************
724 * Name : ResetApplicationList
725 * Description: Empties the app list, if need be, and recreates it.
726 * Parameters : bFirstRun - TRUE if this is the first time this is run, FALSE otherwise
727 * hWnd - handle of the dialog box
728 * hImageList - handle of the image list
729 * Returns : New handle of the image list.
731 static HIMAGELIST ResetApplicationList(BOOL bFirstRun, HWND hWnd, HIMAGELIST hImageList)
733 HWND hWndListView;
735 hWndListView = GetDlgItem(hWnd, IDL_PROGRAMS);
737 /* if first run, create the image list and add the listview columns */
738 if (bFirstRun)
740 if (!AddListViewColumns(hWndListView))
741 return NULL;
743 else /* we need to remove the existing things first */
745 RemoveItemsFromList(hWnd);
746 ImageList_Destroy(hImageList);
748 /* reset the list, since it's probably changed if the uninstallation was
749 successful */
750 EmptyList();
753 /* now create the image list and add the applications to the listview */
754 hImageList = AddListViewImageList(hWndListView);
756 ReadApplicationsFromRegistry(HKEY_LOCAL_MACHINE);
757 ReadApplicationsFromRegistry(HKEY_CURRENT_USER);
759 AddApplicationsToList(hWndListView, hImageList);
760 UpdateButtons(hWnd);
762 return(hImageList);
765 /******************************************************************************
766 * Name : MainDlgProc
767 * Description: Callback procedure for main tab
768 * Parameters : hWnd - hWnd of the window
769 * msg - reason for calling function
770 * wParam - additional parameter
771 * lParam - additional parameter
772 * Returns : Dependant on message
774 static BOOL CALLBACK MainDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
776 int selitem;
777 static HIMAGELIST hImageList;
778 LPNMHDR nmh;
779 LVITEMW lvItem;
781 switch(msg)
783 case WM_INITDIALOG:
784 hImageList = ResetApplicationList(TRUE, hWnd, hImageList);
786 if (!hImageList)
787 return FALSE;
789 return TRUE;
791 case WM_DESTROY:
792 RemoveItemsFromList(hWnd);
793 ImageList_Destroy(hImageList);
795 EmptyList();
797 return 0;
799 case WM_NOTIFY:
800 nmh = (LPNMHDR) lParam;
802 switch (nmh->idFrom)
804 case IDL_PROGRAMS:
805 switch (nmh->code)
807 case LVN_ITEMCHANGED:
808 UpdateButtons(hWnd);
809 break;
811 break;
814 return TRUE;
816 case WM_COMMAND:
817 switch (LOWORD(wParam))
819 case IDC_INSTALL:
820 InstallProgram(hWnd);
821 break;
823 case IDC_ADDREMOVE:
824 selitem = SendDlgItemMessageW(hWnd, IDL_PROGRAMS,
825 LVM_GETNEXTITEM, -1, LVNI_FOCUSED|LVNI_SELECTED);
827 if (selitem != -1)
829 lvItem.iItem = selitem;
830 lvItem.mask = LVIF_PARAM;
832 if (SendDlgItemMessageW(hWnd, IDL_PROGRAMS, LVM_GETITEMW,
833 0, (LPARAM) &lvItem))
834 UninstallProgram(lvItem.lParam);
837 hImageList = ResetApplicationList(FALSE, hWnd, hImageList);
839 break;
841 case IDC_SUPPORT_INFO:
842 selitem = SendDlgItemMessageW(hWnd, IDL_PROGRAMS,
843 LVM_GETNEXTITEM, -1, LVNI_FOCUSED | LVNI_SELECTED);
845 if (selitem != -1)
847 lvItem.iItem = selitem;
848 lvItem.mask = LVIF_PARAM;
850 if (SendDlgItemMessageW(hWnd, IDL_PROGRAMS, LVM_GETITEMW,
851 0, (LPARAM) &lvItem))
852 SupportInfo(hWnd, lvItem.lParam);
855 break;
858 return TRUE;
861 return FALSE;
864 /******************************************************************************
865 * Name : StartApplet
866 * Description: Main routine for applet
867 * Parameters : hWnd - hWnd of the Control Panel
869 static void StartApplet(HWND hWnd)
871 PROPSHEETPAGEW psp;
872 PROPSHEETHEADERW psh;
873 WCHAR tab_title[MAX_STRING_LEN], app_title[MAX_STRING_LEN];
875 /* Load the strings we will use */
876 LoadStringW(hInst, IDS_TAB1_TITLE, tab_title, sizeof(tab_title) / sizeof(tab_title[0]));
877 LoadStringW(hInst, IDS_CPL_TITLE, app_title, sizeof(app_title) / sizeof(app_title[0]));
879 /* Fill out the PROPSHEETPAGE */
880 psp.dwSize = sizeof (PROPSHEETPAGEW);
881 psp.dwFlags = PSP_USETITLE;
882 psp.hInstance = hInst;
883 psp.u.pszTemplate = MAKEINTRESOURCEW (IDD_MAIN);
884 psp.u2.pszIcon = NULL;
885 psp.pfnDlgProc = (DLGPROC) MainDlgProc;
886 psp.pszTitle = tab_title;
887 psp.lParam = 0;
889 /* Fill out the PROPSHEETHEADER */
890 psh.dwSize = sizeof (PROPSHEETHEADERW);
891 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID;
892 psh.hwndParent = hWnd;
893 psh.hInstance = hInst;
894 psh.u.pszIcon = NULL;
895 psh.pszCaption = app_title;
896 psh.nPages = 1;
897 psh.u3.ppsp = &psp;
898 psh.pfnCallback = NULL;
899 psh.u2.nStartPage = 0;
901 /* Display the property sheet */
902 PropertySheetW (&psh);
905 /******************************************************************************
906 * Name : CPlApplet
907 * Description: Entry point for Control Panel applets
908 * Parameters : hwndCPL - hWnd of the Control Panel
909 * message - reason for calling function
910 * lParam1 - additional parameter
911 * lParam2 - additional parameter
912 * Returns : Dependant on message
914 LONG CALLBACK CPlApplet(HWND hwndCPL, UINT message, LPARAM lParam1, LPARAM lParam2)
916 INITCOMMONCONTROLSEX iccEx;
918 switch (message)
920 case CPL_INIT:
921 iccEx.dwSize = sizeof(iccEx);
922 iccEx.dwICC = ICC_LISTVIEW_CLASSES | ICC_TAB_CLASSES;
924 InitCommonControlsEx(&iccEx);
926 return TRUE;
928 case CPL_GETCOUNT:
929 return 1;
931 case CPL_INQUIRE:
933 CPLINFO *appletInfo = (CPLINFO *) lParam2;
935 appletInfo->idIcon = ICO_MAIN;
936 appletInfo->idName = IDS_CPL_TITLE;
937 appletInfo->idInfo = IDS_CPL_DESC;
938 appletInfo->lData = 0;
940 break;
943 case CPL_DBLCLK:
944 StartApplet(hwndCPL);
945 break;
948 return FALSE;