白痴问题:怎么在一个程序中运行另一个程序?

ustc_tweeg 2002-05-03 10:47:42
如果还要传递参数呢?。。。。。。。。。。。
...全文
118 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ustc_tweeg 2002-05-04
  • 打赏
  • 举报
回复
试验成功,酷毙了!只有50分,用洋文的少点,三二开吧。
shawn_liu 2002-05-04
  • 打赏
  • 举报
回复
MSDN中关于ShellExecute的说明

ShellExecute
Performs an operation on a specified file.



HINSTANCE ShellExecute(
HWND hwnd,
LPCTSTR lpVerb,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);

Parameters
hwnd
Handle to a parent window. This window receives any message boxes that an application produces. For example, an application may report an error by producing a message box.
lpVerb
A string, referred to as a verb, that specifies the action to be performed. The set of available verbs depends on the particular file or folder. Generally, the actions available from an object's context menu are available verbs. For more information about verbs and their availability, see Object Verbs. See Extending Context Menus for further discussion of context menus. The following verbs are commonly used: Verb Description
edit Launches an editor and opens the document for editing. If lpFile is not a document file, the function will fail.
explore Explores the folder specified by lpFile.
find Initiates a search starting from the specified directory.
open Opens the file specified by the lpFile parameter. The file can be an executable file, a document file, or a folder.
print Prints the document file specified by lpFile. If lpFile is not a document file, the function will fail.
properties Displays the file or folder's properties.
If you set this paramater to NULL:

For systems prior to Microsoft® Windows® 2000, the default verb is used if it is valid and available in the registry. If not, the "open" verb is used.
For Windows 2000 and later systems, the default verb is used if available. If not, the "open" verb is used. If neither verb is available, the system uses the first verb listed in the registry.
lpFile
Address of a null-terminated string that specifies the file or object on which to execute the specified verb. To specify a shell namespace object, pass the fully-qualified parse name. Note that not all verbs are supported on all objects. For example, not all document types support the "print" verb.
lpParameters
If the lpFile parameter specifies an executable file, lpParameters is an address to a null-terminated string that specifies the parameters to be passed to the application.The format of this string is determined by the verb that is to be invoked. If lpFile specifies a document file, lpParameters should be NULL.
lpDirectory
Address of a null-terminated string that specifies the default directory.
nShowCmd
Flags that specify how an application is to be displayed when it is opened. If lpFile specifies a document file, the flag is simply passed to the associated application. It is up to the application to decide how to handle it.
SW_HIDE Hides the window and activates another window.
SW_MAXIMIZE Maximizes the specified window.
SW_MINIMIZE Minimizes the specified window and activates the next top-level window in the z-order.
SW_RESTORE Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.
SW_SHOW Activates the window and displays it in its current size and position.
SW_SHOWDEFAULT Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application. An application should call ShowWindow with this flag to set the initial show state of its main window.
SW_SHOWMAXIMIZED Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE Displays the window as a minimized window. The active window remains active.
SW_SHOWNA Displays the window in its current state. The active window remains active.
SW_SHOWNOACTIVATE Displays a window in its most recent size and position. The active window remains active.
SW_SHOWNORMAL Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.

Return Values
Returns a value greater than 32 if successful, or an error value that is less than or equal to 32 otherwise. The following table lists the error values. The return value is cast as an HINSTANCE for backward compatibility with 16-bit Microsoft® Windows® applications. It is not a true HINSTANCE, however. The only thing that can be done with the returned HINSTANCE is to cast it to an integer and compare it with the value 32 or one of the error codes below.

0 The operating system is out of memory or resources.
ERROR_FILE_NOT_FOUND The specified file was not found.
ERROR_PATH_NOT_FOUND The specified path was not found.
ERROR_BAD_FORMAT The .exe file is invalid (non-Win32® .exe or error in .exe image).
SE_ERR_ACCESSDENIED The operating system denied access to the specified file.
SE_ERR_ASSOCINCOMPLETE The file name association is incomplete or invalid.
SE_ERR_DDEBUSY The DDE transaction could not be completed because other DDE transactions were being processed.
SE_ERR_DDEFAIL The DDE transaction failed.
SE_ERR_DDETIMEOUT The DDE transaction could not be completed because the request timed out.
SE_ERR_DLLNOTFOUND The specified dynamic-link library was not found.
SE_ERR_FNF The specified file was not found.
SE_ERR_NOASSOC There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable.
SE_ERR_OOM There was not enough memory to complete the operation.
SE_ERR_PNF The specified path was not found.
SE_ERR_SHARE A sharing violation occurred.

