te(this->m_hWnd,"open", " http://www.google.com","","",/ SW_SHOW );
(4)激活相关
程序,发送EMAIL
ShellExecute(this->m_hWnd,"open","mailto:nishinapp@yahoo.com","","", W_SHOW );
(5)用系统打印机打印文档
ShellExecute(this->m_hWnd,"print", "c:\abc.txt","","", SW_HIDE);
(6)用系统查找功能来查找指定文件
ShellExecute(m_hWnd,"find","d:\nish", NULL,NULL,SW_SHOW);
(7)启动一个
程序,直到它运行结束
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "c:\MyProgram.exe";
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
或:
PROCESS_INFORMATION ProcessInfo;
STARTUPINFO StartupInfo; //This is an [in] parameter
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field
if(CreateProcess("c:\winnt\notepad.exe", NULL,
NULL,NULL,FALSE,0,NULL,
NULL,&StartupInfo,&ProcessInfo))
{
WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
}
else
{
MessageBox("The process could not be started");
}
(8)显示文件或文件夹的属性
SHELLEXECUTEINFO ShExecInfo ={0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_INVOKEIDLIST ;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = "properties";
ShExecInfo.lpFile = "c:"; //can be a file as well
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
Windows还提供了一个与ShellExecuteEx()函数相类似的函数WinExec(),它相对于ShellExecuteEx()来说更简单易用,只是功能没有它强大而已,具体使用方法读者朋友自行参阅MSDN。
二、编程步骤
l、启动Visual C++6.0,生成一个基于对话框的应用程序,将该
程序命名为"Test";
2、在对话框上放置一个静态控件,并显示一幅图象;
3、使用Class Wizard为应用程序添加一个CMapHyperLink类,其基类为CStatic;
4、在对话框中添加一个CmapHyperLink类对象m_MapHyperLink1;
5、添加代码,编译运行程序。
三、程序代码
/////////////////////////////////////////////////////////////////////////
//MapHyperLink.h , MapHyperLink.cpp
#if !defined(AFX_HYPERLINK_H__D1625061_574B_11D1_ABBA_00A0243D1382__INCLUDED_)
#define AFX_HYPERLINK_H__D1625061_574B_11D1_ABBA_00A0243D1382__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// CHyperLink window
class CMapHyperLink : public CStatic
{
// Construction/destruction
public:
CMapHyperLink();
virtual ~CMapHyperLink();
public:
void SetURL(CString strURL);
CString GetURL() const;
void SetTipText(CString str