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
27 #include "wine/port.h"
28 #include "wine/unicode.h"
29 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(appwizcpl
);
48 /* define a maximum length for various buffers we use */
49 #define MAX_STRING_LEN 1024
51 static HINSTANCE hInst
;
53 /******************************************************************************
55 * Description: Entry point for DLL file
57 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
,
60 TRACE("(%p, %d, %p)\n", hinstDLL
, fdwReason
, lpvReserved
);
64 case DLL_PROCESS_ATTACH
:
71 /******************************************************************************
72 * Name : UpdateButtons
73 * Description: Enables/disables the Add/Remove button depending on current
74 * selection in list box.
75 * Parameters : hWnd - Handle of the dialog box
77 static void UpdateButtons(HWND hWnd
)
79 BOOL sel
= ListView_GetSelectedCount(GetDlgItem(hWnd
, IDL_PROGRAMS
)) != 0;
81 EnableWindow(GetDlgItem(hWnd
, IDC_ADDREMOVE
), sel
);
82 EnableWindow(GetDlgItem(hWnd
, IDC_SUPPORT_INFO
), sel
);
85 /* Definition of column headers for AddListViewColumns function */
86 typedef struct AppWizColumn
{
92 AppWizColumn columns
[] = {
93 {200, LVCFMT_LEFT
, IDS_COLUMN_NAME
},
94 {150, LVCFMT_LEFT
, IDS_COLUMN_PUBLISHER
},
95 {100, LVCFMT_LEFT
, IDS_COLUMN_VERSION
},
98 /******************************************************************************
99 * Name : AddListViewColumns
100 * Description: Adds column headers to the list view control.
101 * Parameters : hWnd - Handle of the list view control.
102 * Returns : TRUE if completed successfully, FALSE otherwise.
104 static BOOL
AddListViewColumns(HWND hWnd
)
106 WCHAR buf
[MAX_STRING_LEN
];
110 lvc
.mask
= LVCF_FMT
| LVCF_TEXT
| LVCF_SUBITEM
| LVCF_WIDTH
;
112 /* Add the columns */
113 for (i
= 0; i
< sizeof(columns
) / sizeof(columns
[0]); i
++)
118 /* set width and format */
119 lvc
.cx
= columns
[i
].width
;
120 lvc
.fmt
= columns
[i
].fmt
;
122 LoadStringW(hInst
, columns
[i
].title
, buf
, sizeof(buf
) / sizeof(buf
[0]));
124 if (ListView_InsertColumnW(hWnd
, i
, &lvc
) == -1)
131 /******************************************************************************
132 * Name : AddListViewImageList
133 * Description: Creates an ImageList for the list view control.
134 * Parameters : hWnd - Handle of the list view control.
135 * Returns : Handle of the image list.
137 static HIMAGELIST
AddListViewImageList(HWND hWnd
)
142 hSmall
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
145 /* Add default icon to image list */
146 hDefaultIcon
= LoadIconW(hInst
, MAKEINTRESOURCEW(ICO_MAIN
));
147 ImageList_AddIcon(hSmall
, hDefaultIcon
);
148 DestroyIcon(hDefaultIcon
);
150 (void) ListView_SetImageList(hWnd
, hSmall
, LVSIL_SMALL
);
155 /******************************************************************************
156 * Name : ResetApplicationList
157 * Description: Empties the app list, if need be, and recreates it.
158 * Parameters : bFirstRun - TRUE if this is the first time this is run, FALSE otherwise
159 * hWnd - handle of the dialog box
160 * hImageList - handle of the image list
161 * Returns : New handle of the image list.
163 static HIMAGELIST
ResetApplicationList(BOOL bFirstRun
, HWND hWnd
, HIMAGELIST hImageList
)
167 hWndListView
= GetDlgItem(hWnd
, IDL_PROGRAMS
);
169 /* if first run, create the image list and add the listview columns */
172 if (!AddListViewColumns(hWndListView
))
175 else /* we need to remove the existing things first */
177 ImageList_Destroy(hImageList
);
180 /* now create the image list and add the applications to the listview */
181 hImageList
= AddListViewImageList(hWndListView
);
188 /******************************************************************************
190 * Description: Callback procedure for main tab
191 * Parameters : hWnd - hWnd of the window
192 * msg - reason for calling function
193 * wParam - additional parameter
194 * lParam - additional parameter
195 * Returns : Dependant on message
197 static BOOL CALLBACK
MainDlgProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
199 static HIMAGELIST hImageList
;
204 hImageList
= ResetApplicationList(TRUE
, hWnd
, hImageList
);
212 ImageList_Destroy(hImageList
);
220 /******************************************************************************
222 * Description: Main routine for applet
223 * Parameters : hWnd - hWnd of the Control Panel
225 static void StartApplet(HWND hWnd
)
228 PROPSHEETHEADERW psh
;
229 WCHAR tab_title
[MAX_STRING_LEN
], app_title
[MAX_STRING_LEN
];
231 /* Load the strings we will use */
232 LoadStringW(hInst
, IDS_TAB1_TITLE
, tab_title
, sizeof(tab_title
) / sizeof(tab_title
[0]));
233 LoadStringW(hInst
, IDS_CPL_TITLE
, app_title
, sizeof(app_title
) / sizeof(app_title
[0]));
235 /* Fill out the PROPSHEETPAGE */
236 psp
.dwSize
= sizeof (PROPSHEETPAGEW
);
237 psp
.dwFlags
= PSP_USETITLE
;
238 psp
.hInstance
= hInst
;
239 psp
.pszTemplate
= MAKEINTRESOURCEW (IDD_MAIN
);
241 psp
.pfnDlgProc
= (DLGPROC
) MainDlgProc
;
242 psp
.pszTitle
= tab_title
;
245 /* Fill out the PROPSHEETHEADER */
246 psh
.dwSize
= sizeof (PROPSHEETHEADERW
);
247 psh
.dwFlags
= PSH_PROPSHEETPAGE
| PSH_USEICONID
;
248 psh
.hwndParent
= hWnd
;
249 psh
.hInstance
= hInst
;
251 psh
.pszCaption
= app_title
;
254 psh
.pfnCallback
= NULL
;
257 /* Display the property sheet */
258 PropertySheetW (&psh
);
261 /******************************************************************************
263 * Description: Entry point for Control Panel applets
264 * Parameters : hwndCPL - hWnd of the Control Panel
265 * message - reason for calling function
266 * lParam1 - additional parameter
267 * lParam2 - additional parameter
268 * Returns : Dependant on message
270 LONG CALLBACK
CPlApplet(HWND hwndCPL
, UINT message
, LPARAM lParam1
, LPARAM lParam2
)
272 INITCOMMONCONTROLSEX iccEx
;
277 iccEx
.dwSize
= sizeof(iccEx
);
278 iccEx
.dwICC
= ICC_LISTVIEW_CLASSES
| ICC_TAB_CLASSES
;
280 InitCommonControlsEx(&iccEx
);
289 CPLINFO
*appletInfo
= (CPLINFO
*) lParam2
;
291 appletInfo
->idIcon
= ICO_MAIN
;
292 appletInfo
->idName
= IDS_CPL_TITLE
;
293 appletInfo
->idInfo
= IDS_CPL_DESC
;
294 appletInfo
->lData
= 0;
300 StartApplet(hwndCPL
);