从C ++代码打开文件菜单 [英] Open File Menu from c++ code

查看:185
本文介绍了从C ++代码打开文件菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在VC ++ 2008 Express中编写了一个程序,当输入所有必要信息时,它将在另一个程序(扩展名为.mpt)中打开一个文件.

但是,无论出于何种原因,打开"actualFile.mpt"只不过是打开快捷方式"MPT.exe",而不会打开实际文件.

也许我甚至都不敢问这个问题,但是有没有办法从我的C ++代码中执行File-> Open Product ...,并让程序选择要在此MPT软件中打开的文件?

我用来打开文件的调用很简单:

I have written a program in VC++ 2008 Express that, when all necessary information is entered, it opens a file in another program (.mpt extension).

However, for whatever reason, opening "actualFile.mpt" does nothing more than opening the shortcut "MPT.exe", and does not open the actual file.

Maybe I''m being too optimistic even asking this, but is there a way to, from my c++ code, to do a File->Open Product... and have the program select the file to open inside this MPT software?

The call I''m using to open the file is simply:

system(mptFile.c_str());



希望有人能帮忙;预先感谢,
帕特


谢谢各位的帮助.如果有人好奇,我最终使用的命令是"MPT.exe -lmptFile.mpt".



Hope someone can help; thanks in advance,
Pat


Thanks for all the help everyone. If anyone is curious, the command I ended up using is "MPT.exe -lmptFile.mpt".

推荐答案

尝试使用字符串"MPT.exeactualFile"进行调用. mpt".如果MPT的命令行允许传递文件打开,则可以使用.
Try calling with the string "MPT.exe actualFile.mpt". If the command line of MPT allows passing a file to open, this could work.


而不是:

Instead of:

system("actualFile.mpt");



试试:



Try:

system("mpt.exe actualFile.mpt");



或(更加完整):



Or (to be more complete):

CString command;
command.Format("mpt.exe \"%s\"", mptFile);
system(command.c_str());



如果mpt.exe在您的路径中,则实际上应该调用mpt.exe.

然后,唯一的问题是mpt.exe程序是否实际上解析了它的命令行并在命令行上打开了文件,或者它是否期望某种命令行开关. (例如"mpt.exe/o filename.mpt"或类似的名称.)如果您没有关于mpt.exe在其命令行中期望的内容的文档,则始终可以尝试使用从命令窗口,看看您是否可以找到起作用的东西.



If mpt.exe is in your path, then that should actually invoke mpt.exe.

The only question then is if the mpt.exe program actually parses it''s command line and opens files on the command line, or if it expects some sort of command line switch. (Such as "mpt.exe /o filename.mpt" or something similar.) If you don''t have documentation on what mpt.exe expects on it''s command line, you can always experiment with variations typed in from the command window and see if you can hit on something that works.


它不取决于我们的代码,而是取决于系统中如何注册"mtp"扩展名(以及哪个程序)它通过调用哪个参数来调用),并通过该程序的功能来支持在命令行给定的情况下自动打开文件.

您实际上尝试尝试对程序进行特定的调用,例如建议在此处 [^ ] ,但这对于生产"来说不是一个好主意.

假装某个特定应用程序位于用户计算机的路径中不是一个好习惯:想象一下是一台计算机的用户,其中有100个应用程序假装位于用户计算机的路径中.无论您调用什么命令,都将在整个硬盘上运行.没办法!
It does not depend on our code, but on how the "mtp" extension is registered in the system (and hence which program it invokes, with which parameters) and by the capability of that program to support an automatic file open when given by the command line.

You an actually try with a specific invocation of the program like suggested here[^], but it is not a good idea for "production".

Pretending a specific app to be in the path of the user''s computer isn''t a good practice: imagine to be the user of a computer with 100 apps pretending to be in the path. Whatever command you invoke, you run across the entire hard-disk. Not the way to go!


这篇关于从C ++代码打开文件菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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