private void HandleWindowOpenedEvent(IntPtr hwnd)
        {
            if (Process.GetCurrentProcess().MainWindowHandle == hwnd) return;
            if (_openWindows.ContainsKey(hwnd)) return;

            var activatedWindow = User32.GetForegroundWindow();
            var active = activatedWindow == hwnd;

            StringBuilder windowTitleBuilder = new StringBuilder {Length = 300};
            User32.GetWindowText(hwnd, windowTitleBuilder, 300);

            var path = ProcessUtility.GetPathFromHandle(hwnd);

            var item = new OpenItemViewModel(hwnd, windowTitleBuilder.ToString(), path);
            _openWindows.TryAdd(hwnd, item);

            if (active)
            {
                HandleWindowActivatedEvent(hwnd, false);
            }
            ExecuteOnUiThread(RaiseOpenWindowsChanged);
        }
 public void ActivateWindow(OpenItemViewModel openWindowVm)
 {
     User32.SetForegroundWindow(openWindowVm.Hwnd);
 }