~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/appwiz.cpl/appwiz.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * Add/Remove Programs applet
  3  * Partially based on Wine Uninstaller
  4  *
  5  * Copyright 2000 Andreas Mohr
  6  * Copyright 2004 Hannu Valtonen
  7  * Copyright 2005 Jonathan Ernst
  8  * Copyright 2001-2002, 2008 Owen Rudge
  9  *
 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.
 14  *
 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.
 19  *
 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
 23  *
 24  */
 25 
 26 #define NONAMELESSUNION
 27 
 28 #include "config.h"
 29 #include "wine/port.h"
 30 #include "wine/unicode.h"
 31 #include "wine/debug.h"
 32 
 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>
 46 
 47 #include "res.h"
 48 
 49 WINE_DEFAULT_DEBUG_CHANNEL(appwizcpl);
 50 
 51 /* define a maximum length for various buffers we use */
 52 #define MAX_STRING_LEN    1024
 53 
 54 typedef struct APPINFO {
 55     int id;
 56 
 57     LPWSTR title;
 58     LPWSTR path;
 59     LPWSTR path_modify;
 60 
 61     LPWSTR icon;
 62     int iconIdx;
 63 
 64     LPWSTR publisher;
 65     LPWSTR version;
 66 
 67     HKEY regroot;
 68     WCHAR regkey[MAX_STRING_LEN];
 69 
 70     struct APPINFO *next;
 71 } APPINFO;
 72 
 73 static struct APPINFO *AppInfo = NULL;
 74 static HINSTANCE hInst;
 75 
 76 static WCHAR btnRemove[MAX_STRING_LEN];
 77 static WCHAR btnModifyRemove[MAX_STRING_LEN];
 78 
 79 static const WCHAR openW[] = {'o','p','e','n',0};
 80 
 81 /* names of registry keys */
 82 static const WCHAR BackSlashW[] = { '\\', 0 };
 83 static const WCHAR DisplayNameW[] = {'D','i','s','p','l','a','y','N','a','m','e',0};
 84 static const WCHAR DisplayIconW[] = {'D','i','s','p','l','a','y','I','c','o','n',0};
 85 static const WCHAR DisplayVersionW[] = {'D','i','s','p','l','a','y','V','e','r',
 86     's','i','o','n',0};
 87 static const WCHAR PublisherW[] = {'P','u','b','l','i','s','h','e','r',0};
 88 static const WCHAR ContactW[] = {'C','o','n','t','a','c','t',0};
 89 static const WCHAR HelpLinkW[] = {'H','e','l','p','L','i','n','k',0};
 90 static const WCHAR HelpTelephoneW[] = {'H','e','l','p','T','e','l','e','p','h',
 91     'o','n','e',0};
 92 static const WCHAR ModifyPathW[] = {'M','o','d','i','f','y','P','a','t','h',0};
 93 static const WCHAR NoModifyW[] = {'N','o','M','o','d','i','f','y',0};
 94 static const WCHAR ReadmeW[] = {'R','e','a','d','m','e',0};
 95 static const WCHAR URLUpdateInfoW[] = {'U','R','L','U','p','d','a','t','e','I',
 96     'n','f','o',0};
 97 static const WCHAR CommentsW[] = {'C','o','m','m','e','n','t','s',0};
 98 static const WCHAR UninstallCommandlineW[] = {'U','n','i','n','s','t','a','l','l',
 99     'S','t','r','i','n','g',0};
