Author: gedmurphy Date: Wed Oct 4 20:39:45 2006 New Revision: 24396
URL: http://svn.reactos.org/svn/reactos?rev=24396&view=rev Log: - 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.
Modified: trunk/reactos/base/applications/devmgmt/devmgmt.rbuild trunk/reactos/base/applications/devmgmt/enumdevices.c trunk/reactos/base/applications/devmgmt/mainwnd.c trunk/reactos/base/applications/devmgmt/precomp.h
Modified: trunk/reactos/base/applications/devmgmt/devmgmt.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/devmgmt/d... ============================================================================== --- trunk/reactos/base/applications/devmgmt/devmgmt.rbuild (original) +++ trunk/reactos/base/applications/devmgmt/devmgmt.rbuild Wed Oct 4 20:39:45 2006 @@ -15,6 +15,7 @@ <library>user32</library> <library>comctl32</library> <library>advapi32</library> + <library>devmgr</library> <compilationunit name="unit.c"> <file>about.c</file> <file>devmgmt.c</file>
Modified: trunk/reactos/base/applications/devmgmt/enumdevices.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/devmgmt/e... ============================================================================== --- trunk/reactos/base/applications/devmgmt/enumdevices.c (original) +++ trunk/reactos/base/applications/devmgmt/enumdevices.c Wed Oct 4 20:39:45 2006 @@ -12,10 +12,84 @@ static SP_CLASSIMAGELIST_DATA ImageListData; static HDEVINFO hDevInfo;
- -VOID OpenPropSheet(HTREEITEM hItem) -{ - DisplayString(_T("Device Propsheet not yet implemented")); +VOID +FreeDeviceStrings(HWND hTV) +{ + 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 @@ InsertIntoTreeView(HWND hTV, HTREEITEM hRoot, LPTSTR lpLabel, + LPTSTR DeviceID, INT DevImage) { TV_ITEM tvi; @@ -31,9 +106,10 @@ ZeroMemory(&tvi, sizeof(tvi)); 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.cchTextMax = lstrlen(lpLabel); + tvi.lParam = (LPARAM)DeviceID; tvi.iImage = DevImage; tvi.iSelectedImage = DevImage;
@@ -58,11 +134,11 @@ UINT Ret;
*DevPresent = FALSE; + *DevClassName = _T('\0');
Ret = CM_Enumerate_Classes(ClassIndex, &ClassGuid, 0); - if (Ret != CR_SUCCESS) { /* all classes enumerated */ @@ -84,10 +160,6 @@ &RequiredSize)) { lstrcpy(DevClassName, ClassName); - } - else - { - *DevClassName = _T('\0'); }
if (!SetupDiGetClassImageIndex(&ImageListData, @@ -111,7 +183,6 @@ return 0; }
- KeyClass = SetupDiOpenClassRegKeyEx(&ClassGuid, MAXIMUM_ALLOWED, DIOCR_INSTALLER, @@ -145,65 +216,54 @@
static INT EnumDevices(INT index, - TCHAR* DeviceClassName, - TCHAR* DeviceName) + LPTSTR DeviceClassName, + LPTSTR DeviceName, + LPTSTR *DeviceID) { SP_DEVINFO_DATA DeviceInfoData; - DWORD RequiredSize = 0; - GUID *guids = NULL; - BOOL bRet; + DWORD DevIdSize;
*DeviceName = _T('\0'); - - 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; - } - } + *DeviceID = NULL;
ZeroMemory(&DeviceInfoData, sizeof(SP_DEVINFO_DATA)); DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
- bRet = SetupDiEnumDeviceInfo(hDevInfo, - index, - &DeviceInfoData); - - if (!bRet) + if (!SetupDiEnumDeviceInfo(hDevInfo, + index, + &DeviceInfoData)) { /* no such device */ 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 */ @@ -216,17 +276,16 @@ NULL)) { /* if the friendly name fails, try the description instead */ - bRet = SetupDiGetDeviceRegistryProperty(hDevInfo, - &DeviceInfoData, - SPDRP_DEVICEDESC, - 0, - (BYTE*)DeviceName, - MAX_DEV_LEN, - NULL); - if (!bRet) + if (!SetupDiGetDeviceRegistryProperty(hDevInfo, + &DeviceInfoData, + SPDRP_DEVICEDESC, + 0, + (BYTE*)DeviceName, + MAX_DEV_LEN, + NULL)) { /* if the description fails, just give up! */ - return -5; + return -2; } }
@@ -241,6 +300,7 @@ HTREEITEM hDevItem; TCHAR DevName[MAX_DEV_LEN]; TCHAR DevDesc[MAX_DEV_LEN]; + LPTSTR DeviceID = NULL; BOOL DevExist = FALSE; INT ClassRet; INT index = 0; @@ -264,6 +324,7 @@ hDevItem = InsertIntoTreeView(Info->hTreeView, hRoot, DevDesc, + NULL, DevImage); } else @@ -271,6 +332,7 @@ hDevItem = InsertIntoTreeView(Info->hTreeView, hRoot, DevName, + NULL, DevImage); }
@@ -278,12 +340,14 @@ { Ret = EnumDevices(DevIndex, DevName, - DeviceName); + DeviceName, + &DeviceID); if (Ret == 0) { InsertIntoTreeView(Info->hTreeView, hDevItem, DeviceName, + DeviceID, DevImage); }
@@ -298,6 +362,7 @@ hDevInfo = NULL; }
+ /* don't insert classes with no devices */ if (!TreeView_GetChild(Info->hTreeView, hDevItem)) { @@ -366,6 +431,7 @@ hRoot = InsertIntoTreeView(Info->hTreeView, NULL, ComputerName, + NULL, RootImage);
return hRoot;
Modified: trunk/reactos/base/applications/devmgmt/mainwnd.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/devmgmt/m... ============================================================================== --- trunk/reactos/base/applications/devmgmt/mainwnd.c (original) +++ trunk/reactos/base/applications/devmgmt/mainwnd.c Wed Oct 4 20:39:45 2006 @@ -285,7 +285,8 @@ if (!TreeView_GetChild(Info->hTreeView, hSelected)) { - OpenPropSheet(hSelected); + OpenPropSheet(Info->hTreeView, + hSelected); } } break; @@ -348,13 +349,18 @@ case IDC_PROP: { HTREEITEM hSelected = TreeView_GetSelection(Info->hTreeView); - OpenPropSheet(hSelected); + OpenPropSheet(Info->hTreeView, + hSelected); } break;
case IDC_REFRESH: { - HTREEITEM hRoot = InitTreeView(Info); + HTREEITEM hRoot; + + FreeDeviceStrings(Info->hTreeView); + + hRoot = InitTreeView(Info); if (hRoot) ListDevicesByType(Info, hRoot); } @@ -525,6 +531,7 @@
case WM_CLOSE: { + FreeDeviceStrings(Info->hTreeView); DestroyMenu(Info->hShortcutMenu); DestroyWindow(hwnd); } @@ -532,8 +539,6 @@
case WM_DESTROY: { - //DestroyMainWnd(Info); - HeapFree(ProcessHeap, 0, Info);
Modified: trunk/reactos/base/applications/devmgmt/precomp.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/devmgmt/p... ============================================================================== --- trunk/reactos/base/applications/devmgmt/precomp.h (original) +++ trunk/reactos/base/applications/devmgmt/precomp.h Wed Oct 4 20:39:45 2006 @@ -53,7 +53,29 @@
/* 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); VOID ListDevicesByType(PMAIN_WND_INFO Info, HTREEITEM hRoot);