在.NET中使进程窗口可见/不可见

发布于 2024-11-26 05:05:49 字数 336 浏览 0 评论 0原文

我有我的申请,我正在其中开始一个新的流程。但我需要在此过程中调整窗口大小以满足我的要求。但首先该过程以正常大小打开窗口,然后我调整其大小以适应。这让它看起来很奇怪。那么我可以在不可见模式下使用 winodw 启动该过程,然后调整大小并使其可见吗?

ProcessStartInfo startInfo = new ProcessStartInfo("myApp.exe");
MyApp = Process.Start(startInfo);
Thread.Sleep(2000);
MoveWindow(MyApp.MainWindowHandle, 0, 380, 2040, 1150, true);

I have my application, in which I am starting a new process. But I need to resize the window in the process to fit into my requirement. But first the process opens the window in normal size and then I resize it to fit. This make it look odd. So can I start the process with the winodw in invisible mode and then resize and then make it visible?

ProcessStartInfo startInfo = new ProcessStartInfo("myApp.exe");
MyApp = Process.Start(startInfo);
Thread.Sleep(2000);
MoveWindow(MyApp.MainWindowHandle, 0, 380, 2040, 1150, true);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

っ〆星空下的拥抱 2024-12-03 05:05:49

在 .Start() 调用之前尝试过 startInfo.WindowStyle = ProcessWindowStyle.Hidden; 来隐藏它?然后用你的代码来显示它?

像这样:

ProcessStartInfo startInfo = new ProcessStartInfo("myApp.exe");

startInfo.WindowStyle = ProcessWindowStyle.Hidden;

MyApp = Process.Start(startInfo);
Thread.Sleep(2000);
MoveWindow(MyApp.MainWindowHandle, 0, 380, 2040, 1150, true);

要显示窗口,请导入此方法:

[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);

然后在 MoveWindow 函数之后调用它:

ShowWindow(MyApp.MainWindowHandle, 5);

Tried startInfo.WindowStyle = ProcessWindowStyle.Hidden; before .Start() call to hide it? And then use your code to show it?

Like this:

ProcessStartInfo startInfo = new ProcessStartInfo("myApp.exe");

startInfo.WindowStyle = ProcessWindowStyle.Hidden;

MyApp = Process.Start(startInfo);
Thread.Sleep(2000);
MoveWindow(MyApp.MainWindowHandle, 0, 380, 2040, 1150, true);

To show the window import this method:

[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);

Then call it after MoveWindow function:

ShowWindow(MyApp.MainWindowHandle, 5);
就是爱搞怪 2024-12-03 05:05:49

根据 http://msdn.microsoft.com /en-us/library/ms633548%28v=vs.85%29.aspx 您应该对不属于您的 Windows 使用 ShowWindowAsync 以避免不稳定 结果。

According to http://msdn.microsoft.com/en-us/library/ms633548%28v=vs.85%29.aspx you should use ShowWindowAsync for Windows you don't own to avoid erratic results.

℡寂寞咖啡 2024-12-03 05:05:49

考虑到您正在使用正在加载进程的面板。
你可以使用这行代码

 ProcessStartInfo info = new ProcessStartInfo();
 Process p = new process(); // you can also use System.Diagnostics.Process
 ProcessStartInfo info = new ProcessStartInfo();
 info.FileName = // your Process
 info.Arguments = "Your Argument";
 info.UseShellExecute = true;
 info.CreateNoWindow = true;
 info.WindowStyle = ProcessWindowStyle.Maximized; //this will make no effect, so optional
 info.RedirectStandardInput = false;
 info.RedirectStandardOutput = false;
 info.RedirectStandardError = false;
 p = System.Diagnostics.Process.Start(info);
 p.WaitForInputIdle();
 Thread.Sleep(10000);
 SetParent(p.MainWindowHandle, this.pnlAlpha.Handle);
 // You also need to use this line so that your window should be re-sized 
 MoveWindow(p.MainWindowHandle, 0, 0, yourPanel.Width, yourPanel.Height, true);


//Dont forget to add this globally 
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

[DllImport("USER32.dll")]
private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);

considering that you are using a panel where your process is loading..
you can use this line of code

 ProcessStartInfo info = new ProcessStartInfo();
 Process p = new process(); // you can also use System.Diagnostics.Process
 ProcessStartInfo info = new ProcessStartInfo();
 info.FileName = // your Process
 info.Arguments = "Your Argument";
 info.UseShellExecute = true;
 info.CreateNoWindow = true;
 info.WindowStyle = ProcessWindowStyle.Maximized; //this will make no effect, so optional
 info.RedirectStandardInput = false;
 info.RedirectStandardOutput = false;
 info.RedirectStandardError = false;
 p = System.Diagnostics.Process.Start(info);
 p.WaitForInputIdle();
 Thread.Sleep(10000);
 SetParent(p.MainWindowHandle, this.pnlAlpha.Handle);
 // You also need to use this line so that your window should be re-sized 
 MoveWindow(p.MainWindowHandle, 0, 0, yourPanel.Width, yourPanel.Height, true);


//Dont forget to add this globally 
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

[DllImport("USER32.dll")]
private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文