我正在使用Visual Studio Professional 2010做一个软件项目。
以我制作的表单,我想添加一个链接以打开Microsoft Paint。如何执行我的另一个应用程序(MSPaint)?
通过将ShellExecute()
作为动词并将ShellExecute()
作为文件名,调用open
。
mspaint.exe
我的贡献的完整示例:
转到Visual Studio,创建一个新的Win32 C ++项目(不是控制台),然后将以下代码粘贴到源文件中:
ShellExecute(
MainFormWindowHandle,
"open",
"mspaint.exe",
NULL,
NULL,
SW_SHOW
);
我自己提供以下可在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;
}