Browse Source

增加窗口隐藏API,在Win10的WinTab下隐藏窗口

yuzhengyang 5 years ago
parent
commit
c2821e63a2

+ 40 - 0
Azylee.Utils/Azylee.WinformSkin/APIUtils/FormHideAPI.cs

@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace Azylee.WinformSkin.APIUtils
+{
+    public class FormHideAPI
+    {
+        [DllImport("user32.dll")]
+        private static extern Int32 GetWindowLong(IntPtr hwnd, Int32 index);
+        [DllImport("user32.dll")]
+        private static extern Int32 SetWindowLong(IntPtr hwnd, Int32 index, Int32 newValue);
+
+        private const int GWL_EXSTYLE = (-20);
+        private const int WS_EX_APPWINDOW = 0x00040000;
+        private const int WS_EX_TOOLWINDOW = 0x00000080;
+
+        public static bool HideTabAltMenu(IntPtr hwnd)
+        {
+            bool result = true;
+            int exStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
+            if (exStyle == 0)
+            {
+                result = false;
+            }
+            else
+            {
+                exStyle = exStyle & (~WS_EX_APPWINDOW);
+                exStyle = exStyle | WS_EX_TOOLWINDOW;
+                if (0 == SetWindowLong(hwnd, GWL_EXSTYLE, exStyle))
+                {
+                    result = false;
+                }
+            }
+            return result;
+        }
+    }
+}

+ 1 - 0
Azylee.Utils/Azylee.WinformSkin/Azylee.WinformSkin.csproj

@@ -42,6 +42,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="APIUtils\FormAnimateAPI.cs" />
+    <Compile Include="APIUtils\FormHideAPI.cs" />
     <Compile Include="APIUtils\FormStyleAPI.cs" />
     <Compile Include="ButtonUI\ImageButton.cs">
       <SubType>Component</SubType>

+ 20 - 2
Azylee.Utils/Azylee.WinformSkin/FormUI/Toast/ToastForm.cs

@@ -7,6 +7,7 @@ using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
+using System.Runtime.InteropServices;
 using System.Text;
 using System.Windows.Forms;
 
@@ -74,6 +75,7 @@ namespace Azylee.WinformSkin.FormUI.Toast
         }
         private void ToastForm_Load(object sender, EventArgs e)
         {
+            FormHideAPI.HideTabAltMenu(this.Handle);
             SetPosition();//设置初始位置为右下角,开始栏上方12px
             ShowInTaskbar = false;//不在任务栏显示
             TopMost = true;//显示到最上层窗体
@@ -113,7 +115,7 @@ namespace Azylee.WinformSkin.FormUI.Toast
                     Height = 100;
 
                     while ((byte_len = byte_len - 55) > 0) Height += 20;
-                } 
+                }
             }
             catch { }
 
@@ -223,5 +225,21 @@ namespace Azylee.WinformSkin.FormUI.Toast
             }
         }
         #endregion
-    }
+
+        #region 在系统Win+Tab中隐藏窗口
+        //protected override CreateParams CreateParams
+        //{
+        //    get
+        //    {
+        //        const int WS_EX_APPWINDOW = 0x00040000;
+        //        const int WS_EX_TOOLWINDOW = 0x00000080;
+
+        //        CreateParams result = base.CreateParams;
+        //        result.ExStyle = result.ExStyle & (~WS_EX_APPWINDOW);
+        //        result.ExStyle = result.ExStyle | WS_EX_TOOLWINDOW;
+        //        return result;
+        //    }
+        //} 
+        #endregion
+    } 
 }