winfrom启动三方exe程序,让三方exe窗体在屏幕下方显示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
     [DllImport("user32.dll")]
     static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
 
     [DllImport("user32.dll")]
     static extern bool MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool bRepaint);
 
     [DllImport("user32.dll", SetLastError = true)]
     public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
 
     const int SWP_SHOWWINDOW = 0x0040;
     static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
     public struct RECT
     {
         public int Left;
         public int Top;
         public int Right;
         public int Bottom;
     }
 
private void button1_Click(object sender, EventArgs e)
     {
         // string executablePath = @"C:\Users\Administrator\Desktop\WindowsFormsApp2\WindowsFormsApp2\bin\Debug\WindowsFormsApp2.exe";
         string executablePath = Properties.Settings.Default.executablePath;
         Process process = Process.Start(executablePath);
         process.WaitForInputIdle(); // 等待进程变为可互动状态
         Thread.Sleep(1000);
         IntPtr hWnd = process.MainWindowHandle;
      
         if (hWnd != IntPtr.Zero)
         {
             int screenWidth = Screen.PrimaryScreen.WorkingArea.Width;
             int screenHeight = Screen.PrimaryScreen.WorkingArea.Height;
             RECT rect;
             GetWindowRect(hWnd, out rect);
             // 计算窗口的宽度和高度
             int windowWidth = rect.Right - rect.Left;
             int windowHeight = rect.Bottom - rect.Top;
 
             // 设置窗口位置和大小
             SetWindowPos(hWnd, IntPtr.Zero, rect.Left, screenHeight - windowHeight, windowWidth, windowHeight, SWP_SHOWWINDOW);
 
         }
     }

  

posted @   fulllove  阅读(38)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示