zoukankan      html  css  js  c++  java
  • 如何使任意Windows窗口置顶

    在论坛中看到有人问如何可以让任意Windows窗口置顶,这里其实可以使用Windows API函数SetWindowsPos做到。以下是示例代码:

    示例代码演示将一个新打开的记事本程序置顶

     1 [DllImport("user32.dll", SetLastError = true)]
     2 public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
     3 
     4 [DllImport("user32.dll")]
     5 public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
     6 
     7 public static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);    //窗体置顶
     8 public static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);    //取消窗体置顶
     9 public const uint SWP_NOMOVE = 0x0002;    //不调整窗体位置
    10 public const uint SWP_NOSIZE = 0x0001;    //不调整窗体大小
    11 
    12 private void button1_Click(object sender, EventArgs e)
    13 {
    14     //找到默认的打开的记事本程序
    15     IntPtr notepadHandle = FindWindow(null"无标题 - 记事本");
    16     if (notepadHandle == null || notepadHandle == IntPtr.Zero)
    17         return;
    18     SetWindowPos(notepadHandle, HWND_TOPMOST, 1111, SWP_NOMOVE | SWP_NOSIZE);
    19 }
  • 相关阅读:
    Android strings.xml中定义字符串显示空格
    Android各国语言对照表(values-xxx)
    SimInfo获取(MCC, MNC, PLMN)
    Android APN
    Android studio 运行java程序
    [MyBatis]DAO层只写接口,不用写实现类
    idea代码调试debug篇
    比较分析 Spring AOP 和 AspectJ 之间的差别
    maven进阶:一个多模块项目
    Maven最佳实践:划分模块
  • 原文地址:https://www.cnblogs.com/Ricky81317/p/1376745.html
Copyright © 2011-2022 走看看