• C# 禁用窗口激活


    如果界面点击时,不想让窗口激活,可以按如下操作:

     1     public MainWindow()
     2     {
     3         InitializeComponent();
     4         SourceInitialized += OnSourceInitialized;
     5     }
     6     private void OnSourceInitialized(object sender, EventArgs e)
     7     {
     8         var handle = (PresentationSource.FromVisual(this) as HwndSource).Handle;
     9         var exstyle = User32.GetWindowLong(handle, GWL_EXSTYLE);
    10         User32.SetWindowLong(handle, GWL_EXSTYLE, new IntPtr(exstyle.ToInt32() | WS_EX_NOACTIVATE));
    11     }
    12     public const int WS_EX_NOACTIVATE = 0x08000000;
    13     public const int GWL_EXSTYLE = -20;

    User32函数:

    1     [DllImport("user32.dll", EntryPoint = "GetWindowLong")]
    2     public static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);
    3 
    4     [DllImport("user32.dll", EntryPoint = "SetWindowLong")]
    5     public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
  • 相关阅读:
    石子合并之一
    最长公共子序列
    最长上升子序列
    剑圣的逃跑
    方格取数
    数字三角形
    Omkar and Last Class of Math
    IDEA中对代码进行测试
    Spark(一)【spark-3.0安装和入门】
    HTTP请求 Java API
  • 原文地址:https://www.cnblogs.com/kybs0/p/16069916.html
Copyright © 2020-2023  润新知