mirror of
https://github.com/reactos/reactos.git
synced 2024-09-17 16:20:20 +00:00
- Open the device propsheet for child items (not parents as there isn't much point)
- Tag the Device ID onto the treeview items and provide functionality to tear it down - Remove/change some code which wasn't needed to speed up opening time3 - We now have a pretty functional device manager. However it's heavily reliant on devmgr.dll, therefore functionality per device will rely on how complete this lib is. svn path=/trunk/; revision=24396
This commit is contained in:
parent
d0cb64ce3d
commit
7e6d549b19
|
@ -15,6 +15,7 @@
|
||||||
<library>user32</library>
|
<library>user32</library>
|
||||||
<library>comctl32</library>
|
<library>comctl32</library>
|
||||||
<library>advapi32</library>
|
<library>advapi32</library>
|
||||||
|
<library>devmgr</library>
|
||||||
<compilationunit name="unit.c">
|
<compilationunit name="unit.c">
|
||||||
<file>about.c</file>
|
<file>about.c</file>
|
||||||
<file>devmgmt.c</file>
|
<file>devmgmt.c</file>
|
||||||
|
|
|
@ -12,10 +12,84 @@
|
||||||
static SP_CLASSIMAGELIST_DATA ImageListData;
|
static SP_CLASSIMAGELIST_DATA ImageListData;
|
||||||
static HDEVINFO hDevInfo;
|
static HDEVINFO hDevInfo;
|
||||||
|
|
||||||
|
VOID
|
||||||
VOID OpenPropSheet(HTREEITEM hItem)
|
FreeDeviceStrings(HWND hTV)
|
||||||
{
|
{
|
||||||
DisplayString(_T("Device Propsheet not yet implemented"));
|
HTREEITEM hItem;
|
||||||
|
|
||||||
|
hItem = TreeView_GetRoot(hTV);
|
||||||
|
|
||||||
|
if (hItem)
|
||||||
|
{
|
||||||
|
hItem = TreeView_GetChild(hTV,
|
||||||
|
hItem);
|
||||||
|
/* loop the parent items */
|
||||||
|
while (hItem)
|
||||||
|
{
|
||||||
|
hItem = TreeView_GetChild(hTV,
|
||||||
|
hItem);
|
||||||
|
if (hItem == NULL)
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* loop the child items and free the DeviceID */
|
||||||
|
while (TRUE)
|
||||||
|
{
|
||||||
|
HTREEITEM hOldItem;
|
||||||
|
TV_ITEM tvItem;
|
||||||
|
//TCHAR Buf[100];
|
||||||
|
|
||||||
|
tvItem.hItem = hItem;
|
||||||
|
tvItem.mask = TVIF_PARAM;// | TVIF_TEXT;
|
||||||
|
//tvItem.pszText = Buf;
|
||||||
|
//tvItem.cchTextMax = 99;
|
||||||
|
|
||||||
|
(void)TreeView_GetItem(hTV, &tvItem);
|
||||||
|
|
||||||
|
//MessageBox(NULL, Buf, NULL, 0);
|
||||||
|
|
||||||
|
HeapFree(GetProcessHeap(),
|
||||||
|
0,
|
||||||
|
(LPTSTR)tvItem.lParam);
|
||||||
|
|
||||||
|
hOldItem = hItem;
|
||||||
|
|
||||||
|
hItem = TreeView_GetNextSibling(hTV,
|
||||||
|
hItem);
|
||||||
|
if (hItem == NULL)
|
||||||
|
{
|
||||||
|
hItem = hOldItem;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hItem = TreeView_GetParent(hTV,
|
||||||
|
hItem);
|
||||||
|
hItem = TreeView_GetNextSibling(hTV,
|
||||||
|
hItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
VOID
|
||||||
|
OpenPropSheet(HWND hTV,
|
||||||
|
HTREEITEM hItem)
|
||||||
|
{
|
||||||
|
TV_ITEM tvItem;
|
||||||
|
|
||||||
|
tvItem.hItem = hItem;
|
||||||
|
tvItem.mask = TVIF_PARAM;
|
||||||
|
|
||||||
|
if (TreeView_GetItem(hTV, &tvItem) &&
|
||||||
|
(LPTSTR)tvItem.lParam != NULL)
|
||||||
|
{
|
||||||
|
DevicePropertiesExW(hTV,
|
||||||
|
NULL,
|
||||||
|
(LPTSTR)tvItem.lParam,
|
||||||
|
0,
|
||||||
|
FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,6 +97,7 @@ static HTREEITEM
|
||||||
InsertIntoTreeView(HWND hTV,
|
InsertIntoTreeView(HWND hTV,
|
||||||
HTREEITEM hRoot,
|
HTREEITEM hRoot,
|
||||||
LPTSTR lpLabel,
|
LPTSTR lpLabel,
|
||||||
|
LPTSTR DeviceID,
|
||||||
INT DevImage)
|
INT DevImage)
|
||||||
{
|
{
|
||||||
TV_ITEM tvi;
|
TV_ITEM tvi;
|
||||||
|
@ -31,9 +106,10 @@ InsertIntoTreeView(HWND hTV,
|
||||||
ZeroMemory(&tvi, sizeof(tvi));
|
ZeroMemory(&tvi, sizeof(tvi));
|
||||||
ZeroMemory(&tvins, sizeof(tvins));
|
ZeroMemory(&tvins, sizeof(tvins));
|
||||||
|
|
||||||
tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
|
tvi.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
|
||||||
tvi.pszText = lpLabel;
|
tvi.pszText = lpLabel;
|
||||||
tvi.cchTextMax = lstrlen(lpLabel);
|
tvi.cchTextMax = lstrlen(lpLabel);
|
||||||
|
tvi.lParam = (LPARAM)DeviceID;
|
||||||
tvi.iImage = DevImage;
|
tvi.iImage = DevImage;
|
||||||
tvi.iSelectedImage = DevImage;
|
tvi.iSelectedImage = DevImage;
|
||||||
|
|
||||||
|
@ -58,11 +134,11 @@ EnumDeviceClasses(INT ClassIndex,
|
||||||
UINT Ret;
|
UINT Ret;
|
||||||
|
|
||||||
*DevPresent = FALSE;
|
*DevPresent = FALSE;
|
||||||
|
*DevClassName = _T('\0');
|
||||||
|
|
||||||
Ret = CM_Enumerate_Classes(ClassIndex,
|
Ret = CM_Enumerate_Classes(ClassIndex,
|
||||||
&ClassGuid,
|
&ClassGuid,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
if (Ret != CR_SUCCESS)
|
if (Ret != CR_SUCCESS)
|
||||||
{
|
{
|
||||||
/* all classes enumerated */
|
/* all classes enumerated */
|
||||||
|
@ -85,10 +161,6 @@ EnumDeviceClasses(INT ClassIndex,
|
||||||
{
|
{
|
||||||
lstrcpy(DevClassName, ClassName);
|
lstrcpy(DevClassName, ClassName);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
*DevClassName = _T('\0');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!SetupDiGetClassImageIndex(&ImageListData,
|
if (!SetupDiGetClassImageIndex(&ImageListData,
|
||||||
&ClassGuid,
|
&ClassGuid,
|
||||||
|
@ -111,7 +183,6 @@ EnumDeviceClasses(INT ClassIndex,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KeyClass = SetupDiOpenClassRegKeyEx(&ClassGuid,
|
KeyClass = SetupDiOpenClassRegKeyEx(&ClassGuid,
|
||||||
MAXIMUM_ALLOWED,
|
MAXIMUM_ALLOWED,
|
||||||
DIOCR_INSTALLER,
|
DIOCR_INSTALLER,
|
||||||
|
@ -145,67 +216,56 @@ EnumDeviceClasses(INT ClassIndex,
|
||||||
|
|
||||||
static INT
|
static INT
|
||||||
EnumDevices(INT index,
|
EnumDevices(INT index,
|
||||||
TCHAR* DeviceClassName,
|
LPTSTR DeviceClassName,
|
||||||
TCHAR* DeviceName)
|
LPTSTR DeviceName,
|
||||||
|
LPTSTR *DeviceID)
|
||||||
{
|
{
|
||||||
SP_DEVINFO_DATA DeviceInfoData;
|
SP_DEVINFO_DATA DeviceInfoData;
|
||||||
DWORD RequiredSize = 0;
|
DWORD DevIdSize;
|
||||||
GUID *guids = NULL;
|
|
||||||
BOOL bRet;
|
|
||||||
|
|
||||||
*DeviceName = _T('\0');
|
*DeviceName = _T('\0');
|
||||||
|
*DeviceID = NULL;
|
||||||
bRet = SetupDiClassGuidsFromName(DeviceClassName,
|
|
||||||
NULL,
|
|
||||||
RequiredSize,
|
|
||||||
&RequiredSize);
|
|
||||||
if (RequiredSize == 0)
|
|
||||||
return -2;
|
|
||||||
|
|
||||||
if (!bRet)
|
|
||||||
{
|
|
||||||
guids = HeapAlloc(GetProcessHeap(),
|
|
||||||
0,
|
|
||||||
RequiredSize * sizeof(GUID));
|
|
||||||
if (guids == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
bRet = SetupDiClassGuidsFromName(DeviceClassName,
|
|
||||||
guids,
|
|
||||||
RequiredSize,
|
|
||||||
&RequiredSize);
|
|
||||||
|
|
||||||
if (!bRet || RequiredSize == 0)
|
|
||||||
{
|
|
||||||
/* incorrect class name */
|
|
||||||
HeapFree(GetProcessHeap(), 0, guids);
|
|
||||||
return -3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(), 0, guids);
|
|
||||||
if(hDevInfo == INVALID_HANDLE_VALUE)
|
|
||||||
{
|
|
||||||
if(!bRet)
|
|
||||||
{
|
|
||||||
/* device info is unavailable */
|
|
||||||
return -4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ZeroMemory(&DeviceInfoData, sizeof(SP_DEVINFO_DATA));
|
ZeroMemory(&DeviceInfoData, sizeof(SP_DEVINFO_DATA));
|
||||||
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
|
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
|
||||||
|
|
||||||
bRet = SetupDiEnumDeviceInfo(hDevInfo,
|
if (!SetupDiEnumDeviceInfo(hDevInfo,
|
||||||
index,
|
index,
|
||||||
&DeviceInfoData);
|
&DeviceInfoData))
|
||||||
|
|
||||||
if (!bRet)
|
|
||||||
{
|
{
|
||||||
/* no such device */
|
/* no such device */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* get the device ID */
|
||||||
|
if (!SetupDiGetDeviceInstanceId(hDevInfo,
|
||||||
|
&DeviceInfoData,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
&DevIdSize))
|
||||||
|
{
|
||||||
|
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
||||||
|
{
|
||||||
|
(*DeviceID) = (LPTSTR)HeapAlloc(GetProcessHeap(),
|
||||||
|
0,
|
||||||
|
DevIdSize * sizeof(TCHAR));
|
||||||
|
if (*DeviceID)
|
||||||
|
{
|
||||||
|
if (!SetupDiGetDeviceInstanceId(hDevInfo,
|
||||||
|
&DeviceInfoData,
|
||||||
|
*DeviceID,
|
||||||
|
DevIdSize,
|
||||||
|
NULL))
|
||||||
|
{
|
||||||
|
HeapFree(GetProcessHeap(),
|
||||||
|
0,
|
||||||
|
*DeviceID);
|
||||||
|
*DeviceID = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* get the device's friendly name */
|
/* get the device's friendly name */
|
||||||
if (!SetupDiGetDeviceRegistryProperty(hDevInfo,
|
if (!SetupDiGetDeviceRegistryProperty(hDevInfo,
|
||||||
&DeviceInfoData,
|
&DeviceInfoData,
|
||||||
|
@ -216,17 +276,16 @@ EnumDevices(INT index,
|
||||||
NULL))
|
NULL))
|
||||||
{
|
{
|
||||||
/* if the friendly name fails, try the description instead */
|
/* if the friendly name fails, try the description instead */
|
||||||
bRet = SetupDiGetDeviceRegistryProperty(hDevInfo,
|
if (!SetupDiGetDeviceRegistryProperty(hDevInfo,
|
||||||
&DeviceInfoData,
|
&DeviceInfoData,
|
||||||
SPDRP_DEVICEDESC,
|
SPDRP_DEVICEDESC,
|
||||||
0,
|
0,
|
||||||
(BYTE*)DeviceName,
|
(BYTE*)DeviceName,
|
||||||
MAX_DEV_LEN,
|
MAX_DEV_LEN,
|
||||||
NULL);
|
NULL))
|
||||||
if (!bRet)
|
|
||||||
{
|
{
|
||||||
/* if the description fails, just give up! */
|
/* if the description fails, just give up! */
|
||||||
return -5;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,6 +300,7 @@ ListDevicesByType(PMAIN_WND_INFO Info,
|
||||||
HTREEITEM hDevItem;
|
HTREEITEM hDevItem;
|
||||||
TCHAR DevName[MAX_DEV_LEN];
|
TCHAR DevName[MAX_DEV_LEN];
|
||||||
TCHAR DevDesc[MAX_DEV_LEN];
|
TCHAR DevDesc[MAX_DEV_LEN];
|
||||||
|
LPTSTR DeviceID = NULL;
|
||||||
BOOL DevExist = FALSE;
|
BOOL DevExist = FALSE;
|
||||||
INT ClassRet;
|
INT ClassRet;
|
||||||
INT index = 0;
|
INT index = 0;
|
||||||
|
@ -264,6 +324,7 @@ ListDevicesByType(PMAIN_WND_INFO Info,
|
||||||
hDevItem = InsertIntoTreeView(Info->hTreeView,
|
hDevItem = InsertIntoTreeView(Info->hTreeView,
|
||||||
hRoot,
|
hRoot,
|
||||||
DevDesc,
|
DevDesc,
|
||||||
|
NULL,
|
||||||
DevImage);
|
DevImage);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -271,6 +332,7 @@ ListDevicesByType(PMAIN_WND_INFO Info,
|
||||||
hDevItem = InsertIntoTreeView(Info->hTreeView,
|
hDevItem = InsertIntoTreeView(Info->hTreeView,
|
||||||
hRoot,
|
hRoot,
|
||||||
DevName,
|
DevName,
|
||||||
|
NULL,
|
||||||
DevImage);
|
DevImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,12 +340,14 @@ ListDevicesByType(PMAIN_WND_INFO Info,
|
||||||
{
|
{
|
||||||
Ret = EnumDevices(DevIndex,
|
Ret = EnumDevices(DevIndex,
|
||||||
DevName,
|
DevName,
|
||||||
DeviceName);
|
DeviceName,
|
||||||
|
&DeviceID);
|
||||||
if (Ret == 0)
|
if (Ret == 0)
|
||||||
{
|
{
|
||||||
InsertIntoTreeView(Info->hTreeView,
|
InsertIntoTreeView(Info->hTreeView,
|
||||||
hDevItem,
|
hDevItem,
|
||||||
DeviceName,
|
DeviceName,
|
||||||
|
DeviceID,
|
||||||
DevImage);
|
DevImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,6 +362,7 @@ ListDevicesByType(PMAIN_WND_INFO Info,
|
||||||
hDevInfo = NULL;
|
hDevInfo = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* don't insert classes with no devices */
|
||||||
if (!TreeView_GetChild(Info->hTreeView,
|
if (!TreeView_GetChild(Info->hTreeView,
|
||||||
hDevItem))
|
hDevItem))
|
||||||
{
|
{
|
||||||
|
@ -366,6 +431,7 @@ InitTreeView(PMAIN_WND_INFO Info)
|
||||||
hRoot = InsertIntoTreeView(Info->hTreeView,
|
hRoot = InsertIntoTreeView(Info->hTreeView,
|
||||||
NULL,
|
NULL,
|
||||||
ComputerName,
|
ComputerName,
|
||||||
|
NULL,
|
||||||
RootImage);
|
RootImage);
|
||||||
|
|
||||||
return hRoot;
|
return hRoot;
|
||||||
|
|
|
@ -285,7 +285,8 @@ OnNotify(PMAIN_WND_INFO Info,
|
||||||
if (!TreeView_GetChild(Info->hTreeView,
|
if (!TreeView_GetChild(Info->hTreeView,
|
||||||
hSelected))
|
hSelected))
|
||||||
{
|
{
|
||||||
OpenPropSheet(hSelected);
|
OpenPropSheet(Info->hTreeView,
|
||||||
|
hSelected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -348,13 +349,18 @@ MainWndCommand(PMAIN_WND_INFO Info,
|
||||||
case IDC_PROP:
|
case IDC_PROP:
|
||||||
{
|
{
|
||||||
HTREEITEM hSelected = TreeView_GetSelection(Info->hTreeView);
|
HTREEITEM hSelected = TreeView_GetSelection(Info->hTreeView);
|
||||||
OpenPropSheet(hSelected);
|
OpenPropSheet(Info->hTreeView,
|
||||||
|
hSelected);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IDC_REFRESH:
|
case IDC_REFRESH:
|
||||||
{
|
{
|
||||||
HTREEITEM hRoot = InitTreeView(Info);
|
HTREEITEM hRoot;
|
||||||
|
|
||||||
|
FreeDeviceStrings(Info->hTreeView);
|
||||||
|
|
||||||
|
hRoot = InitTreeView(Info);
|
||||||
if (hRoot)
|
if (hRoot)
|
||||||
ListDevicesByType(Info, hRoot);
|
ListDevicesByType(Info, hRoot);
|
||||||
}
|
}
|
||||||
|
@ -525,6 +531,7 @@ MainWndProc(HWND hwnd,
|
||||||
|
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
{
|
{
|
||||||
|
FreeDeviceStrings(Info->hTreeView);
|
||||||
DestroyMenu(Info->hShortcutMenu);
|
DestroyMenu(Info->hShortcutMenu);
|
||||||
DestroyWindow(hwnd);
|
DestroyWindow(hwnd);
|
||||||
}
|
}
|
||||||
|
@ -532,8 +539,6 @@ MainWndProc(HWND hwnd,
|
||||||
|
|
||||||
case WM_DESTROY:
|
case WM_DESTROY:
|
||||||
{
|
{
|
||||||
//DestroyMainWnd(Info);
|
|
||||||
|
|
||||||
HeapFree(ProcessHeap,
|
HeapFree(ProcessHeap,
|
||||||
0,
|
0,
|
||||||
Info);
|
Info);
|
||||||
|
|
|
@ -53,7 +53,29 @@ HWND CreateMainWindow(LPCTSTR lpCaption, int nCmdShow);
|
||||||
|
|
||||||
|
|
||||||
/* enumdevices.c */
|
/* enumdevices.c */
|
||||||
VOID OpenPropSheet(HTREEITEM hItem);
|
// undocumented API's from devmgr
|
||||||
|
#ifdef _UNICODE
|
||||||
|
#define DevicePropertiesEx DevicePropertiesExW
|
||||||
|
INT_PTR
|
||||||
|
WINAPI
|
||||||
|
DevicePropertiesExW(IN HWND hWndParent OPTIONAL,
|
||||||
|
IN LPCWSTR lpMachineName OPTIONAL,
|
||||||
|
IN LPCWSTR lpDeviceID OPTIONAL,
|
||||||
|
IN DWORD dwFlags OPTIONAL,
|
||||||
|
IN BOOL bShowDevMgr);
|
||||||
|
#else
|
||||||
|
#define DevicePropertiesEx DevicePropertiesExA
|
||||||
|
INT_PTR
|
||||||
|
WINAPI
|
||||||
|
DevicePropertiesExA(IN HWND hWndParent OPTIONAL,
|
||||||
|
IN LPCSTR lpMachineName OPTIONAL,
|
||||||
|
IN LPCSTR lpDeviceID OPTIONAL,
|
||||||
|
IN DWORD dwFlags OPTIONAL,
|
||||||
|
IN BOOL bShowDevMgr);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
VOID FreeDeviceStrings(HWND hTV);
|
||||||
|
VOID OpenPropSheet(HWND hTV, HTREEITEM hItem);
|
||||||
HTREEITEM InitTreeView(PMAIN_WND_INFO Info);
|
HTREEITEM InitTreeView(PMAIN_WND_INFO Info);
|
||||||
VOID ListDevicesByType(PMAIN_WND_INFO Info, HTREEITEM hRoot);
|
VOID ListDevicesByType(PMAIN_WND_INFO Info, HTREEITEM hRoot);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue