软件开发过程中,经常遇到的一个需求:点击某个按钮,启动另外一个独立的可执行程序。
null
这一功能在windows系统下如何实现呢?其实很简单。
#include <windows.h>
#include <tchar.h>
#include <assert.h>
const TCHAR szOperation[] = _T(“open”);
const TCHAR szAddress[] = _T(“https://www.baidu.com/”);
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR lpCmd, int
nShow)
{
HINSTANCE hRslt = ShellExecute(NULL, szOperation,
szAddress, NULL, NULL, SW_SHOWNORMAL);
assert(hRslt > (HINSTANCE)HINSTANCE_ERROR);
return 0;
}
上面是一个特例,即实现打开指定连接的网页的功能,只需调用ShellExecute函数,传递合适的参数,系统自动启动默认浏览器,打开参数指定的网址。
如果需要启动某一exe程序,只需将第三个参数设置为exe的文件全路径名,即可。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容