运行exe应用程序并保存他的工作 [英] run exe application and save his work

查看:71
本文介绍了运行exe应用程序并保存他的工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题.

我使用vb.net在桌面上运行 .exe 应用程序,该应用程序具有一个MenuItem标头,其名称为文件",其中包含几个MenuItem Commands ex.复制,粘贴,保存,另存为...
如何使用vb在该应用程序上运行命令保存".
保存命令与"CTRL + S"一起使用,但是如何使用我的vb应用程序在桌面上的应用程序上运行该命令?

Hi guys,I have a problem.

I running an .exe application from desktop with vb.net,and that application has a MenuItem Header which name is "File" which consist of few MenuItem Commands ex. Copy,Paste,Save,Save As...
How to run command "Save" on that application using a vb.
Save command work with "CTRL+S",but how to run that command on application which is on desktop using my vb application???

推荐答案

通常,这是这是一个很糟糕的主意,是一个肮脏的编程领域,没有真正可靠或可支持的东西.某些应用程序开发了一个称为自动化"的功能,该功能将由某些外部过程控制,但此类应用程序应为此专门设计并提供适当的API.对我来说,自动化仍然是肮脏的东西,但它有时会被使用并且被认为是合法的.

如果这是一个通用的UI应用程序,而您的艰辛生活确实迫使您做不好的事情,那么您需要三件事:

1)使用System.Diagnostics.Process.Start运行应用程序,请参见 http://msdn.microsoft.com/zh-cn/library/system.diagnostics.process.aspx [ http://msdn.microsoft.com/zh-我们/library/windows/desktop/ms633507%28v=vs.85%29.aspx [ http://msdn.microsoft.com/en-us/library/system. diagnostics.process.mainwindowhandle.aspx [ ^ ],
http://msdn.microsoft.com/zh-我们/library/windows/desktop/ms646311%28v=vs.85%29.aspx [ http://msdn.microsoft.com/zh-我们/library/windows/desktop/ms633539%28v=vs.85%29.aspx [ http://msdn.microsoft.com/zh-我们/library/windows/desktop/ms633507%28v=vs.85%29.aspx [ http://msdn.microsoft.com/zh-我们/library/windows/desktop/ms646310%28v=vs.85%29.aspx [ http://en.wikipedia.org/wiki/P/invoke [ http://msdn.microsoft.com/en-us/library/Aa712982 [ ^ ].

此CodeProject文章也可能有用:
基本P/调用 [
Generally, this is quite a bad idea, a dirty field of programming, nothing really reliable or supportable. Some applications develops a feature called "Automation" to be controlled by some external process, but such applications should be specially designed for this and provide appropriate API. To me, automation is still dirty stuff, but it is used sometimes and is considered legitimate.

If this is a general-purpose UI application, and you hard life really forces you into doing bad stuff, you need three things:

1) Run application using System.Diagnostics.Process.Start, see http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[^].

2) When a process is started, you can use the property Process.MainWindowHandle to manipulate it using raw Windows API such as SetForegroundWindow, SetActiveWindow, GetLastActivePopup, please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633507%28v=vs.85%29.aspx[^] (good in case the application executes some dialog boxes, etc., using P/Invoke (see below). Remember that that handle can by zero, which means that it is not yet created, then you should repeat the call to the property a bit later. Please see:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainwindowhandle.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646311%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633539%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633507%28v=vs.85%29.aspx[^].

3) You can simulate use input on a low level using raw Windows API SendInput via P/Invoke, please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].

In you need to learn P/Invoke, please see:
http://en.wikipedia.org/wiki/P/invoke[^],
http://msdn.microsoft.com/en-us/library/Aa712982[^].

This CodeProject article can also be useful:
Essential P/Invoke[^].

Do you really want all this for the questionable benefit of controlling some stupid UI application? To tell you the truth, I would not bother. :-)

—SA


这篇关于运行exe应用程序并保存他的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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