Opening process and changing window position

前端 未结 3 1906
臣服心动
臣服心动 2020-11-28 12:15

I want to open from c# an application (standalone flashplayer) and set it position to (0,0) on the screen. How can I do this? So far I\'ve managed to open flashplayer:

相关标签:
3条回答
  • 2020-11-28 12:46

    Once you start the Process, its MainWindowHandle property should be set to some Windows handle that can be used for manipulating with the main window of the started application. I don't think there is a way to move it directly using .NET API, but you can use the MoveWindow API function via P/Invoke.

    Here are some links where you can find more information:

    • MainWindowHandle property of Process at MSDN
    • MoveWindow API function at pinvoke.net
    0 讨论(0)
  • 2020-11-28 12:47

    thanks guys, it's working now! :)

    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);
    
    
        }
    }
    
    0 讨论(0)
  • 2020-11-28 12:57

    Try SetWindowPos as described here. This page shows how to call it from C#.

    0 讨论(0)
提交回复
热议问题