100 
101 static const WCHAR PathUninstallW[] = {
102         'S','o','f','t','w','a','r','e','\\',
103         'M','i','c','r','o','s','o','f','t','\\',
104         'W','i','n','d','o','w','s','\\',
105         'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
106         'U','n','i','n','s','t','a','l','l',0 };
107 
108 /******************************************************************************
109  * Name       : DllMain
110  * Description: Entry point for DLL file
111  */
112 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
113                     LPVOID lpvReserved)
114 {
115     TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
116 
117     switch (fdwReason)
118     {
119         case DLL_PROCESS_ATTACH:
120             hInst = hinstDLL;
121             break;
122     }
123     return TRUE;
124 }
125 
126 /******************************************************************************
127  * Name       : FreeAppInfo
128  * Description: Frees memory used by an AppInfo structure, and any children.
129  */
130 static void FreeAppInfo(APPINFO *info)
131 {
132     while (info)
133     {
134         APPINFO *next_info = info->next;
135 
136         HeapFree(GetProcessHeap(), 0, info->title);
137         HeapFree(GetProcessHeap(), 0, info->path);
138         HeapFree(GetProcessHeap(), 0, info->path_modify);
139         HeapFree(GetProcessHeap(), 0, info->icon);
140         HeapFree(GetProcessHeap(), 0, info->publisher);
141         HeapFree(GetProcessHeap(), 0, info->version);
142         HeapFree(GetProcessHeap(), 0, info);
143         info = next_info;
144     }
145 }
146 
147 /******************************************************************************
148  * Name       : ReadApplicationsFromRegistry
149  * Description: Creates a linked list of uninstallable applications from the
150  *              registry.
151  * Parameters : root    - Which registry root to read from (HKCU/HKLM)
152  * Returns    : TRUE if successful, FALSE otherwise
153  */
154 static BOOL ReadApplicationsFromRegistry(HKEY root)
155 {
156     HKEY hkeyUninst, hkeyApp;
157     int i, id = 0;
158     DWORD sizeOfSubKeyName, displen, uninstlen;
159     DWORD dwNoModify, dwType;
160     WCHAR subKeyName[256];
161     WCHAR key_app[MAX_STRING_LEN];
162     WCHAR *p;
163     APPINFO *iter = AppInfo;
164     LPWSTR iconPtr;
165     BOOL ret = FALSE;
166 
167     if (RegOpenKeyExW(root, PathUninstallW, 0, KEY_READ, &hkeyUninst) !=
168       ERROR_SUCCESS)
169         return FALSE;
170 
171     lstrcpyW(key_app, PathUninstallW);
172     lstrcatW(key_app, BackSlashW);
173     p = key_app+lstrlenW(PathUninstallW)+1;
174 
175     sizeOfSubKeyName = sizeof(subKeyName) / sizeof(subKeyName[0]);
176 
177     if (iter)
178     {
179         /* find the end of the list */
180         for (iter = AppInfo; iter->next; iter = iter->next);
181     }
182 
183     for (i = 0; RegEnumKeyExW(hkeyUninst, i, subKeyName, &sizeOfSubKeyName, NULL,
184         NULL, NULL, NULL) != ERROR_NO_MORE_ITEMS; ++i)
185     {
186         lstrcpyW(p, subKeyName);
187         RegOpenKeyExW(root, key_app, 0, KEY_READ, &hkeyApp);
188 
189         displen = 0;
190         uninstlen = 0;
191 
192         if ((RegQueryValueExW(hkeyApp, DisplayNameW, 0, 0, NULL, &displen) ==
193             ERROR_SUCCESS) && (RegQueryValueExW(hkeyApp, UninstallCommandlineW,
194             0, 0, NULL, &uninstlen) == ERROR_SUCCESS))
195         {
196             /* if we already have iter, allocate the next entry */
197             if (iter)
198             {
199                 iter->next = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
200                     sizeof(struct APPINFO));
201 
202                 if (!iter->next)
203                     goto err;
204 
205                 iter = iter->next;
206             }
207             else
208             {
209                 /* if not, start the list */
210                 iter = AppInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
211                     sizeof(struct APPINFO));
212 
213                 if (!iter)
214                     goto err;
215             }
216 
217             iter->title = HeapAlloc(GetProcessHeap(), 0, displen);
218 
219             if (!iter->title)
220                 goto err;
221 
222             RegQueryValueExW(hkeyApp, DisplayNameW, 0, 0, (LPBYTE)iter->title,
223                 &displen);
224 
225             /* now get DisplayIcon */
226             displen = 0;
227             RegQueryValueExW(hkeyApp, DisplayIconW, 0, 0, NULL, &displen);
228 
229             if (displen == 0)
230                 iter->icon = 0;
231             else
232             {
233                 iter->icon = HeapAlloc(GetProcessHeap(), 0, displen);
234 
235                 if (!iter->icon)
236                     goto err;
237 
238                 RegQueryValueExW(hkeyApp, DisplayIconW, 0, 0, (LPBYTE)iter->icon,
239                     &displen);
240 
241                 /* separate the index from the icon name, if supplied */
242                 iconPtr = strchrW(iter->icon, ',');
243 
244                 if (iconPtr)
245                 {
246                     *iconPtr++ = 0;
247                     iter->iconIdx = atoiW(iconPtr);
248                 }
249             }
250 
251             iter->path = HeapAlloc(GetProcessHeap(), 0, uninstlen);
252 
253             if (!iter->path)
254                 goto err;
255 
256             RegQueryValueExW(hkeyApp, UninstallCommandlineW, 0, 0,
257                 (LPBYTE)iter->path, &uninstlen);
258 
259             /* publisher, version */
260             if (RegQueryValueExW(hkeyApp, PublisherW, 0, 0, NULL, &displen) ==
261                 ERROR_SUCCESS)
262             {
263                 iter->publisher = HeapAlloc(GetProcessHeap(), 0, displen);
264 
265                 if (!iter->publisher)
266                     goto err;
267 
268                 RegQueryValueExW(hkeyApp, PublisherW, 0, 0, (LPBYTE)iter->publisher,
269                     &displen);
270             }
271 
272             if (RegQueryValueExW(hkeyApp, DisplayVersionW, 0, 0, NULL, &displen) ==
273                 ERROR_SUCCESS)
274             {
275                 iter->version = HeapAlloc(GetProcessHeap(), 0, displen);
276 
277                 if (!iter->version)
278                     goto err;
279 
280                 RegQueryValueExW(hkeyApp, DisplayVersionW, 0, 0, (LPBYTE)iter->version,
281                     &displen);
282             }
283 
284             /* Check if NoModify is set */
285             dwType = REG_DWORD;
286             dwNoModify = 0;
287             displen = sizeof(DWORD);
288 
289             if (RegQueryValueExW(hkeyApp, NoModifyW, NULL, &dwType, (LPBYTE)&dwNoModify, &displen)
290                 != ERROR_SUCCESS)
291             {
292                 dwNoModify = 0;
293             }
294 
295             /* Some installers incorrectly create a REG_SZ instead of a REG_DWORD - check for
296                ASCII 49, which equals 1 */
297             if (dwType == REG_SZ)
298                 dwNoModify = (dwNoModify == 49) ? 1 : 0;
299 
300             /* Fetch the modify path */
301             if ((dwNoModify == 0) && (RegQueryValueExW(hkeyApp, ModifyPathW, 0, 0, NULL, &displen)
302                 == ERROR_SUCCESS))
303             {
304                 iter->path_modify = HeapAlloc(GetProcessHeap(), 0, displen);
305 
306                 if (!iter->path_modify)
307                     goto err;
308 
309                 RegQueryValueExW(hkeyApp, ModifyPathW, 0, 0, (LPBYTE)iter->path_modify, &displen);
310             }
311 
312             /* registry key */
313             iter->regroot = root;
314             lstrcpyW(iter->regkey, subKeyName);
315 
316             iter->id = id++;
317         }
318 
319         RegCloseKey(hkeyApp);
320         sizeOfSubKeyName = sizeof(subKeyName) / sizeof(subKeyName[0]);
321     }
322 
323     ret = TRUE;
324     goto end;
325 
326 err:
327     RegCloseKey(hkeyApp);
328     FreeAppInfo(iter);
329 
330 end:
331     RegCloseKey(hkeyUninst);
332     return ret;
333 }
334 
335 
336 /******************************************************************************
337  * Name       : AddApplicationsToList
338  * Description: Populates the list box with applications.
339  * Parameters : hWnd    - Handle of the dialog box
340  */
341 static void AddApplicationsToList(HWND hWnd, HIMAGELIST hList)
342 {
343     APPINFO *iter;
344     LVITEMW lvItem;
345     HICON hIcon;
346     int index;
347 
348     for (iter = AppInfo; iter; iter = iter->next)
349     {
350         if (!iter->title[0]) continue;
351 
352         /* get the icon */
353         index = 0;
354 
355         if (iter->icon)
356         {
357             if (ExtractIconExW(iter->icon, iter->iconIdx, NULL, &hIcon, 1) == 1)
358             {
359                 index = ImageList_AddIcon(hList, hIcon);
360                 DestroyIcon(hIcon);
361             }
362         }
363 
364         lvItem.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_PARAM;
365         lvItem.iItem = iter->id;
366         lvItem.iSubItem = 0;
367         lvItem.pszText = iter->title;
368         lvItem.iImage = index;
369         lvItem.lParam = iter->id;
370 
371         index = ListView_InsertItemW(hWnd, &lvItem);
372 
373         /* now add the subitems (columns) */
374         ListView_SetItemTextW(hWnd, index, 1, iter->publisher);
375         ListView_SetItemTextW(hWnd, index, 2, iter->version);
376     }
377 }
378 
379 /******************************************************************************
380  * Name       : RemoveItemsFromList
381  * Description: Clears the application list box.
382  * Parameters : hWnd    - Handle of the dialog box
383  */
384 static void RemoveItemsFromList(HWND hWnd)
385 {
386     SendDlgItemMessageW(hWnd, IDL_PROGRAMS, LVM_DELETEALLITEMS, 0, 0);
387 }
388 
389 /******************************************************************************
390  * Name       : EmptyList
391  * Description: Frees memory used by the application linked list.
392  */
393 static inline void EmptyList(void)
394 {
395     FreeAppInfo(AppInfo);
396     AppInfo = NULL;
397 }
398 
399 /******************************************************************************
400  * Name       : UpdateButtons
401  * Description: Enables/disables the Add/Remove button depending on current
402  *              selection in list box.
403  * Parameters : hWnd    - Handle of the dialog box
404  */
405 static void UpdateButtons(HWND hWnd)
406 {
407     APPINFO *iter;
408     LVITEMW lvItem;
409     DWORD selitem = SendDlgItemMessageW(hWnd, IDL_PROGRAMS, LVM_GETNEXTITEM, -1,
410        LVNI_FOCUSED | LVNI_SELECTED);
411     BOOL enable_modify = FALSE;
412 
413     if (selitem != -1)
414     {
415         lvItem.iItem = selitem;
416         lvItem.mask = LVIF_PARAM;
417 
418         if (SendDlgItemMessageW(hWnd, IDL_PROGRAMS, LVM_GETITEMW, 0, (LPARAM) &lvItem))
419         {
420             for (iter = AppInfo; iter; iter = iter->next)
421             {
422                 if (iter->id == lvItem.lParam)
423                 {
424                     /* Decide whether to display Modify/Remove as one button or two */
425                     enable_modify = (iter->path_modify != NULL);
426 
427                     /* Update title as appropriate */
428                     if (iter->path_modify == NULL)
429                         SetWindowTextW(GetDlgItem(hWnd, IDC_ADDREMOVE), btnModifyRemove);
430                     else
431                         SetWindowTextW(GetDlgItem(hWnd, IDC_ADDREMOVE), btnRemove);
432 
433                     break;
434                 }
435             }
436         }
437     }
438 
439     /* Enable/disable other buttons if necessary */
440     EnableWindow(GetDlgItem(hWnd, IDC_ADDREMOVE), (selitem != -1));
441     EnableWindow(GetDlgItem(hWnd, IDC_SUPPORT_INFO), (selitem != -1));
442     EnableWindow(GetDlgItem(hWnd, IDC_MODIFY), enable_modify);
443 }
444 
445 /******************************************************************************
446  * Name       : InstallProgram
447  * Description: Search for potential Installer and execute it.
448  * Parameters : hWnd    - Handle of the dialog box
449  */
450 static void InstallProgram(HWND hWnd)
451 {
452     OPENFILENAMEW ofn;
453     WCHAR titleW[MAX_STRING_LEN];
454     WCHAR FilterBufferW[MAX_STRING_LEN];
455     WCHAR FileNameBufferW[MAX_PATH];
456 
457     LoadStringW(hInst, IDS_CPL_TITLE, titleW, sizeof(titleW)/sizeof(WCHAR));
458     LoadStringW(hInst, IDS_INSTALL_FILTER, FilterBufferW, sizeof(FilterBufferW)/sizeof(WCHAR));
459 
460     memset(&ofn, 0, sizeof(OPENFILENAMEW));
461     ofn.lStructSize = sizeof(OPENFILENAMEW);
462     ofn.hwndOwner = hWnd;
463     ofn.hInstance = hInst;
464     ofn.lpstrFilter = FilterBufferW;
465     ofn.nFilterIndex = 0;
466     ofn.lpstrFile = FileNameBufferW;
467     ofn.nMaxFile = MAX_PATH;
468     ofn.lpstrFileTitle = NULL;
469     ofn.nMaxFileTitle = 0;
470     ofn.lpstrTitle = titleW;
471     ofn.Flags = OFN_HIDEREADONLY | OFN_ENABLESIZING;
472     FileNameBufferW[0] = 0;
473 
474     if (GetOpenFileNameW(&ofn))
475     {
476         SHELLEXECUTEINFOW sei;
477         memset(&sei, 0, sizeof(sei));
478         sei.cbSize = sizeof(sei);
479         sei.lpVerb = openW;
480         sei.nShow = SW_SHOWDEFAULT;
481         sei.fMask = SEE_MASK_NO_CONSOLE;
482         sei.lpFile = ofn.lpstrFile;
483 
484         ShellExecuteExW(&sei);
485     }
486 }
487 
488 /******************************************************************************
489  * Name       : UninstallProgram
490  * Description: Executes the specified program's installer.
491  * Parameters : id      - the internal ID of the installer to remove
492  * Parameters : button  - ID of button pressed (Modify or Remove)
493  */
494 static void UninstallProgram(int id, DWORD button)
495 {
496     APPINFO *iter;
497     STARTUPINFOW si;
498     PROCESS_INFORMATION info;
499     WCHAR errormsg[MAX_STRING_LEN];
500     WCHAR sUninstallFailed[MAX_STRING_LEN];
501     HKEY hkey;
502     BOOL res;
503 
504     LoadStringW(hInst, IDS_UNINSTALL_FAILED, sUninstallFailed,
505         sizeof(sUninstallFailed) / sizeof(sUninstallFailed[0]));
506 
507     for (iter = AppInfo; iter; iter = iter->next)
508     {
509         if (iter->id == id)
510         {
511             TRACE("Uninstalling %s (%s)\n", wine_dbgstr_w(iter->title),
512                 wine_dbgstr_w(iter->path));
513 
514             memset(&si, 0, sizeof(STARTUPINFOW));
515             si.cb = sizeof(STARTUPINFOW);
516             si.wShowWindow = SW_NORMAL;
517 
518             res = CreateProcessW(NULL, (button == IDC_MODIFY) ? iter->path_modify : iter->path,
519                 NULL, NULL, FALSE, 0, NULL, NULL, &si, &info);
520 
521             if (res)
522             {
523                 CloseHandle(info.hThread);
524 
525                 /* wait for the process to exit */
526                 WaitForSingleObject(info.hProcess, INFINITE);
527                 CloseHandle(info.hProcess);
528             }
529             else
530             {
531                 wsprintfW(errormsg, sUninstallFailed, iter->path);
532 
533                 if (MessageBoxW(0, errormsg, iter->title, MB_YESNO |
534                     MB_ICONQUESTION) == IDYES)
535                 {
536                     /* delete the application's uninstall entry */
537                     RegOpenKeyExW(iter->regroot, PathUninstallW, 0, KEY_READ, &hkey);
538                     RegDeleteKeyW(hkey, iter->regkey);
539                     RegCloseKey(hkey);
540                 }
541             }
542 
543             break;
544         }
545     }
546 }
547 
548 /**********************************************************************************
549  * Name       : SetInfoDialogText
550  * Description: Sets the text of a label in a window, based upon a registry entry
551  *              or string passed to the function.
552  * Parameters : hKey         - registry entry to read from, NULL if not reading
553  *                             from registry
554  *              lpKeyName    - key to read from, or string to check if hKey is NULL
555  *              lpAltMessage - alternative message if entry not found
556  *              hWnd         - handle of dialog box
557  *              iDlgItem     - ID of label in dialog box
558  */
559 static void SetInfoDialogText(HKEY hKey, LPWSTR lpKeyName, LPWSTR lpAltMessage,
560   HWND hWnd, int iDlgItem)
561 {
562     WCHAR buf[MAX_STRING_LEN];
563     DWORD buflen;
564     HWND hWndDlgItem;
565 
566     hWndDlgItem = GetDlgItem(hWnd, iDlgItem);
567 
568     /* if hKey is null, lpKeyName contains the string we want to check */
569     if (hKey == NULL)
570     {
571         if ((lpKeyName) && (lstrlenW(lpKeyName) > 0))
572             SetWindowTextW(hWndDlgItem, lpKeyName);
573         else
574             SetWindowTextW(hWndDlgItem, lpAltMessage);
575     }
576     else
577     {
578         buflen = MAX_STRING_LEN;
579 
580         if ((RegQueryValueExW(hKey, lpKeyName, 0, 0, (LPBYTE) buf, &buflen) ==
581            ERROR_SUCCESS) && (lstrlenW(buf) > 0))
582             SetWindowTextW(hWndDlgItem, buf);
583         else
584             SetWindowTextW(hWndDlgItem, lpAltMessage);
585     }
586 }
587 
588 /******************************************************************************
589  * Name       : SupportInfoDlgProc
590  * Description: Callback procedure for support info dialog
591  * Parameters : hWnd    - hWnd of the window
592  *              msg     - reason for calling function
593  *              wParam  - additional parameter
594  *              lParam  - additional parameter
595  * Returns    : Dependant on message
596  */
597 static BOOL CALLBACK SupportInfoDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
598 {
599     APPINFO *iter;
600     HKEY hkey;
601     WCHAR oldtitle[MAX_STRING_LEN];
602     WCHAR buf[MAX_STRING_LEN];
603     WCHAR key[MAX_STRING_LEN];
604     WCHAR notfound[MAX_STRING_LEN];
605 
606     switch(msg)
607     {
608         case WM_INITDIALOG:
609             for (iter = AppInfo; iter; iter = iter->next)
610             {
611                 if (iter->id == (int) lParam)
612                 {
613                     lstrcpyW(key, PathUninstallW);
614                     lstrcatW(key, BackSlashW);
615                     lstrcatW(key, iter->regkey);
616 
617                     /* check the application's registry entries */
618                     RegOpenKeyExW(iter->regroot, key, 0, KEY_READ, &hkey);
619 
620                     /* Load our "not specified" string */
621                     LoadStringW(hInst, IDS_NOT_SPECIFIED, notfound,
622                         sizeof(notfound) / sizeof(notfound[0]));
623 
624                     /* Update the data for items already read into the structure */
625                     SetInfoDialogText(NULL, iter->publisher, notfound, hWnd,
626                         IDC_INFO_PUBLISHER);
627                     SetInfoDialogText(NULL, iter->version, notfound, hWnd,
628                         IDC_INFO_VERSION);
629 
630                     /* And now update the data for those items in the registry */
631                     SetInfoDialogText(hkey, (LPWSTR) ContactW, notfound, hWnd,
632                         IDC_INFO_CONTACT);
633                     SetInfoDialogText(hkey, (LPWSTR) HelpLinkW, notfound, hWnd,
634                         IDC_INFO_SUPPORT);
635                     SetInfoDialogText(hkey, (LPWSTR) HelpTelephoneW, notfound, hWnd,
636                         IDC_INFO_PHONE);
637                     SetInfoDialogText(hkey, (LPWSTR) ReadmeW, notfound, hWnd,
638                         IDC_INFO_README);
639                     SetInfoDialogText(hkey, (LPWSTR) URLUpdateInfoW, notfound, hWnd,
640                         IDC_INFO_UPDATES);
641                     SetInfoDialogText(hkey, (LPWSTR) CommentsW, notfound, hWnd,
642                         IDC_INFO_COMMENTS);
643 
644                     /* Update the main label with the app name */
645                     if (GetWindowTextW(GetDlgItem(hWnd, IDC_INFO_LABEL), oldtitle,
646                         MAX_STRING_LEN) != 0)
647                     {
648                         wsprintfW(buf, oldtitle, iter->title);
649                         SetWindowTextW(GetDlgItem(hWnd, IDC_INFO_LABEL), buf);
650                     }
651 
652                     RegCloseKey(hkey);
653 
654                     break;
655                 }
656             }
657 
658             return TRUE;
659 
660         case WM_DESTROY:
661             return 0;
662 
663         case WM_COMMAND:
664             switch (LOWORD(wParam))
665             {
666                 case IDOK:
667                     EndDialog(hWnd, TRUE);
668                     break;
669 
670             }
671 
672             return TRUE;
673     }
674 
675     return FALSE;
676 }
677 
678 /******************************************************************************
679  * Name       : SupportInfo
680  * Description: Displays the Support Information dialog
681  * Parameters : hWnd    - Handle of the main dialog
682  *              id      - ID of the application to display information for
683  */
684 static void SupportInfo(HWND hWnd, int id)
685 {
686     DialogBoxParamW(hInst, MAKEINTRESOURCEW(IDD_INFO), hWnd, (DLGPROC)
687         SupportInfoDlgProc, (LPARAM) id);
688 }
689 
690 /* Definition of column headers for AddListViewColumns function */
691 typedef struct AppWizColumn {
692    int width;
693    int fmt;
694    int title;
695 } AppWizColumn;
696 
697 static const AppWizColumn columns[] = {
698     {200, LVCFMT_LEFT, IDS_COLUMN_NAME},
699     {150, LVCFMT_LEFT, IDS_COLUMN_PUBLISHER},
700     {100, LVCFMT_LEFT, IDS_COLUMN_VERSION},
701 };
702 
703 /******************************************************************************
704  * Name       : AddListViewColumns
705  * Description: Adds column headers to the list view control.
706  * Parameters : hWnd    - Handle of the list view control.
707  * Returns    : TRUE if completed successfully, FALSE otherwise.
708  */
709 static BOOL AddListViewColumns(HWND hWnd)
710 {
711     WCHAR buf[MAX_STRING_LEN];
712     LVCOLUMNW lvc;
713     UINT i;
714 
715     lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
716 
717     /* Add the columns */
718     for (i = 0; i < sizeof(columns) / sizeof(columns[0]); i++)
719     {
720         lvc.iSubItem = i;
721         lvc.pszText = buf;
722 
723         /* set width and format */
724         lvc.cx = columns[i].width;
725         lvc.fmt = columns[i].fmt;
726 
727         LoadStringW(hInst, columns[i].title, buf, sizeof(buf) / sizeof(buf[0]));
728 
729         if (ListView_InsertColumnW(hWnd, i, &lvc) == -1)
730             return FALSE;
731     }
732 
733     return TRUE;
734 }
735 
736 /******************************************************************************
737  * Name       : AddListViewImageList
738  * Description: Creates an ImageList for the list view control.
739  * Parameters : hWnd    - Handle of the list view control.
740  * Returns    : Handle of the image list.
741  */
742 static HIMAGELIST AddListViewImageList(HWND hWnd)
743 {
744     HIMAGELIST hSmall;
745     HICON hDefaultIcon;
746 
747     hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
748         ILC_MASK, 1, 1);
749 
750     /* Add default icon to image list */
751     hDefaultIcon = LoadIconW(hInst, MAKEINTRESOURCEW(ICO_MAIN));
752     ImageList_AddIcon(hSmall, hDefaultIcon);
753     DestroyIcon(hDefaultIcon);
754 
755     SendMessageW(hWnd, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)hSmall);
756 
757     return hSmall;
758 }
759 
760 /******************************************************************************
761  * Name       : ResetApplicationList
762  * Description: Empties the app list, if need be, and recreates it.
763  * Parameters : bFirstRun  - TRUE if this is the first time this is run, FALSE otherwise
764  *              hWnd       - handle of the dialog box
765  *              hImageList - handle of the image list
766  * Returns    : New handle of the image list.
767  */
768 static HIMAGELIST ResetApplicationList(BOOL bFirstRun, HWND hWnd, HIMAGELIST hImageList)
769 {
770     HWND hWndListView;
771 
772     hWndListView = GetDlgItem(hWnd, IDL_PROGRAMS);
773 
774     /* if first run, create the image list and add the listview columns */
775     if (bFirstRun)
776     {
777         if (!AddListViewColumns(hWndListView))
778             return NULL;
779     }
780     else /* we need to remove the existing things first */
781     {
782         RemoveItemsFromList(hWnd);
783         ImageList_Destroy(hImageList);
784 
785         /* reset the list, since it's probably changed if the uninstallation was
786            successful */
787         EmptyList();
788     }
789 
790     /* now create the image list and add the applications to the listview */
791     hImageList = AddListViewImageList(hWndListView);
792 
793     ReadApplicationsFromRegistry(HKEY_LOCAL_MACHINE);
794     ReadApplicationsFromRegistry(HKEY_CURRENT_USER);
795 
796     AddApplicationsToList(hWndListView, hImageList);
797     UpdateButtons(hWnd);
798 
799     return(hImageList);
800 }
801 
802 /******************************************************************************
803  * Name       : MainDlgProc
804  * Description: Callback procedure for main tab
805  * Parameters : hWnd    - hWnd of the window
806  *              msg     - reason for calling function
807  *              wParam  - additional parameter
808  *              lParam  - additional parameter
809  * Returns    : Dependant on message
810  */
811 static BOOL CALLBACK MainDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
812 {
813     int selitem;
814     static HIMAGELIST hImageList;
815     LPNMHDR nmh;
816     LVITEMW lvItem;
817 
818     switch(msg)
819     {
820         case WM_INITDIALOG:
821             hImageList = ResetApplicationList(TRUE, hWnd, hImageList);
822 
823             if (!hImageList)
824                 return FALSE;
825 
826             return TRUE;
827 
828         case WM_DESTROY:
829             RemoveItemsFromList(hWnd);
830             ImageList_Destroy(hImageList);
831 
832             EmptyList();
833 
834             return 0;
835 
836         case WM_NOTIFY:
837             nmh = (LPNMHDR) lParam;
838 
839             switch (nmh->idFrom)
840             {
841                 case IDL_PROGRAMS:
842                     switch (nmh->code)
843                     {
844                         case LVN_ITEMCHANGED:
845                             UpdateButtons(hWnd);
846                             break;
847                     }
848                     break;
849             }
850 
851             return TRUE;
852 
853         case WM_COMMAND:
854             switch (LOWORD(wParam))
855             {
856                 case IDC_INSTALL:
857                     InstallProgram(hWnd);
858                     break;
859 
860                 case IDC_ADDREMOVE:
861                 case IDC_MODIFY:
862                     selitem = SendDlgItemMessageW(hWnd, IDL_PROGRAMS,
863                         LVM_GETNEXTITEM, -1, LVNI_FOCUSED|LVNI_SELECTED);
864 
865                     if (selitem != -1)
866                     {
867                         lvItem.iItem = selitem;
868                         lvItem.mask = LVIF_PARAM;
869 
870                         if (SendDlgItemMessageW(hWnd, IDL_PROGRAMS, LVM_GETITEMW,
871                           0, (LPARAM) &lvItem))
872                             UninstallProgram(lvItem.lParam, LOWORD(wParam));
873                     }
874 
875                     hImageList = ResetApplicationList(FALSE, hWnd, hImageList);
876 
877                     break;
878 
879                 case IDC_SUPPORT_INFO:
880                     selitem = SendDlgItemMessageW(hWnd, IDL_PROGRAMS,
881                         LVM_GETNEXTITEM, -1, LVNI_FOCUSED | LVNI_SELECTED);
882 
883                     if (selitem != -1)
884                     {
885                         lvItem.iItem = selitem;
886                         lvItem.mask = LVIF_PARAM;
887 
888                         if (SendDlgItemMessageW(hWnd, IDL_PROGRAMS, LVM_GETITEMW,
889                           0, (LPARAM) &lvItem))
890                             SupportInfo(hWnd, lvItem.lParam);
891                     }
892 
893                     break;
894             }
895 
896             return TRUE;
897     }
898 
899     return FALSE;
900 }
901 
902 /******************************************************************************
903  * Name       : StartApplet
904  * Description: Main routine for applet
905  * Parameters : hWnd    - hWnd of the Control Panel
906  */
907 static void StartApplet(HWND hWnd)
908 {
909     PROPSHEETPAGEW psp;
910     PROPSHEETHEADERW psh;
911     WCHAR tab_title[MAX_STRING_LEN], app_title[MAX_STRING_LEN];
912 
913     /* Load the strings we will use */
914     LoadStringW(hInst, IDS_TAB1_TITLE, tab_title, sizeof(tab_title) / sizeof(tab_title[0]));
915     LoadStringW(hInst, IDS_CPL_TITLE, app_title, sizeof(app_title) / sizeof(app_title[0]));
916     LoadStringW(hInst, IDS_REMOVE, btnRemove, sizeof(btnRemove) / sizeof(btnRemove[0]));
917     LoadStringW(hInst, IDS_MODIFY_REMOVE, btnModifyRemove, sizeof(btnModifyRemove) / sizeof(btnModifyRemove[0]));
918 
919     /* Fill out the PROPSHEETPAGE */
920     psp.dwSize = sizeof (PROPSHEETPAGEW);
921     psp.dwFlags = PSP_USETITLE;
922     psp.hInstance = hInst;
923     psp.u.pszTemplate = MAKEINTRESOURCEW (IDD_MAIN);
924     psp.u2.pszIcon = NULL;
925     psp.pfnDlgProc = (DLGPROC) MainDlgProc;
926     psp.pszTitle = tab_title;
927     psp.lParam = 0;
928 
929     /* Fill out the PROPSHEETHEADER */
930     psh.dwSize = sizeof (PROPSHEETHEADERW);
931     psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USEICONID;
932     psh.hwndParent = hWnd;
933     psh.hInstance = hInst;
934     psh.u.pszIcon = NULL;
935     psh.pszCaption = app_title;
936     psh.nPages = 1;
937     psh.u3.ppsp = &psp;
938     psh.pfnCallback = NULL;
939     psh.u2.nStartPage = 0;
940 
941     /* Display the property sheet */
942     PropertySheetW (&psh);
943 }
944 
945 /******************************************************************************
946  * Name       : CPlApplet
947  * Description: Entry point for Control Panel applets
948  * Parameters : hwndCPL - hWnd of the Control Panel
949  *              message - reason for calling function
950  *              lParam1 - additional parameter
951  *              lParam2 - additional parameter
952  * Returns    : Dependant on message
953  */
954 LONG CALLBACK CPlApplet(HWND hwndCPL, UINT message, LPARAM lParam1, LPARAM lParam2)
955 {
956     INITCOMMONCONTROLSEX iccEx;
957 
958     switch (message)
959     {
960         case CPL_INIT:
961             iccEx.dwSize = sizeof(iccEx);
962             iccEx.dwICC = ICC_LISTVIEW_CLASSES | ICC_TAB_CLASSES;
963 
964             InitCommonControlsEx(&iccEx);
965 
966             return TRUE;
967 
968         case CPL_GETCOUNT:
969             return 1;
970 
971         case CPL_INQUIRE:
972         {
973             CPLINFO *appletInfo = (CPLINFO *) lParam2;
974 
975             appletInfo->idIcon = ICO_MAIN;
976             appletInfo->idName = IDS_CPL_TITLE;
977             appletInfo->idInfo = IDS_CPL_DESC;
978             appletInfo->lData = 0;
979 
980             break;
981         }
982 
983         case CPL_DBLCLK:
984             StartApplet(hwndCPL);
985             break;
986     }
987 
988     return FALSE;
989 }
990 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.