使用Process.Start()时如何在活动显示上打开应用程序?

编程入门 行业动态 更新时间:2024-10-25 02:23:08
本文介绍了使用Process.Start()时如何在活动显示上打开应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用

System.Diagnostics.Process.Start(ProcessInfo);

从我的Windows窗体应用程序中在记事本中打开一个TEXT文件.

to open a TEXT file in notepad from within my windows form application.

详细的代码段为

ProcessStartInfo PSI = new ProcessStartInfo("notepad.exe", LogFile); PSI.WindowStyle = ProcessWindowStyle.Normal; System.Diagnostics.Process p = System.Diagnostics.Process.Start(PSI);

但是,它会在默认桌面上打开记事本,但不会在运行主应用程序的扩展桌面上打开记事本.

However, it opens notepad on the default desktop but not on the extended desktop on which the main application is running.

现在,问题是,如何在活动桌面(即运行当前应用程序的窗口)上打开记事本?

Now, the question is, how to open notepad on the active desktop i.e. Window on which the current application is running?

推荐答案

除了指定初始窗口状态(正常,隐藏等)外,您基本上无法控制新启动的应用程序的启动方式以及显示位置

Other that specifying the initial window state (normal, hidden, etc), you have basically no control over how the newly launched application starts up and where it shows itself.

这里最好的选择是启动应用程序,然后使用其窗口句柄告诉它移动.所有这些都需要使用P/Invoke来调用 MoveWindow .所有这些功能的C#签名都在 pinvoke 上.

The best bet here is to launch the application, then use its window handle to tell it to move. This all requires using P/Invoke, to call MoveWindow. The C# signatures for all of those functions are on pinvoke.

这是一个非常简单的(VB.NET)示例,其中显示了基本概念.在这种情况下,正如@Lloyd指出的那样,您需要的窗口句柄是从 Process.Start 返回的 Process.MainWindowHandle .请注意, Process.MainWindowHandle 不会立即填写.您通常需要调用 WaitForInputIdle 以确保实际上已创建窗口.如果 MainWindowHandle 为0,那么您就会知道它为时过早.

Here's a very simple (VB.NET) example that shows the basic idea. In this case, as @Lloyd points out, the window handle you need is the Process.MainWindowHandle you get back from Process.Start. Note that Process.MainWindowHandle isn't filled in immediately; you typically need to call WaitForInputIdle to make sure the window actually gets created. If MainWindowHandle is 0 then you'll know it's too soon.

更多推荐

使用Process.Start()时如何在活动显示上打开应用程序?

本文发布于:2023-11-13 10:44:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584160.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   如何在   Process   Start

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!