是否可以从另一个正在运行的窗口表单应用程序中运行窗口表单应用程序 [英] Is it possible to run a window form application from another running window form application

查看:56
本文介绍了是否可以从另一个正在运行的窗口表单应用程序中运行窗口表单应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从另一个正在运行的窗口表单应用程序中运行窗口表单应用程序?如有可能,请提供帮助.谢谢

Is it possible to run a window form application from another running window form application? If possible, then please help.Thanks

推荐答案

Pong提供了答案.
但是,通过这种方式,两个进程无法通信.

我觉得您的意思是在另一个应用程序的内部运行一个应用程序.如果您没有两个应用程序的源代码,那将不容易.如果您有源代码,那么最好的办法就是对代码进行重新处理,使其在一个应用程序和一个进程中运行.

如果您没有"guest"或"child"应用程序的源代码,我不建议您解决此问题-不能保证良好的结果并且很难实现.

1)您可以通过System.Diagnostic.Process将子"应用程序作为子进程运行,获取两个应用程序的主要形式的Windows句柄(使用Process.MainWindowHandle获取其中一个子进程)和P/Invoke并使用Windows API功能SetParent.结果取决于子应用程序的工作方式-此技巧可能会造成破坏.

2)您可以使用Reflection提取使用通过System.Reflection.Assembly.LoadFrom加载的"guest"应用程序程序集的主要形式的类.您可以尝试获取其主要形式的类,将其实例化并通过Form.Show添加到应用程序的Application中.这样,您将只有一个过程,这总是更好.第二个程序集将用作库,而不用作具有自己进程的单独应用程序.解决这个问题不是一件容易的事,而且可能破坏第二个装配体的功能.

同样,尝试任何一种方法都需要研究.在某些情况下,它将起作用.通常情况下,结果无法保证.

—SA
Pong provided the answer.
However, in this way the two processes cannot communicate.

I feel that you mean running one application inside the form of another one. If you don''t have source code of both applications, it is not easy. If you have source codes, best you can do is re-work the code the way they run in one application and one process.

If you don''t have the source code of "guest" or "child" application, I do not recommend addressing this problem — the good results are not guaranteed and hard to achieve.

1) You can run "child" application as a child process via System.Diagnostic.Process, get windows handles of the main forms of both application (use Process.MainWindowHandle to get the one of the child process) and P/Invoke and use Windows API function SetParent. The result depends on how child application works — this trick can be disruptive.

2) You can use Reflection to extract the class of the main form of using the "guest" application assembly of loaded through System.Reflection.Assembly.LoadFrom. You can try to get the class of it''s main form, instantiate it and add to your application''s Application through Form.Show. In this way, you will have only one process, which is always better. The second assembly will be used as the library, not as a separate application with its own process. Solving this problem is not very easy and also could be disruptive to the functionality of the second assembly.

Again, trying any of those approaches is a matter of research. In certain cases it will work. In the general case the result is not guaranteed.

—SA


是的.尝试这样的事情.

Yes it is. Try something like this.

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.FileName="c:\\codeproject\\test.exe";
proc.Start();


这篇关于是否可以从另一个正在运行的窗口表单应用程序中运行窗口表单应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