• c# 隐藏窗口在ALT+TAB中


    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;
                }
            }

    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);
            }
    
    ————————————————
    
    原文链接:https://blog.csdn.net/qq452626100/article/details/52314283
  • 相关阅读:
    在VS中用CLAPACK解决广义特征值问题
    再议:__cdecl与__stdcall 调用约定在动态链接库调用中不同的表现
    类成员析构、虚析构函数、动态生成对象相关的 关于析构顺序的杂谈
    C++ 中dynamic_cast的使用方法
    函数传值 复制构造函数 深度拷贝
    hdoj_1867A + B for you again
    如何判断一个数是否为素数
    hdoj_2087剪花布条
    STL容器之优先队列
    hdoj_4006优先队列的使用
  • 原文地址:https://www.cnblogs.com/WeiYongZhi/p/12001110.html
Copyright © 2020-2023  润新知