Remarks
This method allows you to execute any commands in a folder's context menu or stored in the registry.

To open a folder, use either of the following calls:

ShellExecute(handle, NULL, path_to_folder, NULL, NULL, SW_SHOWNORMAL);

or

ShellExecute(handle, "open", path_to_folder, NULL, NULL, SW_SHOWNORMAL);

To explore a folder, use:

ShellExecute(handle, "explore", path_to_folder, NULL, NULL, SW_SHOWNORMAL);

To launch the shell's Find utility for a directory, use:

ShellExecute(handle, "find", path_to_folder, NULL, NULL, 0);

If lpOperation is NULL, the function opens the file specified by lpFile. If lpOperation is "open" or "explore", the function will attempt to open or explore the folder.

With multiple monitors, if you specify the window handle and set lpOperation to "Properties", any windows created by ShellExecute may not appear in the correct position.

To obtain information about the application that is launched as a result of calling ShellExecute, use ShellExecuteEx.
ustc_tweeg 2002-05-03
  • 打赏
  • 举报
回复
ShellExecute(NULL,"open","iloveu.bmp",NULL,NULL,SW_SHOWNORMAL);
no error no warning 但执行后什么都没有why?那图的路径要不要设呀。。。
开ie的那个太爽了!!
xb4270293 2002-05-03
  • 打赏
  • 举报
回复
我使用MFC编写一个APP,要求About对话框中显示LOGO、公司名、地址和公司的URL链接。使用户点击URL链接以后,启动浏览器访问Web页面,这种对话框中的热链接使应用程序增色不少。我琢磨的方法是从系统注册表中通过查找.htm 或 .html文件的关联程序来获得缺省浏览器的名字,这样好象有很多工作要做。此外,如果浏览器已经打开,总是开始一个新的实例替代当前已有的一个实例。想找一个容易一点的方法,但我查过有关的资料,没有收获,请高手指教。
解决方法:
如果有这样的一个API函数该多好:OpenThisHereURLForMeNowPlease(),问题不就解决了!!我告诉你吧,有,但它不是你所想象的那个函数。到目前为止,有关文档中还没有提到过这么一个有用的函数,它能打开桌面上的任何文件,也能打开Internet URL。唯一我能找到的参考资料是在Microsoft® Access KnowledgeBase中很暧昧地提到过这个函数。
这个不可思议的函数就是:ShellExecute,取代了WinExec。你可以给它任何文件的名字,它都能识别出来并打开它。例如:

ShellExecute(NULL,"open","iloveu.bmp",NULL,NULL,SW_SHOWNORMAL);


用缺省的位图编辑器打开一个叫iloveu.bmp的位图文件,这个缺省的位图编辑器可能是Microsoft Paint, Adobe Photoshop, 或者 Corel PhotoPaint。

有关ShellExecute的详细用法信息自己去参考有关资料吧,重要的是你知道了这个函数能打开任何文件,甚至是桌面和URL快捷方式( .ink或 .url)。ShellExecute解析系统注册表HKEY_CLASSES_ROOT中所有的内容,判断启动那一个执行程序,并且启动一个新的实例或使用DDE将文件名连到一打开的实例。然后,ShellExecute 返回打开文件的应用的实例句柄。

更奇妙的是ShellExecute不仅能打开机器上的文件,还能打开Internet的站点地址。例如:

ShellExecute(NULL, "open", "http://www.microsoft.com", NULL, NULL, SW_SHOWNORMAL);
这个代码使你能访问微软的主页。当ShellExecute遇到文件名前面的“http:”时,可以判断出要打开的文件是Web文件,随之启动Internet Explorer 或者 Netscape Navigator 或者任何你使用的别的浏览器打开文件。ShellExecute还能识别其它协议,象FTP、GOPHER。甚至识别“mailto”,如果文件名指向“mailto:zxn@hq.cninfo.net”,它启动电子邮件程序并打开一个待编辑的新邮件。总之,ShellExecute函数就是如此简单地打开磁盘文件和Internet文件。如果将第二个参数“OPEN”改为“PRINT”或者“EXPLORE”,ShellExecute将能打印文件和打开文件夹。ShellExecute还有一个扩展函数ShellExecuteEx,所带参数中有一个特殊的结构,功能更强,它的用法参见有关文档。

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