用C#代码打开exe文件,如何控制窗口弹出的位置

解决方案 »

  1.   

    因为外部引用的EXE文件,不受C#管辖,所以要控制窗口位置,必须使用API,参考WIN32 API的相关函数:SetWindowsEx,FindWindowsEx等。
      

  2.   

    exe要是你编写的,接受个位置参数作为启动参数不就OK了。
    exe要不是你写的,你就参考楼下的答案。
      

  3.   

            public const int HWND_TOPMOST = -1;
            public const int SWP_NOMOVE = 0x2;
            public const int SWP_NOSIZE = 0x1;        [DllImport("user32.dll", SetLastError = true)]
            static extern IntPtr FindWindow(string lpClassName, string lpWindowName);        [DllImport("user32.dll")]
            static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X,
              int Y, int cx, int cy, uint uFlags);        [DllImport("user32.dll")]
            static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth,
              int nHeight, bool bRepaint); private void Test()
            {
                IntPtr hWnd = FindWindow("CabinetWClass", null);
                if (hWnd.ToInt32() != 0)
                {
    //Get positions of the specified window(GetWindowPlacement).
                    SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE + SWP_NOMOVE);
                    MoveWindow(hWnd, 90, 27, 461, 426, true);
                }
            }