打开过程和改变窗口位置
我想从c#应用程序(独立flashplayer)打开并在屏幕上将其设置为(0,0)。 我怎样才能做到这一点? 到目前为止,我已经成功打开了flashplayer:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace swflauncher { class Program { static void Main(string[] args) { Process flash = new Process(); flash.StartInfo.WindowStyle = ProcessWindowStyle.Normal; flash.StartInfo.FileName = "D:\\development\\flex4\\runtimes\\player\\10\\win\\FlashPlayer.exe"; flash.Start(); } } }
按照此处的说明尝试SetWindowPos
。 此页面显示如何从C#调用它。
谢谢你们,它现在正在工作! 🙂
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading; namespace swflauncher { class Program { static void Main(string[] args) { Process flash = new Process(); flash.StartInfo.WindowStyle = ProcessWindowStyle.Normal; flash.StartInfo.FileName = "D:\\development\\flex4\\runtimes\\player\\10\\win\\FlashPlayer.exe"; flash.Start(); Thread.Sleep(100); IntPtr id = flash.MainWindowHandle; Console.Write(id); Program.MoveWindow(flash.MainWindowHandle, 0, 0, 500, 500, true); } [DllImport("user32.dll", SetLastError = true)] internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); } }
启动Process
,应将其MainWindowHandle
属性设置为某个Windows句柄,该句柄可用于使用已启动应用程序的主窗口进行操作。 我认为没有办法直接使用.NET API移动它,但您可以通过P / Invoke使用MoveWindow
API函数。
以下是一些链接,您可以在其中找到更多信息:
- MSDN 上
Process
MainWindowHandle
属性 - Movevindow API函数在pinvoke.net上