diff --git a/Control/UserControls/Config/ThemeControl.xaml b/Control/UserControls/Config/ThemeControl.xaml
index 0159ffc..19be6ef 100644
--- a/Control/UserControls/Config/ThemeControl.xaml
+++ b/Control/UserControls/Config/ThemeControl.xaml
@@ -109,8 +109,18 @@
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Control/UserControls/Config/ThemeControl.xaml.cs b/Control/UserControls/Config/ThemeControl.xaml.cs
index 2640e71..64c3f66 100644
--- a/Control/UserControls/Config/ThemeControl.xaml.cs
+++ b/Control/UserControls/Config/ThemeControl.xaml.cs
@@ -167,6 +167,6 @@ namespace GeekDesk.Control.UserControls.Config
}
appConfig.IsShow = null;
}
-
+
}
}
diff --git a/Control/UserControls/PannelCard/RightCardControl.xaml.cs b/Control/UserControls/PannelCard/RightCardControl.xaml.cs
index 452026e..3d54f10 100644
--- a/Control/UserControls/PannelCard/RightCardControl.xaml.cs
+++ b/Control/UserControls/PannelCard/RightCardControl.xaml.cs
@@ -1051,10 +1051,10 @@ namespace GeekDesk.Control.UserControls.PannelCard
private void VerticalCard_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
- if (appData.AppConfig.EnableEveryThing == true && EveryThingUtil.hasNext())
+ if (appData.AppConfig.EnableEveryThing == true && EveryThingUtil.HasNext())
{
HandyControl.Controls.ScrollViewer sv = sender as HandyControl.Controls.ScrollViewer;
- if (sv.ExtentHeight - (sv.ActualHeight + sv.VerticalOffset) < 200 && EveryThingUtil.hasNext())
+ if (sv.ExtentHeight - (sv.ActualHeight + sv.VerticalOffset) < 200 && EveryThingUtil.HasNext())
{
string[] split = MainWindow.mainWindow.TotalMsgBtn.Content.ToString().Split(' ');
long count = Convert.ToInt64(split[0]);
diff --git a/Control/Windows/ConfigWindow.xaml b/Control/Windows/ConfigWindow.xaml
index 02e7063..788f2d5 100644
--- a/Control/Windows/ConfigWindow.xaml
+++ b/Control/Windows/ConfigWindow.xaml
@@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:xf="clr-namespace:XamlFlair;assembly=XamlFlair.WPF"
- xmlns:local="clr-namespace:GeekDesk"
+ xmlns:local="clr-namespace:GeekDesk" xmlns:viewmodel="clr-namespace:GeekDesk.ViewModel" d:DataContext="{d:DesignInstance Type=viewmodel:AppConfig}"
Title="Setting"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
diff --git a/GeekDesk.csproj b/GeekDesk.csproj
index edb7e0d..cd73dbb 100644
--- a/GeekDesk.csproj
+++ b/GeekDesk.csproj
@@ -294,8 +294,6 @@
-
-
@@ -327,6 +325,7 @@
+
diff --git a/MainWindow.xaml b/MainWindow.xaml
index 9988053..ab250c8 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -27,7 +27,8 @@
MouseDown="MainWindow_MouseDown"
MouseEnter="MainWindow_MouseEnter"
GotFocus="Window_GotFocus"
- Loaded="Window_Loaded"
+ Loaded="Window_Loaded"
+ Topmost="{Binding AppConfig.AlwaysTopmost}"
>
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index bd6f0c9..8b5327e 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -44,7 +44,6 @@ namespace GeekDesk
public static int toDoHotKeyId = -1;
public static int colorPickerHotKeyId = -1;
public static MainWindow mainWindow;
- DelayHelper searchDelayHelper = new DelayHelper(300);
public MainWindow()
{
//加载数据
@@ -54,9 +53,6 @@ namespace GeekDesk
//用于其他类访问
mainWindow = this;
- //置于顶层
- this.Topmost = true;
-
//执行待办提醒
ToDoTask.BackLogCheck();
@@ -354,9 +350,7 @@ namespace GeekDesk
//毛玻璃 暂时未解决阴影问题
//BlurGlassUtil.EnableBlur(this);
- //开启延迟搜索 优化搜索功能
- searchDelayHelper.Idled += SearchDelay;
-
+ WindowUtil.SetOwner(this, WindowUtil.GetDesktopHandle(this, DesktopLayer.Progman));
if (appData.AppConfig.EnableEveryThing == true)
{
@@ -364,7 +358,6 @@ namespace GeekDesk
EveryThingUtil.EnableEveryThing();
}
-
Keyboard.Focus(SearchBox);
MessageUtil.ChangeWindowMessageFilter(MessageUtil.WM_COPYDATA, 1);
@@ -383,7 +376,7 @@ namespace GeekDesk
{
if (MotionControl.hotkeyFinished)
{
- if (mainWindow.Visibility == Visibility.Collapsed || mainWindow.Opacity == 0 || MarginHide.IS_HIDE)
+ if (CheckSholeShowApp())
{
ShowApp();
}
@@ -587,6 +580,7 @@ namespace GeekDesk
ShowWindowFollowMouse.Show(mainWindow, MousePosition.CENTER, 0, 0);
}
+
MainWindow.mainWindow.Activate();
mainWindow.Show();
//mainWindow.Visibility = Visibility.Visible;
@@ -705,7 +699,7 @@ namespace GeekDesk
///
private void NotifyIcon_Click(object sender, RoutedEventArgs e)
{
- if (this.Visibility == Visibility.Collapsed || this.Opacity == 0)
+ if (CheckSholeShowApp())
{
ShowApp();
}
@@ -715,6 +709,14 @@ namespace GeekDesk
}
}
+ private static bool CheckSholeShowApp()
+ {
+ return mainWindow.Visibility == Visibility.Collapsed
+ || mainWindow.Opacity == 0
+ || MarginHide.IS_HIDE
+ || !WindowUtil.WindowIsTop(mainWindow);
+ }
+
///
/// 右键任务栏图标 设置
///
diff --git a/Plugins/EveryThing/EveryThingUtil.cs b/Plugins/EveryThing/EveryThingUtil.cs
index 9f20c7e..e4d00fe 100644
--- a/Plugins/EveryThing/EveryThingUtil.cs
+++ b/Plugins/EveryThing/EveryThingUtil.cs
@@ -32,53 +32,58 @@ namespace GeekDesk.Plugins.EveryThing
new Thread(() =>
{
-
- Thread.Sleep(2000);
-
- //判断EveryThing服务是否已启动
- bool enabled = false;
- Process[] processList = Process.GetProcesses();
- foreach (System.Diagnostics.Process process in processList)
+ try
{
- if (process.ProcessName.ToUpper().Equals("EVERYTHING"))
+ Thread.Sleep(2000);
+
+ //判断EveryThing服务是否已启动
+ bool enabled = false;
+ Process[] processList = Process.GetProcesses();
+ foreach (System.Diagnostics.Process process in processList)
{
- enabled = true;
- IsByGeekDesk = false;
- break;
+ if (process.ProcessName.ToUpper().Equals("EVERYTHING"))
+ {
+ enabled = true;
+ IsByGeekDesk = false;
+ break;
+ }
}
- }
- if (!enabled)
- {
- //启动服务
+ if (!enabled)
+ {
+ //启动服务
+ using (Process p = new Process())
+ {
+ p.StartInfo.FileName = everyThingPath;
+ p.StartInfo.UseShellExecute = true;
+ p.StartInfo.Verb = "runas";
+ p.StartInfo.Arguments = " -svc";
+ p.Start();
+ }
+ }
+
+ Thread.Sleep(2000);
+ processList = Process.GetProcesses();
+
+ //启动程序
using (Process p = new Process())
{
p.StartInfo.FileName = everyThingPath;
- p.StartInfo.UseShellExecute = true;
- p.StartInfo.Verb = "runas";
- p.StartInfo.Arguments = " -svc";
p.Start();
+ int waitTime = 3000;
+ while (true && waitTime > 0)
+ {
+ Thread.Sleep(100);
+ waitTime -= 100;
+ p.CloseMainWindow();
+ }
+
}
- }
-
- Thread.Sleep(2000);
- processList = Process.GetProcesses();
-
-
- //启动程序
- using (Process p = new Process())
+ } catch (Exception e)
{
- p.StartInfo.FileName = everyThingPath;
- p.Start();
- int waitTime = 3000;
- while (true && waitTime > 0)
- {
- Thread.Sleep(100);
- waitTime -= 100;
- p.CloseMainWindow();
- }
}
+
}).Start();
}
@@ -101,7 +106,7 @@ namespace GeekDesk.Plugins.EveryThing
}
- public static bool hasNext()
+ public static bool HasNext()
{
return ui < Everything_GetNumResults();
}
diff --git a/Util/DelayHelper.cs b/Util/DelayHelper.cs
deleted file mode 100644
index 125c35a..0000000
--- a/Util/DelayHelper.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace GeekDesk.Util
-{
- public class DelayHelper
- {
- public event EventHandler Idled = delegate { };
- public int WaitingMilliSeconds { get; set; }
-
- public object Source { get; set; }
-
- readonly System.Threading.Timer waitingTimer;
-
- public DelayHelper(int waitingMilliSeconds = 600)
- {
- WaitingMilliSeconds = waitingMilliSeconds;
- waitingTimer = new System.Threading.Timer(p =>
- {
- Idled(this, EventArgs.Empty);
- });
- }
-
-
- public void DelayExecute(object source)
- {
- this.Source = source;
- waitingTimer.Change(WaitingMilliSeconds, System.Threading.Timeout.Infinite);
- }
- }
-}
diff --git a/Util/DelayHelperFlyoutMenuItem.cs b/Util/DelayHelperFlyoutMenuItem.cs
deleted file mode 100644
index 9250cd3..0000000
--- a/Util/DelayHelperFlyoutMenuItem.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace GeekDesk.Util
-{
- public class DelayHelperFlyoutMenuItem
- {
- public DelayHelperFlyoutMenuItem()
- {
- TargetType = typeof(DelayHelperFlyoutMenuItem);
- }
- public int Id { get; set; }
- public string Title { get; set; }
-
- public Type TargetType { get; set; }
- }
-}
\ No newline at end of file
diff --git a/Util/WindowUtil.cs b/Util/WindowUtil.cs
new file mode 100644
index 0000000..0d224b2
--- /dev/null
+++ b/Util/WindowUtil.cs
@@ -0,0 +1,141 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Forms;
+using System.Windows.Interop;
+
+namespace GeekDesk.Util
+{
+ public class WindowUtil
+ {
+
+ public enum GetWindowCmd : uint
+ {
+ GW_HWNDFIRST = 0,
+ GW_HWNDLAST = 1,
+ GW_HWNDNEXT = 2,
+ GW_HWNDPREV = 3,
+ GW_OWNER = 4,
+ GW_CHILD = 5,
+ GW_ENABLEDPOPUP = 6
+ }
+
+ [Flags]
+ public enum SetWindowPosFlags
+ {
+ SWP_NOSIZE = 0x0001,
+ SWP_NOMOVE = 0x0002,
+ SWP_NOZORDER = 0x0004,
+ SWP_NOREDRAW = 0x0008,
+ SWP_NOACTIVATE = 0x0010,
+ SWP_FRAMECHANGED = 0x0020,
+ SWP_SHOWWINDOW = 0x0040,
+ SWP_HIDEWINDOW = 0x0080,
+ SWP_NOCOPYBITS = 0x0100,
+ SWP_NOOWNERZORDER = 0x0200,
+ SWP_NOSENDCHANGING = 0x0400
+ }
+
+ //取得前台窗口句柄函数
+ [DllImport("user32.dll")]
+ private static extern IntPtr GetForegroundWindow();
+ //取得桌面窗口句柄函数
+ [DllImport("user32.dll")]
+ private static extern IntPtr GetDesktopWindow();
+ [DllImport("user32.dll", CharSet = CharSet.Auto)]
+ private static extern IntPtr FindWindow(string className, string windowName);
+ [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
+ private static extern IntPtr GetWindow(HandleRef hWnd, int nCmd);
+ [DllImport("user32.dll")]
+ private static extern IntPtr SetParent(IntPtr child, IntPtr parent);
+ [DllImport("user32.dll", EntryPoint = "GetDCEx", CharSet = CharSet.Auto, ExactSpelling = true)]
+ private static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hrgnClip, int flags);
+ [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
+ private static extern bool SetWindowPos(HandleRef hWnd, HandleRef hWndInsertAfter, int x, int y, int cx, int cy, int flags);
+ [DllImport("user32.dll")]
+ private static extern int ReleaseDC(IntPtr window, IntPtr handle);
+
+
+
+ public static void SetOwner(Window source, IntPtr parentHandle)
+ {
+ WindowInteropHelper helper = new WindowInteropHelper(source);
+ helper.Owner = parentHandle;
+ }
+
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static bool WindowIsTop(Window window)
+ {
+ IntPtr handle = new WindowInteropHelper(window).Handle;
+ IntPtr deskHandle = GetDesktopHandle(window, DesktopLayer.Progman);
+ IntPtr deskHandle2 = GetDesktopHandle(window, DesktopLayer.FolderView);
+ IntPtr deskHandle3 = GetDesktopHandle(window, DesktopLayer.SHELLDLL);
+ IntPtr topHandle = GetForegroundWindow();
+ return (topHandle.Equals(handle) || topHandle.Equals(deskHandle));
+ }
+
+
+
+
+ public const int GW_CHILD = 5;
+
+ public static IntPtr GetDesktopHandle(Window window, DesktopLayer layer)
+ {
+ HandleRef hWnd;
+ IntPtr hDesktop = new IntPtr();
+ switch (layer)
+ {
+ case DesktopLayer.Progman:
+ hDesktop = FindWindow("Progman", null);//第一层桌面
+ break;
+ case DesktopLayer.SHELLDLL:
+ hDesktop = FindWindow("Progman", null);//第一层桌面
+ hWnd = new HandleRef(window, hDesktop);
+ hDesktop = GetWindow(hWnd, GW_CHILD);//第2层桌面
+ break;
+ case DesktopLayer.FolderView:
+ hDesktop = FindWindow("Progman", null);//第一层桌面
+ hWnd = new HandleRef(window, hDesktop);
+ hDesktop = GetWindow(hWnd, GW_CHILD);//第2层桌面
+ hWnd = new HandleRef(window, hDesktop);
+ hDesktop = GetWindow(hWnd, GW_CHILD);//第3层桌面
+ break;
+ }
+ return hDesktop;
+ }
+
+ public void EmbedDesktop(Object embeddedWindow, IntPtr childWindow, IntPtr parentWindow)
+ {
+ Form window = (Form)embeddedWindow;
+ HandleRef HWND_BOTTOM = new HandleRef(embeddedWindow, new IntPtr(1));
+ const int SWP_FRAMECHANGED = 0x0020;//发送窗口大小改变消息
+ SetParent(childWindow, parentWindow);
+ SetWindowPos(new HandleRef(window, childWindow), HWND_BOTTOM, 300, 300, window.Width, window.Height, SWP_FRAMECHANGED);
+ }
+ }
+
+ public enum DesktopLayer
+ {
+ Progman = 0,
+ SHELLDLL = 1,
+ FolderView = 2
+ }
+
+
+
+
+
+
+
+}
diff --git a/ViewModel/AppConfig.cs b/ViewModel/AppConfig.cs
index 29af1c9..61b62f4 100644
--- a/ViewModel/AppConfig.cs
+++ b/ViewModel/AppConfig.cs
@@ -107,6 +107,22 @@ namespace GeekDesk.ViewModel
private bool? enableEveryThing;
+ private bool? alwaysTopmost;
+
+
+ public bool? AlwaysTopmost
+ {
+ get
+ {
+ if (alwaysTopmost == null) alwaysTopmost = false;
+ return alwaysTopmost;
+ }
+ set
+ {
+ alwaysTopmost = value;
+ OnPropertyChanged("AlwaysTopmost");
+ }
+ }
public bool? EnableEveryThing
{