ShellExecute 声明: Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _ (ByVal hWnd As Long, ByVal lpOperation As String, _ ByVal lpFile As String, ByVal lpParameters As String, _ ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long 原型: HINSTANCE ShellExecute( HWND hwnd, //父窗口句柄 LPCTSTR lpOperation, //操作,"open","print","explore" LPCTSTR lpFile, //文件名,前面可加路径 LPCTSTR lpParameters, //参数 LPCTSTR lpDirectory, //默认文件夹 INT nShowCmd //显示方式 );
打开一个应用程序 ShellExecute(this->m_hWnd,"open","calc.exe","","", SW_SHOW ); 或 ShellExecute(this->m_hWnd,"open","notepad.exe","c:MyLog.log","",SW_SHOW );
打开一个同系统程序相关连的文档 ShellExecute(this->m_hWnd,"open","c:\\abc.txt","","",SW_SHOW );
激活相关程序,发送EMAIL ShellExecute(this->m_hWnd,"open","mailto:iwgh@163.com","","", SW_SHOW );
打开文件夹
ShellExecute(handle, "open", path_to_folder, NULL, NULL, SW_SHOWNORMAL)
用系统打印机打印文档 ShellExecute(this->m_hWnd,"print","c:\\abc.txt","","", SW_HIDE);
本函数还可以用来连接到网页,照下面写就行了: ShellExecute 0&, vbNullString, "", vbNullString, vbNullString, vbNormalFocus
或者这样写来发送Email: ShellExecute me.hwnd, "open", "mailto:iwgh@163.com", vbNullString, vbNullString, SW_SHOW
另外有ShellExecute的替代用法,更加简单实用,不用API,一句Shell搞定!
连接到网页: Shell "rundll32.exe url.dll,FileProtocolHandler " 打开文件: Shell "rundll32.exe url.dll,FileProtocolHandler " & App.Path & "SHELLTST.TXT"
(iwgh) |