在windows下打开其他程序有三个函数:winexec,shellexecute,createprocess
下面我们主要说明ShellExecute
原型如下:
HINSTANCE ShellExecute(
HWND hwnd, //父窗口句柄
LPCTSTR lpOperation, //操作, 打开方式 "edit","explore","open","find","print","NULL"
LPCTSTR lpFile, //文件名,前面可加路径
LPCTSTR lpParameters, //参数
LPCTSTR lpDirectory, //默认文件夹
INT nShowCmd //显示方式
); ShellExecute的功能是运行一个外部程序(或者是打开一个已注册的文件、打开一个目录、打印一个文件等等),并对外部程序有一定的控制。下面是一些例子:
- 打开网页:
- ShellExecute(this->m_hWnd,"open",
- "http://www.google.com","","", SW_SHOW );
- 用记事本打开文件:
- ShellExecute(this->m_hWnd,"open","notepad.exe",
- "c:\\MyLog.log","",SW_SHOW );
- 用系统查找功能来查找指定文件:
- ShellExecute(m_hWnd,"find","d:\\nish",NULL,NULL,SW_SHOW);