如何从Visual C ++应用程序执行另一个程序

问题描述 投票:2回答:3

我正在使用Visual Studio Professional 2010做一个软件项目。

以我制作的表单,我想添加一个链接以打开Microsoft Paint。如何执行我的另一个应用程序(MSPaint)?

windows visual-studio-2010 visual-c++
3个回答
5
投票

通过将ShellExecute()作为动词并将ShellExecute()作为文件名,调用open

mspaint.exe

1
投票

我的贡献的完整示例:

转到Visual Studio,创建一个新的Win32 C ++项目(不是控制台),然后将以下代码粘贴到源文件中:

ShellExecute(
    MainFormWindowHandle,
    "open",
    "mspaint.exe",
    NULL,
    NULL,
    SW_SHOW
);

0
投票

我自己提供以下可在Windows中使用的代码

// Win32Project1.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "Win32Project1.h"
#include "shellapi.h"


int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPTSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);



    ShellExecuteA ( NULL, "open", 
        "your.exe", 
        "your params", 
        "working dir", SW_SHOW);


    return TRUE;
}
© www.soinside.com 2019 - 2024. All rights reserved.