From 6ed09fb64b7c926ad972a0f9ba7073c013205e06 Mon Sep 17 00:00:00 2001 From: Ged Murphy Date: Thu, 22 Oct 2015 17:21:30 +0000 Subject: [PATCH] [DEVMGR] - Automatically refresh the view whenever there is a hardware change on the machine - Don't force a refresh when we enable/disable devices, this is now be picked up automatically svn path=/trunk/; revision=69649 --- .../dll/win32/devmgr/devmgmt/DeviceView.cpp | 8 +--- .../dll/win32/devmgr/devmgmt/MainWindow.cpp | 41 ++++++++++++++++++- reactos/dll/win32/devmgr/devmgmt/MainWindow.h | 1 + reactos/dll/win32/devmgr/precomp.h | 2 + 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/reactos/dll/win32/devmgr/devmgmt/DeviceView.cpp b/reactos/dll/win32/devmgr/devmgmt/DeviceView.cpp index ec9429147ac..388a258e30c 100644 --- a/reactos/dll/win32/devmgr/devmgmt/DeviceView.cpp +++ b/reactos/dll/win32/devmgr/devmgmt/DeviceView.cpp @@ -700,13 +700,7 @@ CDeviceView::EnableSelectedDevice( } } - if (Node->EnableDevice(Enable, NeedsReboot)) - { - Refresh(m_ViewType, true, true, Node->GetDeviceId()); - return true; - } - - return false; + return Node->EnableDevice(Enable, NeedsReboot); } bool diff --git a/reactos/dll/win32/devmgr/devmgmt/MainWindow.cpp b/reactos/dll/win32/devmgr/devmgmt/MainWindow.cpp index 7b3ba55ddba..9c6750ac043 100644 --- a/reactos/dll/win32/devmgr/devmgmt/MainWindow.cpp +++ b/reactos/dll/win32/devmgr/devmgmt/MainWindow.cpp @@ -21,6 +21,8 @@ #define BTN_UPDATE_DRV 4 #define BTN_UNINSTALL_DRV 5 +#define REFRESH_TIMER 1 + HINSTANCE g_hThisInstance = NULL; HINSTANCE g_hParentInstance = NULL; @@ -81,7 +83,8 @@ CDeviceManager::CDeviceManager(void) : m_hMainWnd(NULL), m_hStatusBar(NULL), m_hToolBar(NULL), - m_CmdShow(0) + m_CmdShow(0), + m_RefreshPending(false) { m_szMainWndClass = L"DevMgmtWndClass"; } @@ -773,6 +776,42 @@ CDeviceManager::MainWndProc(_In_ HWND hwnd, break; } + case WM_DEVICECHANGE: + { + if (wParam == DBT_DEVNODES_CHANGED) + { + // + // The OS can send multiple change messages in quick sucsession. To avoid + // refreshing multiple times (and to avoid waiting in the message thread) + // we set a timer to run in 500ms, which should leave enough time for all + // the messages to come through. Wrap so we don't set multiple timers + // + if (InterlockedCompareExchange((LONG *)&This->m_RefreshPending, true, false) == false) + { + SetTimer(hwnd, REFRESH_TIMER, 500, NULL); + } + } + break; + } + case WM_TIMER: + { + if (wParam == REFRESH_TIMER) + { + // Schedule a refresh (this just creates a thread and returns) + This->m_DeviceView->Refresh(This->m_DeviceView->GetCurrentView(), + true, + true, + NULL); + + // Cleanup the timer + KillTimer(hwnd, REFRESH_TIMER); + + // Allow more change notifications + InterlockedExchange((LONG *)&This->m_RefreshPending, false); + } + break; + } + case WM_ENTERMENULOOP: { This->UpdateStatusBar(true); diff --git a/reactos/dll/win32/devmgr/devmgmt/MainWindow.h b/reactos/dll/win32/devmgr/devmgmt/MainWindow.h index 7202c1f945a..d78c89aedf7 100644 --- a/reactos/dll/win32/devmgr/devmgmt/MainWindow.h +++ b/reactos/dll/win32/devmgr/devmgmt/MainWindow.h @@ -17,6 +17,7 @@ class CDeviceManager HMENU m_hMenu; HMENU m_hActionMenu; int m_CmdShow; + bool m_RefreshPending; public: CDeviceManager(void); diff --git a/reactos/dll/win32/devmgr/precomp.h b/reactos/dll/win32/devmgr/precomp.h index 2a3c6322d95..92c8e109011 100644 --- a/reactos/dll/win32/devmgr/precomp.h +++ b/reactos/dll/win32/devmgr/precomp.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit @@ -59,6 +60,7 @@ OUT LPDWORD lpReboot); #include #include #include +#include #include #include