2 * ReactOS New devices installation
3 * Copyright (C) 2005, 2008 ReactOS Team
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * PROJECT: ReactOS Add hardware control panel
21 * FILE: dll/cpl/hdwwiz/hdwwiz.c
22 * PURPOSE: ReactOS Add hardware control panel
23 * PROGRAMMER: Hervé Poussineau (hpoussin@reactos.org)
24 * Dmitry Chapyshev (dmitry@reactos.org)
30 /* GLOBALS ******************************************************************/
32 HINSTANCE hApplet
= NULL
;
34 SP_CLASSIMAGELIST_DATA ImageListData
;
36 typedef BOOL (WINAPI
*PINSTALL_NEW_DEVICE
)(HWND
, LPGUID
, PDWORD
);
39 /* STATIC FUNCTIONS *********************************************************/
50 ncm
.cbSize
= sizeof(NONCLIENTMETRICS
);
51 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, 0, &ncm
, 0);
53 LogFont
= ncm
.lfMessageFont
;
54 LogFont
.lfWeight
= FW_BOLD
;
55 _tcscpy(LogFont
.lfFaceName
, _T("MS Shell Dlg"));
59 LogFont
.lfHeight
= 0 - GetDeviceCaps (hdc
, LOGPIXELSY
) * FontSize
/ 72;
60 hFont
= CreateFontIndirect(&LogFont
);
66 static INT_PTR CALLBACK
67 StartPageDlgProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
74 SendDlgItemMessage(hwndDlg
, IDC_FINISHTITLE
, WM_SETFONT
, (WPARAM
)hTitleFont
, (LPARAM
)TRUE
);
82 static INT_PTR CALLBACK
83 SearchPageDlgProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
88 static INT_PTR CALLBACK
89 IsConnctedPageDlgProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
95 if(HIWORD(wParam
) == BN_CLICKED
)
97 if ((SendDlgItemMessage(hwndDlg
, IDC_CONNECTED
, BM_GETCHECK
, 0, 0) == BST_CHECKED
) ||
98 (SendDlgItemMessage(hwndDlg
, IDC_NOTCONNECTED
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
100 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
| PSWIZB_BACK
);
104 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
);
112 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
118 if ((SendDlgItemMessage(hwndDlg
, IDC_CONNECTED
, BM_GETCHECK
, 0, 0) == BST_CHECKED
) ||
119 (SendDlgItemMessage(hwndDlg
, IDC_NOTCONNECTED
, BM_GETCHECK
, 0, 0) == BST_CHECKED
))
121 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_NEXT
| PSWIZB_BACK
);
125 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
);
132 if (SendDlgItemMessage(hwndDlg
, IDC_NOTCONNECTED
, BM_GETCHECK
, 0, 0) == BST_CHECKED
)
133 SetWindowLong(hwndDlg
, DWL_MSGRESULT
, IDD_NOTCONNECTEDPAGE
);
135 SetWindowLong(hwndDlg
, DWL_MSGRESULT
, IDD_PROBELISTPAGE
);
147 static INT_PTR CALLBACK
148 FinishPageDlgProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
155 SendDlgItemMessage(hwndDlg
, IDC_FINISHTITLE
, WM_SETFONT
, (WPARAM
)hTitleFont
, (LPARAM
)TRUE
);
161 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
167 /* Only "Finish" button */
168 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_FINISH
);
179 static INT_PTR CALLBACK
180 NotConnectedPageDlgProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
187 SendDlgItemMessage(hwndDlg
, IDC_FINISHTITLE
, WM_SETFONT
, (WPARAM
)hTitleFont
, (LPARAM
)TRUE
);
193 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
199 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_FINISH
| PSWIZB_BACK
);
205 SetWindowLong(hwndDlg
, DWL_MSGRESULT
, IDD_ISCONNECTEDPAGE
);
217 TrimGuidString(LPWSTR szString
, LPWSTR szNewString
)
222 if (wcslen(szString
) == 38)
224 if ((szString
[0] == L
'{') && (szString
[37] == L
'}'))
226 for (Index
= 0; Index
< wcslen(szString
); Index
++)
227 szBuffer
[Index
] = szString
[Index
+ 1];
229 szBuffer
[36] = L
'\0';
230 wcscpy(szNewString
, szBuffer
);
234 wcscpy(szNewString
, L
"\0");
238 InitProbeListPage(HWND hwndDlg
)
242 WCHAR szBuffer
[MAX_STR_SIZE
], szGuid
[MAX_STR_SIZE
], szTrimGuid
[MAX_STR_SIZE
];
243 HWND hList
= GetDlgItem(hwndDlg
, IDC_PROBELIST
);
245 SP_DEVINFO_DATA DevInfoData
;
246 ULONG ulStatus
, ulProblemNumber
;
253 ZeroMemory(&Column
, sizeof(LV_COLUMN
));
255 GetClientRect(hList
, &Rect
);
257 Column
.mask
= LVCF_FMT
| LVCF_TEXT
| LVCF_WIDTH
;
258 Column
.fmt
= LVCFMT_LEFT
;
260 Column
.pszText
= NULL
;
261 Column
.cx
= Rect
.right
- GetSystemMetrics(SM_CXVSCROLL
);
262 (VOID
) ListView_InsertColumn(hList
, 0, &Column
);
264 ZeroMemory(&Item
, sizeof(LV_ITEM
));
266 LoadString(hApplet
, IDS_ADDNEWDEVICE
, szBuffer
, sizeof(szBuffer
) / sizeof(WCHAR
));
268 Item
.mask
= LVIF_TEXT
| LVIF_PARAM
| LVIF_STATE
| LVIF_IMAGE
;
269 Item
.pszText
= (LPTSTR
) szBuffer
;
272 (VOID
) ListView_InsertItem(hList
, &Item
);
274 (VOID
) ListView_SetExtendedListViewStyle(hList
, LVS_EX_FULLROWSELECT
);
276 hDevInfo
= SetupDiGetClassDevsEx(NULL
, NULL
, NULL
, DIGCF_ALLCLASSES
| DIGCF_PRESENT
, NULL
, NULL
, 0);
278 if (hDevInfo
== INVALID_HANDLE_VALUE
) return;
280 /* get the device image List */
281 ImageListData
.cbSize
= sizeof(ImageListData
);
282 SetupDiGetClassImageList(&ImageListData
);
284 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
285 for (Index
= 0; TRUE
; Index
++)
287 if (!SetupDiEnumDeviceInfo(hDevInfo
, Index
, &DevInfoData
)) break;
289 if (CM_Get_DevNode_Status_Ex(&ulStatus
, &ulProblemNumber
, DevInfoData
.DevInst
, 0, NULL
) == CR_SUCCESS
)
291 if (ulStatus
& DN_NO_SHOW_IN_DM
) continue;
294 /* get the device's friendly name */
295 if (!SetupDiGetDeviceRegistryProperty(hDevInfo
,
303 /* if the friendly name fails, try the description instead */
304 SetupDiGetDeviceRegistryProperty(hDevInfo
,
313 SetupDiGetDeviceRegistryProperty(hDevInfo
,
321 TrimGuidString(szGuid
, szTrimGuid
);
322 UuidFromStringW(szTrimGuid
, &ClassGuid
);
324 SetupDiGetClassImageIndex(&ImageListData
,
328 /* Set device name */
329 Item
.pszText
= (LPTSTR
) szBuffer
;
330 Item
.mask
= LVIF_TEXT
| LVIF_PARAM
| LVIF_IMAGE
;
331 Item
.iItem
= (INT
) ListView_GetItemCount(hList
);
332 (VOID
) ListView_InsertItem(hList
, &Item
);
334 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
337 (VOID
) ListView_SetImageList(hList
, ImageListData
.ImageList
, LVSIL_SMALL
);
338 SetupDiDestroyDeviceInfoList(hDevInfo
);
341 static INT_PTR CALLBACK
342 ProbeListPageDlgProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
348 InitProbeListPage(hwndDlg
);
360 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
366 PropSheet_SetWizButtons(GetParent(hwndDlg
), PSWIZB_BACK
);
372 SetWindowLong(hwndDlg
, DWL_MSGRESULT
, IDD_FINISHPAGE
);
384 HardwareWizardInit(HWND hwnd
)
386 HPROPSHEETPAGE ahpsp
[5];
387 PROPSHEETPAGE psp
= {0};
391 /* Create the Start page, until setup is working */
392 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
393 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
394 psp
.hInstance
= hApplet
;
396 psp
.pfnDlgProc
= StartPageDlgProc
;
397 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_STARTPAGE
);
398 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
400 /* Create search page */
401 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
402 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
403 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_SEARCHTITLE
);
404 psp
.pszHeaderSubTitle
= NULL
;
405 psp
.hInstance
= hApplet
;
407 psp
.pfnDlgProc
= SearchPageDlgProc
;
408 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_SEARCHPAGE
);
409 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
411 /* Create is connected page */
412 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
413 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
414 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_ISCONNECTED
);
415 psp
.pszHeaderSubTitle
= NULL
;
416 psp
.hInstance
= hApplet
;
418 psp
.pfnDlgProc
= IsConnctedPageDlgProc
;
419 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_ISCONNECTEDPAGE
);
420 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
422 /* Create probe list page */
423 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
424 psp
.dwFlags
= PSP_DEFAULT
| PSP_USEHEADERTITLE
| PSP_USEHEADERSUBTITLE
;
425 psp
.pszHeaderTitle
= MAKEINTRESOURCE(IDS_PROBELISTTITLE
);
426 psp
.pszHeaderSubTitle
= NULL
;
427 psp
.hInstance
= hApplet
;
429 psp
.pfnDlgProc
= ProbeListPageDlgProc
;
430 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_PROBELISTPAGE
);
431 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
433 /* Create finish page */
434 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
435 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
436 psp
.hInstance
= hApplet
;
438 psp
.pfnDlgProc
= FinishPageDlgProc
;
439 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_FINISHPAGE
);
440 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
442 /* Create not connected page */
443 psp
.dwSize
= sizeof(PROPSHEETPAGE
);
444 psp
.dwFlags
= PSP_DEFAULT
| PSP_HIDEHEADER
;
445 psp
.hInstance
= hApplet
;
447 psp
.pfnDlgProc
= NotConnectedPageDlgProc
;
448 psp
.pszTemplate
= MAKEINTRESOURCE(IDD_NOTCONNECTEDPAGE
);
449 ahpsp
[nPages
++] = CreatePropertySheetPage(&psp
);
451 /* Create the property sheet */
452 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
453 psh
.dwFlags
= PSH_WIZARD97
| PSH_WATERMARK
| PSH_HEADER
;
454 psh
.hInstance
= hApplet
;
455 psh
.hwndParent
= hwnd
;
459 psh
.pszbmWatermark
= MAKEINTRESOURCE(IDB_WATERMARK
);
460 psh
.pszbmHeader
= MAKEINTRESOURCE(IDB_HEADER
);
462 /* Create title font */
463 hTitleFont
= CreateTitleFont();
465 /* Display the wizard */
468 DeleteObject(hTitleFont
);
471 /* FUNCTIONS ****************************************************************/
474 InstallNewDevice(HWND hwndParent
, LPGUID ClassGuid
, PDWORD pReboot
)
480 AddHardwareWizard(HWND hwnd
, LPWSTR lpName
)
484 DPRINT1("No support of remote installation yet!\n");
488 HardwareWizardInit(hwnd
);
491 /* Control Panel Callback */
493 CPlApplet(HWND hwndCpl
, UINT uMsg
, LPARAM lParam1
, LPARAM lParam2
)
505 CPLINFO
*CPlInfo
= (CPLINFO
*)lParam2
;
507 CPlInfo
->idIcon
= IDI_CPLICON
;
508 CPlInfo
->idName
= IDS_CPLNAME
;
509 CPlInfo
->idInfo
= IDS_CPLDESCRIPTION
;
514 AddHardwareWizard(hwndCpl
, NULL
);
522 DllMain(HINSTANCE hinstDLL
, DWORD dwReason
, LPVOID lpvReserved
)
524 UNREFERENCED_PARAMETER(lpvReserved
);
528 case DLL_PROCESS_ATTACH
:
530 DisableThreadLibraryCalls(hinstDLL
);