指定窗口标题,历遍当前窗口,返回窗口句柄(数组) 在网上找几遍,都写得好长,写得好复杂~~求指教:如果我现在在系统中打开了三个标题为“测试窗口”的窗口,那么如何精确得到他们的句柄?尽量要短,这样看起来可以很快吸收,我在网上找了一天,就会了个模糊擦找的,达不到要求~~写成一个类吧,太谢谢你了~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 补充一下,我这里只是距离三个窗口,大哥千万不要for 3来写,呵呵,窗口数量不一定的 不知这样是否符合你的要求// 调用List<IntPtr> list = GetHandles("测试窗口");// 方法private List<IntPtr> GetHandles(string title){ List<IntPtr> handles = new List<IntPtr>(); foreach (Form item in Application.OpenForms) { if (item.Text == title) { handles.Add(item.Handle); } } return handles;} 调用enumchildwindows api做递归 [DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto)]public static extern IntPtr FindWindowEx( IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow );List<IntPtr> result = new List<IntPtr>();IntPtr hWnd = IntPtr.Zero;do{ hWnd = FindWindowEx(IntPtr.Zero, hWnd, null, "测试窗口"); if (hWnd != IntPtr.Zero) { result.Add(hWnd); }}while (hWnd != IntPtr.Zero);return result; 4L 正解 用api findwindow或者 用Process 列出所有进程 然后查看每个进程的标题.. c# winform 取整个电脑所有磁盘文件,如图 c#如何调用VC++ DLL,参数为字符串或字符数组.+100分相送. WinForm下实现不规则窗体,设定Region的问题 [winform]如何取得数据库中的所有表名 跪求:关于Server.URLEncode的问题 2006年,第一贴~关于。NET程序结构问题。 C#写OPCClient 问大家一个很复杂问题,请各位高手进来指点? 请问哪里有MSDN2002下载? 有关自动生成txt文件的问题?? TreeView节点重命名问题 会用FreeTextBox控件的麻烦帮看下
// 调用
List<IntPtr> list = GetHandles("测试窗口");
// 方法
private List<IntPtr> GetHandles(string title)
{
List<IntPtr> handles = new List<IntPtr>();
foreach (Form item in Application.OpenForms)
{
if (item.Text == title)
{
handles.Add(item.Handle);
}
}
return handles;
}
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr FindWindowEx(
IntPtr hwndParent,
IntPtr hwndChildAfter,
string lpszClass,
string lpszWindow
);List<IntPtr> result = new List<IntPtr>();
IntPtr hWnd = IntPtr.Zero;
do
{
hWnd = FindWindowEx(IntPtr.Zero, hWnd, null, "测试窗口");
if (hWnd != IntPtr.Zero)
{
result.Add(hWnd);
}
}
while (hWnd != IntPtr.Zero);
return result;
或者 用Process 列出所有进程 然后查看每个进程的标题..