C#操作移动其他程序窗口
2014-05-05 09:55
141 查看
在这里使用了Win32 API来做的。可以使用C#根据窗体的路径,启动一个进程,然后使用Win32 API控制打开窗口的位置和大小。
主要代码如下:
public class A
{
//调用Win32 API
[System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "MoveWindow")]
public static extern bool MoveWindow(System.IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
//打开窗体方法,fileName是C++的窗体名称,包含路径
private void OpenAndSetWindow(String fileName)
{
Process p = new Process();//新建进程
p.StartInfo.FileName = fileName;//设置进程名字
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
p.Start();
MoveWindow(p.MainWindowHandle, 200, 300, 500, 400, true);
//p.MainWindowHandle是你要移动的窗口的句柄;200,300是移动后窗口左上角的横纵坐标;500,400是移动后窗口的宽度和高度;true表示移动后的窗口是需要重画
}
}
如果打开IE网页,可以成下面语句一句
p.StartInfo.FileName = "iexplore";
p.StartInfo.Arguments = "www.baidu.com";//网页
分类: C#学习
主要代码如下:
public class A
{
//调用Win32 API
[System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "MoveWindow")]
public static extern bool MoveWindow(System.IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
//打开窗体方法,fileName是C++的窗体名称,包含路径
private void OpenAndSetWindow(String fileName)
{
Process p = new Process();//新建进程
p.StartInfo.FileName = fileName;//设置进程名字
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
p.Start();
MoveWindow(p.MainWindowHandle, 200, 300, 500, 400, true);
//p.MainWindowHandle是你要移动的窗口的句柄;200,300是移动后窗口左上角的横纵坐标;500,400是移动后窗口的宽度和高度;true表示移动后的窗口是需要重画
}
}
如果打开IE网页,可以成下面语句一句
p.StartInfo.FileName = "iexplore";
p.StartInfo.Arguments = "www.baidu.com";//网页
分类: C#学习
相关文章推荐
- C#操作移动其他程序窗口
- C#操作移动其他程序窗口
- C#父窗口和其他窗口之间实现控件互操作
- C# 关闭其他程序窗口、进程
- C#进程启动程序,并禁止原窗口操作
- C#隐藏其他程序窗口以及添加最小化/最大化按钮
- Java调用Win32实现操作其他程序窗口
- 在使用C#调用COM组件操作Excel的时候阻止其他程序对此文件操作
- C# 关闭其他程序窗口、进程
- delphi有关获取其他程序的窗口及对窗口内控件的操作
- C# 关闭其他程序窗口、进程
- c#控制其他程序窗口位置
- C#实现关闭其他程序窗口或进程代码分享
- c# 关闭其他程序窗口/进程
- c# .net 如何截取当前程序窗口指定位置的截图
- 利用C#线程窗口调试多线程程序
- c#随机抽人(随机抽组,抽奖,搜索匹配)程序(基于.net窗口)
- C#实现对外部程序的调用操作
- Delphi 获取其他程序窗口句柄
- C# 对文件与文件夹的操作包括删除、移动与复制