Process 后, 如何获取打开窗口的句柄(根据进程句柄获取窗口句柄)
来源:互联网 发布:儿童学乐器知乎 编辑:程序博客网 时间:2024/05/16 11:35
using System;using System.Diagnostics;using System.Runtime.InteropServices;using System.Text;namespace Text{ public class Program { [DllImport("user32.dll")] static extern IntPtr GetTopWindow(IntPtr hWnd); [DllImport("user32.dll")] static extern Int32 GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount); [DllImport("user32.dll")] static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount); [DllImport("user32.dll")] static extern IntPtr GetWindow(IntPtr hWnd, UInt32 uCmd); [DllImport("user32.dll")] static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); private static readonly UInt32 GW_HWNDNEXT = 2; static Int32 Run() { Process myProcess = new Process(); myProcess.StartInfo.UseShellExecute = false; myProcess.StartInfo.FileName = "notepad.exe"; myProcess.StartInfo.CreateNoWindow = true; myProcess.Start(); myProcess.WaitForExit(2000); return myProcess.Id; } static IntPtr GetWnd(Int32 pID,String className, String text) { IntPtr h = GetTopWindow(IntPtr.Zero); while (h != IntPtr.Zero) { UInt32 newID; GetWindowThreadProcessId(h, out newID); if (newID == pID) { StringBuilder sbClassName = new StringBuilder(200); StringBuilder sbText = new StringBuilder(200); GetClassName(h, sbClassName, 200); GetWindowText(h, sbText, 200); if (sbClassName.ToString().IndexOf(className,StringComparison.CurrentCultureIgnoreCase) >= 0 && sbText.ToString().IndexOf(text,StringComparison.CurrentCultureIgnoreCase) >= 0) { break; } } h = GetWindow(h, GW_HWNDNEXT); } return h; } static void Main(string[] args) { Console.WriteLine(GetWnd(Run(), "Notepad", "无标题 - 记事本")); Console.ReadKey(); } }}
原文:http://bbs.csdn.net/topics/390157129
0 0
- Process 后, 如何获取打开窗口的句柄(根据进程句柄获取窗口句柄)
- 根据窗口句柄来获取进程ID
- 根据进程id获取主窗口句柄
- 根据进程名称获取窗口句柄
- C++根据进程获取主窗口的句柄
- GetProcessMainWnd(获取进程窗口句柄)
- 纯net获取打开进程的窗口句柄
- 通过进程获取窗口的句柄
- 通过进程获取窗口的句柄
- C#获取进程的主窗口句柄
- C#获取进程的主窗口句柄
- C#获取进程的主窗口句柄
- C#获取进程的主窗口句柄
- 如何根据进程id获取该进程的主窗口句柄
- 如何获取本窗口句柄
- 如何获取其它窗口的句柄
- python 根据标题获取窗口句柄,根据句柄取得进程号,关闭进程
- 获取桌面窗口的句柄
- 史上最简单的Ubuntu上搭建java和Android开发环境
- 杭电1162Eddy's picture(最小生成树)
- Linux下菜单编辑配置
- cocos2dx基础篇——音乐音效SimpleAudioEngine
- 云计算网络虚拟化学习笔记-私有网络
- Process 后, 如何获取打开窗口的句柄(根据进程句柄获取窗口句柄)
- unity调用摄像头
- 文章标题
- 4种常见食物不宜和猪肉搭配
- dfs+剪枝 poj1011
- zoj 1203 Swordfish 【最小生成树 kruskal && prim】
- CodeForces 25A IQ test 唯一奇偶
- session原理
- React Native 简介:用 JavaScript 搭建 iOS 应用(2)