c# 隐藏窗口在ALT+TAB中
2016-08-25 14:36
92 查看
WPF:
#region Window styles [Flags] public enum ExtendedWindowStyles { // ... WS_EX_TOOLWINDOW = 0x00000080, // ... } public enum GetWindowLongFields { // ... GWL_EXSTYLE = (-20), // ... } [DllImport("user32.dll")] public static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex); public static IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong) { int error = 0; IntPtr result = IntPtr.Zero; // Win32 SetWindowLong doesn't clear error on success SetLastError(0); if (IntPtr.Size == 4) { // use SetWindowLong Int32 tempResult = IntSetWindowLong(hWnd, nIndex, IntPtrToInt32(dwNewLong)); error = Marshal.GetLastWin32Error(); result = new IntPtr(tempResult); } else { // use SetWindowLongPtr result = IntSetWindowLongPtr(hWnd, nIndex, dwNewLong); error = Marshal.GetLastWin32Error(); } if ((result == IntPtr.Zero) && (error != 0)) { throw new System.ComponentModel.Win32Exception(error); } return result; } [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", SetLastError = true)] private static extern IntPtr IntSetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong); [DllImport("user32.dll", EntryPoint = "SetWindowLong", SetLastError = true)] private static extern Int32 IntSetWindowLong(IntPtr hWnd, int nIndex, Int32 dwNewLong); private static int IntPtrToInt32(IntPtr intPtr) { return unchecked((int)intPtr.ToInt64()); } [DllImport("kernel32.dll", EntryPoint = "SetLastError")] public static extern void SetLastError(int dwErrorCode); #endregion private void image_Loaded(object sender, RoutedEventArgs e) { WindowInteropHelper wndHelper = new WindowInteropHelper(this); int exStyle = (int)GetWindowLong(wndHelper.Handle, (int)GetWindowLongFields.GWL_EXSTYLE); exStyle |= (int)ExtendedWindowStyles.WS_EX_TOOLWINDOW; SetWindowLong(wndHelper.Handle, (int)GetWindowLongFields.GWL_EXSTYLE, (IntPtr)exStyle); }
winform:
protected override CreateParams CreateParams
{
get
{
const int WS_EX_APPWINDOW = 0x40000;
const int WS_EX_TOOLWINDOW = 0x80;
CreateParams cp = base.CreateParams;
cp.ExStyle &= (~WS_EX_APPWINDOW); // 不显示在TaskBar
cp.ExStyle |= WS_EX_TOOLWINDOW; // 不显示在Alt-Tab
return cp;
}
}
相关文章推荐
- 怎样让窗口不显示在任务栏和ALT+TAB中(隐藏窗口再嵌套,几乎是万能的办法)
- C# 隐藏窗体 ALT+TAb不可见
- C#打印时如何隐藏打印窗口
- C# 窗口全屏 隐藏任务栏 (代码)
- C# 调用控制台程序同时隐藏控制台窗口
- 转:隐藏C#控制台程序运行时的窗口
- C#窗体 隐藏标题栏后 移动窗口的方法
- Alt-Tab不能切换当前窗口的问题
- 在C#隐藏启动窗口的几种方法
- c# 隐藏控制台窗口
- 【转载】c# tabcontrol控件标签如何隐藏?
- C#窗体隐藏标题栏后,鼠标可拖动窗口的代码!
- C# 窗口全屏 隐藏任务栏 (代码)
- [转]在C#隐藏启动窗口的几种方法
- c#如何实现双击TabContrl关闭Tab,隐藏tab标签
- c# tabcontrol 隐藏索引标签,代码是现成的组件
- 怎样让窗口不显示在任务栏和ALT+TAB中
- c# 如何隐藏TabControl控件的标签
- C#隐藏主窗口的方法
- C# WINForm 如何关闭系统进程,调用cmd并执行命令(隐藏CMD窗口) - 赤色火焰 - 京华志