Author: gedmurphy
Date: Tue Oct 17 19:56:41 2006
New Revision: 24557
URL:
http://svn.reactos.org/svn/reactos?rev=24557&view=rev
Log:
- enumerate devices in a separate thread so it doesn't stall opening of the main
window
- check for problems with devices, e.g. disabled devices (currently missing code to
display overlay icons)
- enable / disable the properties command dependant on what item is selected
- fix a few potential bugs
Modified:
trunk/reactos/base/applications/devmgmt/En.rc
trunk/reactos/base/applications/devmgmt/devmgmt.c
trunk/reactos/base/applications/devmgmt/enumdevices.c
trunk/reactos/base/applications/devmgmt/mainwnd.c
trunk/reactos/base/applications/devmgmt/misc.c
trunk/reactos/base/applications/devmgmt/precomp.h
Modified: trunk/reactos/base/applications/devmgmt/En.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/devmgmt/…
==============================================================================
--- trunk/reactos/base/applications/devmgmt/En.rc (original)
+++ trunk/reactos/base/applications/devmgmt/En.rc Tue Oct 17 19:56:41 2006
@@ -8,7 +8,7 @@
BEGIN
MENUITEM "Print", IDC_PRINT, GRAYED
MENUITEM SEPARATOR
- MENUITEM "Properties", IDC_PROP
+ MENUITEM "Properties", IDC_PROP, GRAYED
MENUITEM SEPARATOR
MENUITEM "Help", IDC_PROGHELP, GRAYED
END
@@ -30,7 +30,7 @@
BEGIN
POPUP "popup"
BEGIN
- MENUITEM "Properties", IDC_PROP
+ MENUITEM "Properties", IDC_PROP, GRAYED
MENUITEM SEPARATOR
MENUITEM "Help", IDC_PROGHELP
END
Modified: trunk/reactos/base/applications/devmgmt/devmgmt.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/devmgmt/…
==============================================================================
--- trunk/reactos/base/applications/devmgmt/devmgmt.c (original)
+++ trunk/reactos/base/applications/devmgmt/devmgmt.c Tue Oct 17 19:56:41 2006
@@ -38,9 +38,6 @@
return 1;
}
-// FreeConsole();
-// AllocConsole();
-
if (InitMainWindowImpl())
{
hMainWnd = CreateMainWindow(lpAppName,
Modified: trunk/reactos/base/applications/devmgmt/enumdevices.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/devmgmt/…
==============================================================================
--- trunk/reactos/base/applications/devmgmt/enumdevices.c (original)
+++ trunk/reactos/base/applications/devmgmt/enumdevices.c Tue Oct 17 19:56:41 2006
@@ -12,21 +12,22 @@
static SP_CLASSIMAGELIST_DATA ImageListData;
static HDEVINFO hDevInfo;
+
VOID
-FreeDeviceStrings(HWND hTV)
+FreeDeviceStrings(HWND hTreeView)
{
HTREEITEM hItem;
- hItem = TreeView_GetRoot(hTV);
+ hItem = TreeView_GetRoot(hTreeView);
if (hItem)
{
- hItem = TreeView_GetChild(hTV,
+ hItem = TreeView_GetChild(hTreeView,
hItem);
/* loop the parent items */
while (hItem)
{
- hItem = TreeView_GetChild(hTV,
+ hItem = TreeView_GetChild(hTreeView,
hItem);
if (hItem == NULL)
break;
@@ -43,7 +44,7 @@
//tvItem.pszText = Buf;
//tvItem.cchTextMax = 99;
- (void)TreeView_GetItem(hTV, &tvItem);
+ (void)TreeView_GetItem(hTreeView, &tvItem);
//MessageBox(NULL, Buf, NULL, 0);
@@ -53,7 +54,7 @@
hOldItem = hItem;
- hItem = TreeView_GetNextSibling(hTV,
+ hItem = TreeView_GetNextSibling(hTreeView,
hItem);
if (hItem == NULL)
{
@@ -62,9 +63,9 @@
}
}
- hItem = TreeView_GetParent(hTV,
+ hItem = TreeView_GetParent(hTreeView,
hItem);
- hItem = TreeView_GetNextSibling(hTV,
+ hItem = TreeView_GetNextSibling(hTreeView,
hItem);
}
}
@@ -72,7 +73,7 @@
VOID
-OpenPropSheet(HWND hTV,
+OpenPropSheet(HWND hTreeView,
HTREEITEM hItem)
{
TV_ITEM tvItem;
@@ -80,10 +81,10 @@
tvItem.hItem = hItem;
tvItem.mask = TVIF_PARAM;
- if (TreeView_GetItem(hTV, &tvItem) &&
+ if (TreeView_GetItem(hTreeView, &tvItem) &&
(LPTSTR)tvItem.lParam != NULL)
{
- DevicePropertiesExW(hTV,
+ DevicePropertiesExW(hTreeView,
NULL,
(LPTSTR)tvItem.lParam,
0,
@@ -94,11 +95,12 @@
static HTREEITEM
-InsertIntoTreeView(HWND hTV,
+InsertIntoTreeView(HWND hTreeView,
HTREEITEM hRoot,
LPTSTR lpLabel,
LPTSTR DeviceID,
- INT DevImage)
+ INT DevImage,
+ LONG DevProb)
{
TV_ITEM tvi;
TV_INSERTSTRUCT tvins;
@@ -113,10 +115,21 @@
tvi.iImage = DevImage;
tvi.iSelectedImage = DevImage;
+ if (DevProb != 0)
+ {
+ tvi.stateMask = TVIS_OVERLAYMASK;
+
+ if (DevProb == CM_PROB_DISABLED)
+ {
+ /* FIXME: set the overlay icon */
+ }
+
+ }
+
tvins.item = tvi;
tvins.hParent = hRoot;
- return TreeView_InsertItem(hTV, &tvins);
+ return TreeView_InsertItem(hTreeView, &tvins);
}
@@ -214,13 +227,15 @@
}
-static INT
+static LONG
EnumDevices(INT index,
LPTSTR DeviceClassName,
LPTSTR DeviceName,
LPTSTR *DeviceID)
{
SP_DEVINFO_DATA DeviceInfoData;
+ CONFIGRET cr;
+ LONG Status, ProblemNumber;
DWORD DevIdSize;
*DeviceName = _T('\0');
@@ -276,17 +291,23 @@
NULL))
{
/* if the friendly name fails, try the description instead */
- if (!SetupDiGetDeviceRegistryProperty(hDevInfo,
- &DeviceInfoData,
- SPDRP_DEVICEDESC,
- 0,
- (BYTE*)DeviceName,
- MAX_DEV_LEN,
- NULL))
- {
- /* if the description fails, just give up! */
- return -2;
- }
+ SetupDiGetDeviceRegistryProperty(hDevInfo,
+ &DeviceInfoData,
+ SPDRP_DEVICEDESC,
+ 0,
+ (BYTE*)DeviceName,
+ MAX_DEV_LEN,
+ NULL);
+ }
+
+ cr = CM_Get_DevNode_Status_Ex(&Status,
+ &ProblemNumber,
+ DeviceInfoData.DevInst,
+ 0,
+ NULL);
+ if (cr == CR_SUCCESS && (Status & DN_HAS_PROBLEM))
+ {
+ return ProblemNumber;
}
return 0;
@@ -294,7 +315,7 @@
VOID
-ListDevicesByType(PMAIN_WND_INFO Info,
+ListDevicesByType(HWND hTreeView,
HTREEITEM hRoot)
{
HTREEITEM hDevItem;
@@ -317,23 +338,26 @@
if ((ClassRet != -1) && (DevExist))
{
TCHAR DeviceName[MAX_DEV_LEN];
- INT Ret, DevIndex = 0;
+ INT DevIndex = 0;
+ LONG Ret;
if (DevDesc[0] != _T('\0'))
{
- hDevItem = InsertIntoTreeView(Info->hTreeView,
+ hDevItem = InsertIntoTreeView(hTreeView,
hRoot,
DevDesc,
NULL,
- DevImage);
+ DevImage,
+ 0);
}
else
{
- hDevItem = InsertIntoTreeView(Info->hTreeView,
+ hDevItem = InsertIntoTreeView(hTreeView,
hRoot,
DevName,
NULL,
- DevImage);
+ DevImage,
+ 0);
}
do
@@ -342,13 +366,14 @@
DevName,
DeviceName,
&DeviceID);
- if (Ret == 0)
+ if (Ret >= 0)
{
- InsertIntoTreeView(Info->hTreeView,
+ InsertIntoTreeView(hTreeView,
hDevItem,
DeviceName,
DeviceID,
- DevImage);
+ DevImage,
+ Ret);
}
DevIndex++;
@@ -363,15 +388,15 @@
}
/* don't insert classes with no devices */
- if (!TreeView_GetChild(Info->hTreeView,
+ if (!TreeView_GetChild(hTreeView,
hDevItem))
{
- (void)TreeView_DeleteItem(Info->hTreeView,
+ (void)TreeView_DeleteItem(hTreeView,
hDevItem);
}
else
{
- (void)TreeView_SortChildren(Info->hTreeView,
+ (void)TreeView_SortChildren(hTreeView,
hDevItem,
0);
}
@@ -381,18 +406,18 @@
} while (ClassRet != -1);
- (void)TreeView_Expand(Info->hTreeView,
+ (void)TreeView_Expand(hTreeView,
hRoot,
TVE_EXPAND);
- (void)TreeView_SortChildren(Info->hTreeView,
+ (void)TreeView_SortChildren(hTreeView,
hRoot,
0);
}
HTREEITEM
-InitTreeView(PMAIN_WND_INFO Info)
+InitTreeView(HWND hTreeView)
{
HTREEITEM hRoot;
HBITMAP hComp;
@@ -400,7 +425,7 @@
DWORD dwSize = MAX_PATH;
INT RootImage;
- (void)TreeView_DeleteAllItems(Info->hTreeView);
+ (void)TreeView_DeleteAllItems(hTreeView);
/* get the device image List */
ImageListData.cbSize = sizeof(ImageListData);
@@ -415,7 +440,7 @@
DeleteObject(hComp);
- (void)TreeView_SetImageList(Info->hTreeView,
+ (void)TreeView_SetImageList(hTreeView,
ImageListData.ImageList,
TVSIL_NORMAL);
@@ -428,11 +453,12 @@
RootImage = ImageList_GetImageCount(ImageListData.ImageList) - 1;
/* insert the root item into the tree */
- hRoot = InsertIntoTreeView(Info->hTreeView,
+ hRoot = InsertIntoTreeView(hTreeView,
NULL,
ComputerName,
NULL,
- RootImage);
+ RootImage,
+ 0);
return hRoot;
}
Modified: trunk/reactos/base/applications/devmgmt/mainwnd.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/devmgmt/…
==============================================================================
--- trunk/reactos/base/applications/devmgmt/mainwnd.c (original)
+++ trunk/reactos/base/applications/devmgmt/mainwnd.c Tue Oct 17 19:56:41 2006
@@ -15,7 +15,7 @@
/* Toolbar buttons */
TBBUTTON Buttons [] =
{ /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */
- {TBICON_PROP, IDC_PROP, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0}, /*
properties */
+ {TBICON_PROP, IDC_PROP, TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0}, /*
properties */
{TBICON_REFRESH, IDC_REFRESH, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0}, /* refresh
*/
/* Note: First item for a seperator is its width in pixels */
@@ -198,12 +198,30 @@
}
-
-static VOID
+static DWORD WINAPI
+DeviceEnumThread(LPVOID lpParameter)
+{
+ HTREEITEM hRoot;
+ HWND *hTreeView;
+
+ hTreeView = (HWND *)lpParameter;
+
+ hRoot = InitTreeView(*hTreeView);
+ if (hRoot)
+ {
+ ListDevicesByType(*hTreeView, hRoot);
+ return 0;
+ }
+
+ return -1;
+}
+
+
+static BOOL
InitMainWnd(PMAIN_WND_INFO Info)
{
+ HANDLE DevEnumThread;
HMENU hMenu;
- HTREEITEM hRoot;
if (!CreateToolbar(Info))
DisplayString(_T("error creating toolbar"));
@@ -211,7 +229,7 @@
if (!CreateTreeView(Info))
{
DisplayString(_T("error creating list view"));
- return;
+ return FALSE;
}
if (!CreateStatusBar(Info))
@@ -229,10 +247,21 @@
0);
SetMenuDefaultItem(Info->hShortcutMenu, IDC_PROP, FALSE);
- /* emum all devices */
- hRoot = InitTreeView(Info);
- if (hRoot)
- ListDevicesByType(Info, hRoot);
+ /* create seperate thread to emum devices */
+ DevEnumThread = CreateThread(NULL,
+ 0,
+ DeviceEnumThread,
+ &Info->hTreeView,
+ 0,
+ NULL);
+ if (!DevEnumThread)
+ {
+ DisplayString(_T("Failed to enumerate devices"));
+ return FALSE;
+ }
+
+ CloseHandle(DevEnumThread);
+ return TRUE;
}
@@ -273,11 +302,38 @@
OnNotify(PMAIN_WND_INFO Info,
LPARAM lParam)
{
-
LPNMHDR pnmhdr = (LPNMHDR)lParam;
switch (pnmhdr->code)
{
+ case TVN_SELCHANGED:
+ {
+ LPNM_TREEVIEW pnmtv = (LPNM_TREEVIEW)lParam;
+
+ if (!TreeView_GetChild(Info->hTreeView,
+ pnmtv->itemNew.hItem))
+ {
+ SendMessage(Info->hTool,
+ TB_SETSTATE,
+ IDC_PROP,
+ (LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
+
+ EnableMenuItem(GetMenu(Info->hMainWnd), IDC_PROP, MF_ENABLED);
+ EnableMenuItem(Info->hShortcutMenu, IDC_PROP, MF_ENABLED);
+ }
+ else
+ {
+ SendMessage(Info->hTool,
+ TB_SETSTATE,
+ IDC_PROP,
+ (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
+
+ EnableMenuItem(GetMenu(Info->hMainWnd), IDC_PROP, MF_GRAYED);
+ EnableMenuItem(Info->hShortcutMenu, IDC_PROP, MF_GRAYED);
+ }
+ }
+ break;
+
case NM_DBLCLK:
{
HTREEITEM hSelected = TreeView_GetSelection(Info->hTreeView);
@@ -299,7 +355,7 @@
ScreenToClient(Info->hTreeView, &HitTest.pt))
{
if (TreeView_HitTest(Info->hTreeView, &HitTest))
- (void)TreeView_SelectItem(Info->hTreeView, HitTest.hItem);
+ TreeView_SelectItem(Info->hTreeView, HitTest.hItem);
}
}
break;
@@ -329,7 +385,6 @@
case IDC_EXIT:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_EXIT);
break;
-
}
}
break;
@@ -360,9 +415,17 @@
FreeDeviceStrings(Info->hTreeView);
- hRoot = InitTreeView(Info);
+ hRoot = InitTreeView(Info->hTreeView);
if (hRoot)
- ListDevicesByType(Info, hRoot);
+ ListDevicesByType(Info->hTreeView, hRoot);
+
+ SendMessage(Info->hTool,
+ TB_SETSTATE,
+ IDC_PROP,
+ (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
+
+ EnableMenuItem(GetMenu(Info->hMainWnd), IDC_PROP, MF_GRAYED);
+ EnableMenuItem(Info->hShortcutMenu, IDC_PROP, MF_GRAYED);
}
break;
@@ -458,7 +521,8 @@
GWLP_USERDATA,
(LONG_PTR)Info);
- InitMainWnd(Info);
+ if (!InitMainWnd(Info))
+ SendMessage(hwnd, WM_CLOSE, 0, 0);
/* Show the window */
ShowWindow(hwnd,
@@ -639,3 +703,4 @@
hInstance);
}
+
Modified: trunk/reactos/base/applications/devmgmt/misc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/devmgmt/…
==============================================================================
--- trunk/reactos/base/applications/devmgmt/misc.c (original)
+++ trunk/reactos/base/applications/devmgmt/misc.c Tue Oct 17 19:56:41 2006
@@ -258,21 +258,3 @@
{
MessageBox(NULL, Msg, _T("Note!"), MB_ICONEXCLAMATION|MB_OK);
}
-
-
-VOID TimerInfo(LPTSTR text)
-{
- static HANDLE hOut = NULL;
- DWORD Count;
- TCHAR buf[256];
- static DWORD start = 0;
-
- if (!start) start = GetTickCount();
-
- if (!hOut) hOut = GetStdHandle(STD_ERROR_HANDLE);
-
- if (text) _sntprintf(buf, 256, _T("%s\ttime : %d\n"), text, GetTickCount()
- start);
- else _sntprintf(buf, 256, _T("time : %d\n"), GetTickCount() - start);
-
- WriteConsole(hOut, buf, lstrlen(buf)+1, &Count, NULL);
-}
Modified: trunk/reactos/base/applications/devmgmt/precomp.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/devmgmt/…
==============================================================================
--- trunk/reactos/base/applications/devmgmt/precomp.h (original)
+++ trunk/reactos/base/applications/devmgmt/precomp.h Tue Oct 17 19:56:41 2006
@@ -74,10 +74,10 @@
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);
+VOID FreeDeviceStrings(HWND hTreeView);
+VOID OpenPropSheet(HWND hTreeView, HTREEITEM hItem);
+HTREEITEM InitTreeView(HWND hTreeView);
+VOID ListDevicesByType(HWND hTreeView, HTREEITEM hRoot);
/* misc.c */