打开过程和改变窗口位置

bar*_*tek 13 c#

我想从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();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

bar*_*tek 42

谢谢你们,它现在正在工作!:)

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);


    }
}
Run Code Online (Sandbox Code Playgroud)

  • 比答案要好得多,因为你真的很想分享工作代码,谢谢. (12认同)

Tom*_*cek 5

启动后Process,MainWindowHandle应将其属性设置为某个Windows句柄,该句柄可用于使用已启动应用程序的主窗口进行操作.我认为没有办法直接使用.NET API移动它,但您可以MoveWindow通过P/Invoke 使用API函数.

以下是一些链接,您可以在其中找到更多信息:

  • Process.WaitForInputIdle()将很重要. (2认同)

Han*_*son 4

SetWindowPos请按照此处所述进行尝试。本页展示了如何从 C# 调用它。

  • 这不是一个好的答案,因为没有提供工作代码。此外,显示“如何从 C# 调用它”的页面一团糟,而且实际上并未提供功能齐全的示例(未知方法 GetActiveWindowHandle)。作者的较低答案要好得多。简洁且实用。 (7认同)