📄 advprop.c
字号:
}
case WM_INITDIALOG:
{
dap = (PDEVADVPROP_INFO)((LPPROPSHEETPAGE)lParam)->lParam;
if (dap != NULL)
{
SetWindowLongPtr(hwndDlg,
DWL_USER,
(DWORD_PTR)dap);
UpdateDriverDlg(hwndDlg,
dap);
}
Ret = TRUE;
break;
}
}
}
return Ret;
}
static VOID
InitDevUsageActions(IN HWND hwndDlg,
IN HWND hComboBox,
IN PDEVADVPROP_INFO dap)
{
INT Index;
UINT i;
UINT Actions[] =
{
IDS_ENABLEDEVICE,
IDS_DISABLEDEVICE,
};
for (i = 0;
i != sizeof(Actions) / sizeof(Actions[0]);
i++)
{
/* fill in the device usage combo box */
if (LoadString(hDllInstance,
Actions[i],
dap->szTemp,
sizeof(dap->szTemp) / sizeof(dap->szTemp[0])))
{
Index = (INT)SendMessage(hComboBox,
CB_ADDSTRING,
0,
(LPARAM)dap->szTemp);
if (Index != CB_ERR)
{
SendMessage(hComboBox,
CB_SETITEMDATA,
(WPARAM)Index,
(LPARAM)Actions[i]);
switch (Actions[i])
{
case IDS_ENABLEDEVICE:
if (dap->DeviceStarted)
{
SendMessage(hComboBox,
CB_SETCURSEL,
(WPARAM)Index,
0);
}
break;
case IDS_DISABLEDEVICE:
if (!dap->DeviceStarted)
{
SendMessage(hComboBox,
CB_SETCURSEL,
(WPARAM)Index,
0);
}
break;
default:
break;
}
}
}
}
}
static UINT
GetSelectedUsageAction(IN HWND hComboBox)
{
INT Index;
UINT Ret = 0;
Index = (INT)SendMessage(hComboBox,
CB_GETCURSEL,
0,
0);
if (Index != CB_ERR)
{
INT iRet = (INT) SendMessage(hComboBox,
CB_GETITEMDATA,
(WPARAM)Index,
0);
if (iRet != CB_ERR)
{
Ret = (UINT)iRet;
}
}
return Ret;
}
static BOOL
ApplyGeneralSettings(IN HWND hwndDlg,
IN PDEVADVPROP_INFO dap)
{
BOOL Ret = FALSE;
if (dap->DeviceUsageChanged && dap->IsAdmin && dap->CanDisable)
{
UINT SelectedUsageAction;
BOOL NeedReboot = FALSE;
SelectedUsageAction = GetSelectedUsageAction(GetDlgItem(hwndDlg,
IDC_DEVUSAGE));
switch (SelectedUsageAction)
{
case IDS_ENABLEDEVICE:
if (!dap->DeviceStarted)
{
Ret = EnableDevice(dap->DeviceInfoSet,
&dap->DeviceInfoData,
TRUE,
0,
&NeedReboot);
}
break;
case IDS_DISABLEDEVICE:
if (dap->DeviceStarted)
{
Ret = EnableDevice(dap->DeviceInfoSet,
&dap->DeviceInfoData,
FALSE,
0,
&NeedReboot);
}
break;
default:
break;
}
if (Ret)
{
if (NeedReboot)
{
/* make PropertySheet() return PSM_REBOOTSYSTEM */
PropSheet_RebootSystem(hwndDlg);
}
}
else
{
/* FIXME - display an error message */
DPRINT1("Failed to enable/disable device! LastError: %d\n",
GetLastError());
}
}
else
Ret = !dap->DeviceUsageChanged;
/* disable the apply button */
PropSheet_UnChanged(GetParent(hwndDlg),
hwndDlg);
dap->DeviceUsageChanged = FALSE;
return Ret;
}
static VOID
UpdateDevInfo(IN HWND hwndDlg,
IN PDEVADVPROP_INFO dap,
IN BOOL ReOpen)
{
HWND hDevUsage, hPropSheetDlg, hDevProbBtn;
CONFIGRET cr;
ULONG Status, ProblemNumber;
SP_DEVINSTALL_PARAMS_W InstallParams;
UINT TroubleShootStrId = IDS_TROUBLESHOOTDEV;
BOOL bFlag, bDevActionAvailable = TRUE;
BOOL bDrvInstalled = FALSE;
DWORD iPage;
HDEVINFO DeviceInfoSet = NULL;
PSP_DEVINFO_DATA DeviceInfoData = NULL;
PROPSHEETHEADER psh;
DWORD nDriverPages = 0;
BOOL RecalcPages = FALSE;
hPropSheetDlg = GetParent(hwndDlg);
if (dap->PageInitialized)
{
/* switch to the General page */
PropSheet_SetCurSelByID(hPropSheetDlg,
IDD_DEVICEGENERAL);
/* remove and destroy the existing device property sheet pages */
if (dap->DevPropSheets != NULL)
{
for (iPage = 0;
iPage != dap->nDevPropSheets;
iPage++)
{
if (dap->DevPropSheets[iPage] != NULL)
{
PropSheet_RemovePage(hPropSheetDlg,
(WPARAM) -1,
dap->DevPropSheets[iPage]);
RecalcPages = TRUE;
}
}
}
}
iPage = 0;
if (dap->FreeDevPropSheets)
{
/* don't free the array if it's the one allocated in
DisplayDeviceAdvancedProperties */
HeapFree(GetProcessHeap(),
0,
dap->DevPropSheets);
dap->FreeDevPropSheets = FALSE;
}
dap->DevPropSheets = NULL;
dap->nDevPropSheets = 0;
if (ReOpen)
{
/* create a new device info set and re-open the device */
if (dap->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE)
{
SetupDiDestroyDeviceInfoList(dap->CurrentDeviceInfoSet);
}
dap->ParentDevInst = 0;
dap->CurrentDeviceInfoSet = SetupDiCreateDeviceInfoListEx(NULL,
hwndDlg,
dap->lpMachineName,
NULL);
if (dap->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE)
{
if (SetupDiOpenDeviceInfo(dap->CurrentDeviceInfoSet,
dap->szDeviceID,
hwndDlg,
0,
&dap->CurrentDeviceInfoData))
{
if (dap->CloseDevInst)
{
SetupDiDestroyDeviceInfoList(dap->DeviceInfoSet);
}
dap->CloseDevInst = TRUE;
dap->DeviceInfoSet = dap->CurrentDeviceInfoSet;
dap->DeviceInfoData = dap->CurrentDeviceInfoData;
dap->CurrentDeviceInfoSet = INVALID_HANDLE_VALUE;
}
else
goto GetParentNode;
}
else
{
GetParentNode:
/* get the parent node from the initial devinst */
CM_Get_Parent_Ex(&dap->ParentDevInst,
dap->DeviceInfoData.DevInst,
0,
dap->hMachine);
}
if (dap->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE)
{
DeviceInfoSet = dap->CurrentDeviceInfoSet;
DeviceInfoData = &dap->CurrentDeviceInfoData;
}
else
{
DeviceInfoSet = dap->DeviceInfoSet;
DeviceInfoData = &dap->DeviceInfoData;
}
}
else
{
DeviceInfoSet = dap->DeviceInfoSet;
DeviceInfoData = &dap->DeviceInfoData;
}
dap->HasDriverPage = FALSE;
dap->HasResourcePage = FALSE;
dap->HasPowerPage = FALSE;
if (IsDriverInstalled(DeviceInfoData->DevInst,
dap->hMachine,
&bDrvInstalled) &&
bDrvInstalled)
{
if (SetupDiCallClassInstaller((dap->ShowRemotePages ?
DIF_ADDREMOTEPROPERTYPAGE_ADVANCED :
DIF_ADDPROPERTYPAGE_ADVANCED),
DeviceInfoSet,
DeviceInfoData))
{
/* get install params */
InstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS_W);
if (!SetupDiGetDeviceInstallParamsW(DeviceInfoSet,
DeviceInfoData,
&InstallParams))
{
/* zero the flags */
InstallParams.Flags = 0;
}
dap->HasDriverPage = !(InstallParams.Flags & DI_DRIVERPAGE_ADDED);
dap->HasResourcePage = !(InstallParams.Flags & DI_RESOURCEPAGE_ADDED);
dap->HasPowerPage = !(InstallParams.Flags & DI_FLAGSEX_POWERPAGE_ADDED);
}
}
/* get the device icon */
if (dap->hDevIcon != NULL)
{
DestroyIcon(dap->hDevIcon);
dap->hDevIcon = NULL;
}
if (!SetupDiLoadClassIcon(&DeviceInfoData->ClassGuid,
&dap->hDevIcon,
NULL))
{
dap->hDevIcon = NULL;
}
/* get the device name */
if (GetDeviceDescriptionString(DeviceInfoSet,
DeviceInfoData,
dap->szDevName,
sizeof(dap->szDevName) / sizeof(dap->szDevName[0])))
{
PropSheet_SetTitle(hPropSheetDlg,
PSH_PROPTITLE,
dap->szDevName);
}
/* set the device image */
SendDlgItemMessage(hwndDlg,
IDC_DEVICON,
STM_SETICON,
(WPARAM)dap->hDevIcon,
0);
/* set the device name edit control text */
SetDlgItemText(hwndDlg,
IDC_DEVNAME,
dap->szDevName);
/* set the device type edit control text */
if (GetDeviceTypeString(DeviceInfoData,
dap->szTemp,
sizeof(dap->szTemp) / sizeof(dap->szTemp[0])))
{
SetDlgItemText(hwndDlg,
IDC_DEVTYPE,
dap->szTemp);
}
/* set the device manufacturer edit control text */
if (GetDeviceManufacturerString(DeviceInfoSet,
DeviceInfoData,
dap->szTemp,
sizeof(dap->szTemp) / sizeof(dap->szTemp[0])))
{
SetDlgItemText(hwndDlg,
IDC_DEVMANUFACTURER,
dap->szTemp);
}
/* set the device location edit control text */
if (GetDeviceLocationString(DeviceInfoData->DevInst,
dap->ParentDevInst,
dap->szTemp,
sizeof(dap->szTemp) / sizeof(dap->szTemp[0])))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -