当前位置: 首页 > news >正文

c#遍历窗口,根据标题获取handle并显示窗口

using System.Runtime.InteropServices;

using System.Text;

//1,定义

//[DllImport("User32.dll", EntryPoint = "FindWindow")]

//public extern static IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)]

public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);

//[DllImport("user32.dll")]

//public static extern int GetWindowTextLength(IntPtr hWnd);

[DllImport("User32.dll", CharSet = CharSet.Auto)]

public static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int nMaxCount);

//[DllImport("user32.dll")]

//private static extern int GetClassName(IntPtr hWnd, StringBuilder lpString, int nMaxCount);

// Callback Declaration

public delegate bool EnumWindowsCallback(IntPtr hwnd, int lParam);

[DllImport("user32.dll")]

private static extern int EnumWindows(EnumWindowsCallback callPtr, int lParam);

private EnumWindowsCallback callBackFn = new EnumWindowsCallback(ReportWindow);

private static StringBuilder title = new StringBuilder(256);

//2,回调方法的具体实现

public static bool ReportWindow(IntPtr hwnd, int lParam)

{

GetWindowText(hwnd, title, title.Capacity);

if ("TestWindow".Equals(title.ToString()))

{

//MessageBox.Show("找到了!"); //窗口的title: TestWindow

ShowWindow(hwnd, 8);

}

return true;

}

//3,调用回调方法

EnumWindows(callBackFn, 0);

http://www.lryc.cn/news/28347.html

相关文章:

  • MyBatis高频面试专题
  • 曹云金郭德纲关系迎曙光,新剧《猎黑行动》被德云社弟子齐点赞
  • 如何在 OpenEuler 系统中安装 Docker
  • MySQL日志管理
  • 进 制
  • pycharm关联github、新建以及更新仓
  • java基础知识之小碎片(自问自答版本)---嘻嘻,春招加油呀~
  • 蚁群算法c++
  • 北大青鸟天府校区IT学习大揭秘
  • 04 Linux errno.h错误码中文注释
  • MySQL表的约束
  • Go语言的条件控制语句及循环语句的学习笔记
  • D. Linguistics(思维 + 贪心)
  • maxWell数据迁移
  • 混合图像python旗舰版
  • 开发手册——一、编程规约_5.集合处理
  • 【elastic】elastic高可用集群部署
  • 初识Liunx下的进程状态和环境变量以及进程优先级
  • JavaEE——何为线程及创建线程
  • linux配置核查MySQL 配置规范 (Linux)_S3A3G3
  • Protobuf简介
  • 【Kubernetes】第十七篇 - ECS 服务停机和环境修复
  • Vue2的生命周期(详解)
  • Potions (Hard Version) and (Easy Version)(背包DP + 反悔贪心)
  • 剑指 Offer II 017. 含有所有字符的最短字符串
  • Modbus协议初探(C#实现)
  • 【华为OD机试2023】静态扫描 C++ Java Python
  • 函数栈帧的创建和销毁(详解)
  • 【100个 Unity实用技能】 | 脚本无需挂载到游戏对象上也可执行的方法
  • 条件期望5