[DEVMGR]
[reactos.git] / reactos / dll / win32 / devmgr / devmgmt / MainWindow.cpp
index 9c6750a..50dc3a9 100644 (file)
@@ -93,7 +93,6 @@ CDeviceManager::~CDeviceManager(void)
 {
 }
 
-
 bool
 CDeviceManager::Create(_In_ HWND /*hWndParent*/,
                        _In_ HINSTANCE hInst,
@@ -132,7 +131,6 @@ CDeviceManager::Create(_In_ HWND /*hWndParent*/,
 }
 
 
-
 /* PRIVATE METHODS **********************************************/
 
 bool
@@ -245,21 +243,36 @@ CDeviceManager::UpdateStatusBar(_In_ bool InMenuLoop)
 }
 
 bool
-CDeviceManager::RefreshView(_In_ ViewType Type)
+CDeviceManager::RefreshView(_In_ ViewType Type,
+                            _In_ bool ScanForChanges)
 {
     UINT CheckId = 0;
 
     // Refreshed the cached view
-    m_DeviceView->Refresh(Type, FALSE, TRUE, NULL);
+    m_DeviceView->Refresh(Type, ScanForChanges, true);
 
     // Get the menu item id
     switch (Type)
     {
-        case DevicesByType: CheckId = IDC_DEVBYTYPE; break;
-        case DevicesByConnection: CheckId = IDC_DEVBYCONN; break;
-        case ResourcesByType: CheckId = IDC_RESBYTYPE; break;
-        case ResourcesByConnection: CheckId = IDC_RESBYCONN; break;
-        default: ATLASSERT(FALSE); break;
+        case DevicesByType:
+            CheckId = IDC_DEVBYTYPE;
+            break;
+
+        case DevicesByConnection:
+            CheckId = IDC_DEVBYCONN;
+            break;
+
+        case ResourcesByType:
+            CheckId = IDC_RESBYTYPE;
+            break;
+
+        case ResourcesByConnection:
+            CheckId = IDC_RESBYCONN;
+            break;
+
+        default:
+            ATLASSERT(FALSE);
+            break;
     }
 
     // Set the new check item
@@ -290,7 +303,8 @@ CDeviceManager::CreateToolBar(void)
                                  (HMENU)IDC_TOOLBAR,
                                  g_hThisInstance,
                                  NULL);
-    if (m_hToolBar == NULL) return FALSE;
+    if (m_hToolBar == NULL)
+        return FALSE;
 
     // Don't show clipped buttons
     SendMessageW(m_hToolBar,
@@ -394,8 +408,6 @@ void CDeviceManager::UpdateToolbar()
     SendMessageW(m_hToolBar, TB_SETSTATE, IDC_DISABLE_DRV, MAKELPARAM(State, 0));
 }
 
-
-
 bool
 CDeviceManager::StatusBarLoadString(_In_ HWND hStatusBar,
                                     _In_ INT PartId,
@@ -437,10 +449,7 @@ CDeviceManager::OnCreate(_In_ HWND hwnd)
         if (m_DeviceView->Initialize())
         {
             // Do the initial scan
-            m_DeviceView->Refresh(m_DeviceView->GetCurrentView(),
-                                  true,
-                                  true,
-                                  NULL);
+            RefreshView(m_DeviceView->GetCurrentView(), true);
 
             // Display the window according to the user request
             ShowWindow(hwnd, m_CmdShow);
@@ -545,7 +554,6 @@ CDeviceManager::OnNotify(_In_ LPARAM lParam)
                     lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_UNINSTALL);
                     break;
             }
-            idButton = idButton;
             break;
         }
     }
@@ -608,13 +616,13 @@ CDeviceManager::OnCommand(_In_ WPARAM wParam,
 
         case IDC_DEVBYTYPE:
         {
-            RefreshView(DevicesByType);
+            RefreshView(DevicesByType, false);
             break;
         }
 
         case IDC_DEVBYCONN:
         {
-            RefreshView(DevicesByConnection);
+            RefreshView(DevicesByConnection, false);
             break;
         }
 
@@ -633,10 +641,7 @@ CDeviceManager::OnCommand(_In_ WPARAM wParam,
                 CheckMenuItem(m_hMenu, IDC_SHOWHIDDEN, MF_BYCOMMAND | MF_CHECKED);
             }
             // Refresh the device view
-            m_DeviceView->Refresh(m_DeviceView->GetCurrentView(),
-                                  false,
-                                  true,
-                                  NULL);
+            RefreshView(m_DeviceView->GetCurrentView(), false);
             break;
         }
 
@@ -672,6 +677,12 @@ CDeviceManager::OnCommand(_In_ WPARAM wParam,
     return RetCode;
 }
 
+void
+CDeviceManager::OnActivate(void)
+{
+    m_DeviceView->SetFocus();
+}
+
 LRESULT
 CDeviceManager::OnDestroy(void)
 {
@@ -781,33 +792,31 @@ CDeviceManager::MainWndProc(_In_ HWND hwnd,
             if (wParam == DBT_DEVNODES_CHANGED)
             {
                 //
-                // The OS can send multiple change messages in quick sucsession. To avoid
+                // The OS can send multiple change messages in quick succession. 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)
+                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);
+                This->RefreshView(This->m_DeviceView->GetCurrentView(), true);
 
                 // Cleanup the timer
                 KillTimer(hwnd, REFRESH_TIMER);
 
                 // Allow more change notifications
-                InterlockedExchange((LONG *)&This->m_RefreshPending, false);
+                InterlockedExchange((LONG *)&This->m_RefreshPending, FALSE);
             }
             break;
         }
@@ -830,7 +839,13 @@ CDeviceManager::MainWndProc(_In_ HWND hwnd,
             DestroyWindow(hwnd);
             break;
         }
-        
+
+        case WM_ACTIVATE:
+        {
+            if (LOWORD(hwnd))
+                This->OnActivate();
+            break;
+        }
 
         case WM_DESTROY:
         {