C# 怎么获取刚刚打开的那个窗体的句柄啊 在做一个打开一个播放器让它自动最大化的那个东西,获取刚打开的那个播放器的句柄 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 窗体对象.Handle不就可以了么。2L貌似很多帖子都是这句:“查了资料,想了很久,还是没能解答你的问题,不过还是帮你顶上,希望高手光临......” 或者findwindow来查询窗体句柄如果不适用就用EnumWindow来遍历窗体 用C# 干嘛要用Windows的APIC#不是提供了UIAutomaiton类么,这个就是专么用来自动化测试的,里面可以去操作其他窗体 调用API 代码这里 有兴趣可以看下 汗 没分结贴了。#region 打开指定的文件 public static Process OpenFile(string filePath) { int num = 0; Process pro = null; try { if (File.Exists(filePath)) { pro = Process.Start(filePath); while (num < 10) { num++; Action action = new Action(delegate() { Thread.Sleep(500); IntPtr ht = pro.MainWindowHandle; ShowWindow(pro.MainWindowHandle, 3); //将窗口最大化 SetForegroundWindow(pro.MainWindowHandle); //如果没有ShowWindow,此方法不能设置最小化的窗口 }); action.BeginInvoke(null, null); } } } catch (Exception ex) { throw; } return pro; } [DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)] public static extern int ShowWindow(IntPtr hwnd, int nCmdShow); [DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr hWnd); } #endregion 求推荐好用的地图功能控件 C# 给定一个路径字符串,怎样判断是文件还是文件夹? 如何实现校内网自动登陆写日志? 对listbox中的items进行筛选 如何将一个文件创建在指定N层还没有创建的目录下? ListView的SelectedIndexChanged事件如何将当前所有选中的行取消 listView 中的查找,与删除 FastReport.Net保存流问题 如何进行类型转换 声明,Iiuri<>liuri,C#学习小组msn联系人名单不是liuri所发 客户端如何通过服务端跟其他客户端发送信息 wcf data service 怎么取表的数据总数
2L貌似很多帖子都是这句:“查了资料,想了很久,还是没能解答你的问题,不过还是帮你顶上,希望高手光临......”
#region 打开指定的文件
public static Process OpenFile(string filePath)
{
int num = 0;
Process pro = null;
try
{
if (File.Exists(filePath))
{
pro = Process.Start(filePath);
while (num < 10)
{
num++;
Action action = new Action(delegate()
{
Thread.Sleep(500);
IntPtr ht = pro.MainWindowHandle;
ShowWindow(pro.MainWindowHandle, 3); //将窗口最大化
SetForegroundWindow(pro.MainWindowHandle); //如果没有ShowWindow,此方法不能设置最小化的窗口
});
action.BeginInvoke(null, null);
}
}
}
catch (Exception ex)
{ throw;
}
return pro;
}
[DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
}
#endregion