advprop.c
来自「一个类似windows」· C语言 代码 · 共 1,799 行 · 第 1/4 页
C
1,799 行
/*
* ReactOS Device Manager Applet
* Copyright (C) 2004 - 2005 ReactOS Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Id: hwpage.c 19599 2005-11-26 02:12:58Z weiden $
*
* PROJECT: ReactOS devmgr.dll
* FILE: lib/devmgr/advprop.c
* PURPOSE: ReactOS Device Manager
* PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
* UPDATE HISTORY:
* 04-04-2004 Created
*/
#include <precomp.h>
#define NDEBUG
#include <debug.h>
typedef INT_PTR (WINAPI *PPROPERTYSHEETW)(LPCPROPSHEETHEADERW);
typedef HPROPSHEETPAGE (WINAPI *PCREATEPROPERTYSHEETPAGEW)(LPCPROPSHEETPAGEW);
typedef BOOL (WINAPI *PDESTROYPROPERTYSHEETPAGE)(HPROPSHEETPAGE);
typedef struct _DEVADVPROP_INFO
{
HWND hWndGeneralPage;
HWND hWndParent;
WNDPROC ParentOldWndProc;
HICON hDevIcon;
HDEVINFO DeviceInfoSet;
SP_DEVINFO_DATA DeviceInfoData;
HDEVINFO CurrentDeviceInfoSet;
SP_DEVINFO_DATA CurrentDeviceInfoData;
DEVINST ParentDevInst;
HMACHINE hMachine;
LPCWSTR lpMachineName;
HINSTANCE hComCtl32;
PCREATEPROPERTYSHEETPAGEW pCreatePropertySheetPageW;
PDESTROYPROPERTYSHEETPAGE pDestroyPropertySheetPage;
DWORD PropertySheetType;
DWORD nDevPropSheets;
HPROPSHEETPAGE *DevPropSheets;
BOOL FreeDevPropSheets : 1;
BOOL CanDisable : 1;
BOOL DeviceStarted : 1;
BOOL DeviceUsageChanged : 1;
BOOL CloseDevInst : 1;
BOOL IsAdmin : 1;
BOOL DoDefaultDevAction : 1;
BOOL PageInitialized : 1;
BOOL ShowRemotePages : 1;
BOOL HasDriverPage : 1;
BOOL HasResourcePage : 1;
BOOL HasPowerPage : 1;
WCHAR szDevName[255];
WCHAR szTemp[255];
WCHAR szDeviceID[1];
/* struct may be dynamically expanded here! */
} DEVADVPROP_INFO, *PDEVADVPROP_INFO;
typedef struct _ENUMDRIVERFILES_CONTEXT
{
HWND hDriversListView;
UINT nCount;
} ENUMDRIVERFILES_CONTEXT, *PENUMDRIVERFILES_CONTEXT;
#define PM_INITIALIZE (WM_APP + 0x101)
static UINT WINAPI
EnumDeviceDriverFilesCallback(IN PVOID Context,
IN UINT Notification,
IN UINT_PTR Param1,
IN UINT_PTR Param2)
{
LVITEM li;
PENUMDRIVERFILES_CONTEXT EnumDriverFilesContext = (PENUMDRIVERFILES_CONTEXT)Context;
li.mask = LVIF_TEXT | LVIF_STATE;
li.iItem = EnumDriverFilesContext->nCount++;
li.iSubItem = 0;
li.state = (li.iItem == 0 ? LVIS_SELECTED : 0);
li.stateMask = LVIS_SELECTED;
li.pszText = (LPWSTR)Param1;
(void)ListView_InsertItem(EnumDriverFilesContext->hDriversListView,
&li);
return NO_ERROR;
}
static VOID
UpdateDriverDetailsDlg(IN HWND hwndDlg,
IN HWND hDriversListView,
IN PDEVADVPROP_INFO dap)
{
HDEVINFO DeviceInfoSet;
PSP_DEVINFO_DATA DeviceInfoData;
SP_DRVINFO_DATA DriverInfoData;
ENUMDRIVERFILES_CONTEXT EnumDriverFilesContext;
if (dap->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE)
{
DeviceInfoSet = dap->CurrentDeviceInfoSet;
DeviceInfoData = &dap->CurrentDeviceInfoData;
}
else
{
DeviceInfoSet = dap->DeviceInfoSet;
DeviceInfoData = &dap->DeviceInfoData;
}
/* 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);
/* fill the driver files list view */
EnumDriverFilesContext.hDriversListView = hDriversListView;
EnumDriverFilesContext.nCount = 0;
(void)ListView_DeleteAllItems(EnumDriverFilesContext.hDriversListView);
DriverInfoData.cbSize = sizeof(SP_DRVINFO_DATA);
if (FindCurrentDriver(DeviceInfoSet,
DeviceInfoData,
&DriverInfoData) &&
SetupDiSetSelectedDriver(DeviceInfoSet,
DeviceInfoData,
&DriverInfoData))
{
HSPFILEQ queueHandle;
queueHandle = SetupOpenFileQueue();
if (queueHandle != (HSPFILEQ)INVALID_HANDLE_VALUE)
{
SP_DEVINSTALL_PARAMS DeviceInstallParams = {0};
DeviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
if (SetupDiGetDeviceInstallParams(DeviceInfoSet,
DeviceInfoData,
&DeviceInstallParams))
{
DeviceInstallParams.FileQueue = queueHandle;
DeviceInstallParams.Flags |= DI_NOVCP;
if (SetupDiSetDeviceInstallParams(DeviceInfoSet,
DeviceInfoData,
&DeviceInstallParams) &&
SetupDiCallClassInstaller(DIF_INSTALLDEVICEFILES,
DeviceInfoSet,
DeviceInfoData))
{
DWORD scanResult;
RECT rcClient;
LVCOLUMN lvc;
/* enumerate the driver files */
SetupScanFileQueue(queueHandle,
SPQ_SCAN_USE_CALLBACK,
NULL,
EnumDeviceDriverFilesCallback,
&EnumDriverFilesContext,
&scanResult);
/* update the list view column width */
GetClientRect(hDriversListView,
&rcClient);
lvc.mask = LVCF_WIDTH;
lvc.cx = rcClient.right;
(void)ListView_SetColumn(hDriversListView,
0,
&lvc);
}
}
SetupCloseFileQueue(queueHandle);
}
}
}
static INT_PTR
CALLBACK
DriverDetailsDlgProc(IN HWND hwndDlg,
IN UINT uMsg,
IN WPARAM wParam,
IN LPARAM lParam)
{
PDEVADVPROP_INFO dap;
INT_PTR Ret = FALSE;
dap = (PDEVADVPROP_INFO)GetWindowLongPtr(hwndDlg,
DWL_USER);
if (dap != NULL || uMsg == WM_INITDIALOG)
{
switch (uMsg)
{
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDOK:
{
EndDialog(hwndDlg,
IDOK);
break;
}
}
break;
}
case WM_CLOSE:
{
EndDialog(hwndDlg,
IDCANCEL);
break;
}
case WM_INITDIALOG:
{
LV_COLUMN lvc;
HWND hDriversListView;
dap = (PDEVADVPROP_INFO)lParam;
if (dap != NULL)
{
SetWindowLongPtr(hwndDlg,
DWL_USER,
(DWORD_PTR)dap);
hDriversListView = GetDlgItem(hwndDlg,
IDC_DRIVERFILES);
/* add a column to the list view control */
lvc.mask = LVCF_FMT | LVCF_WIDTH;
lvc.fmt = LVCFMT_LEFT;
lvc.cx = 0;
(void)ListView_InsertColumn(hDriversListView,
0,
&lvc);
UpdateDriverDetailsDlg(hwndDlg,
hDriversListView,
dap);
}
Ret = TRUE;
break;
}
}
}
return Ret;
}
static VOID
UpdateDriverDlg(IN HWND hwndDlg,
IN PDEVADVPROP_INFO dap)
{
HDEVINFO DeviceInfoSet;
PSP_DEVINFO_DATA DeviceInfoData;
if (dap->CurrentDeviceInfoSet != INVALID_HANDLE_VALUE)
{
DeviceInfoSet = dap->CurrentDeviceInfoSet;
DeviceInfoData = &dap->CurrentDeviceInfoData;
}
else
{
DeviceInfoSet = dap->DeviceInfoSet;
DeviceInfoData = &dap->DeviceInfoData;
}
/* 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);
/* query the driver provider */
if (GetDriverProviderString(DeviceInfoSet,
DeviceInfoData,
dap->szTemp,
sizeof(dap->szTemp) / sizeof(dap->szTemp[0])))
{
SetDlgItemText(hwndDlg,
IDC_DRVPROVIDER,
dap->szTemp);
}
/* query the driver date */
if (GetDriverDateString(DeviceInfoSet,
DeviceInfoData,
dap->szTemp,
sizeof(dap->szTemp) / sizeof(dap->szTemp[0])))
{
SetDlgItemText(hwndDlg,
IDC_DRVDATE,
dap->szTemp);
}
/* query the driver version */
if (GetDriverVersionString(DeviceInfoSet,
DeviceInfoData,
dap->szTemp,
sizeof(dap->szTemp) / sizeof(dap->szTemp[0])))
{
SetDlgItemText(hwndDlg,
IDC_DRVVERSION,
dap->szTemp);
}
}
static INT_PTR
CALLBACK
AdvProcDriverDlgProc(IN HWND hwndDlg,
IN UINT uMsg,
IN WPARAM wParam,
IN LPARAM lParam)
{
PDEVADVPROP_INFO dap;
INT_PTR Ret = FALSE;
dap = (PDEVADVPROP_INFO)GetWindowLongPtr(hwndDlg,
DWL_USER);
if (dap != NULL || uMsg == WM_INITDIALOG)
{
switch (uMsg)
{
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDC_DRIVERDETAILS:
{
DialogBoxParam(hDllInstance,
MAKEINTRESOURCE(IDD_DRIVERDETAILS),
hwndDlg,
DriverDetailsDlgProc,
(ULONG_PTR)dap);
break;
}
}
break;
}
case WM_NOTIFY:
{
NMHDR *hdr = (NMHDR*)lParam;
switch (hdr->code)
{
case PSN_APPLY:
break;
}
break;
}
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:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?