如何从一个不同的进程关闭一个窗口 [英] how to close a window from a different process

查看:139
本文介绍了如何从一个不同的进程关闭一个窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想指示关机很好,从一个不同的进程C#应用程序。
我也希望能够要求它以打开其主窗口。
我有它的主窗口句柄的引用。



我知道我可以通过周密的计划,如远程处理或WCF做到这一点。
的问题是使用简单的机制,如窗口消息,或者在C#应用程序


解决方案<窗口的OnClose事件处理它,我可以做/ DIV>

的PInvoke的SendMessage()发送WM_CLOSE消息应用程序的主窗口。要求它打开它的主窗口可能将是相当困难的,直到创建窗口,你不能获得的窗口句柄。的Process.Start()会以正常的方式。



一个低成本的替代方案,以WCF和优越的PInvoke是命名管道或与应用程序接口的插座。这需要能够修改该应用的源代码。


I have a c# application which I want to instruct to shutdown nicely, from a different process. I also want to be able to ask it to open its main window. I have a reference to its main window handle.

I know I can do it using elaborate schemes such as remoting or WCF. the question is can I do it using simpler mechanisms such as window messages, or the OnClose event handlers of the window in the c# application

解决方案

Pinvoke SendMessage() to send the WM_CLOSE message to the app's main window. Asking it to open its main window is probably going to be quite difficult, you cannot obtain the window handle until the window is created. Process.Start() would be the normal way.

A low cost alternative to WCF and superior to pinvoke is a named pipe or a socket to interface with the app. This requires being able to modify the source code of the app.

这篇关于如何从一个不同的进程关闭一个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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