在VC中为应用程序添加图形超链接功能
void UpdateTipText( LPCTSTR lpszText, CWnd* pWnd, UINT nIDTool = 0 ); |
该函数的参数的含义与成员函数AddTool()的参数的含义大同小异,这里不再赘述。
对于超链接来说,一般会在超链接区域改变鼠标的形状,显示手状的鼠标,提示这是一个超链接区域。当然可以在程序中添加一个手状的光标资源,然后使用LoadCursor()函数等加载,这种方法对广大读者朋友一定是耳熟能详了,所以为了扩大读者朋友的编程思路,这里介绍一种从Windows的winhlp32.exe文件中加载光标资源,代码如下:
void CMapHyperLink::SetDefaultCursor() { if (m_hLinkCursor == NULL) // No cursor handle - load our own { // Get the windows directory CString strWndDir; GetWindowsDirectory(strWndDir.GetBuffer(MAX_PATH), MAX_PATH); strWndDir.ReleaseBuffer(); strWndDir += _T("\winhlp32.exe"); // This retrieves cursor #106 from winhlp32.exe, which is a hand pointer HMODULE hModule = LoadLibrary(strWndDir); if (hModule) { HCURSOR hHandCursor = ::LoadCursor(hModule, MAKEINTRESOURCE(106)); if (hHandCursor) m_hLinkCursor = CopyCursor(hHandCursor); } FreeLibrary(hModule); } } |
为了根据网页或信箱地址实现超链接功能,需要用到一个WINDOWS API函数ShellExecute(),其原型为:
HINSTANCE ShellExecute( HWND hwnd, //窗口句柄 LPCTSTR lpOperation, //操作类型 LPCTSTR lpFile, //文件指针 LPCTSTR lpParameters, //文件可带的参数 LPCTSTR lpDirectory, //缺省目录 INT nShowCmd //显示方式 ); |
ShellExecute()函数用于打开或执行一个文件,在调用此函数时只须指定要打开或执行的文件名,而不必管用什么程序去打开或执行文件,WINDOWS会自动根据要打开或执行的文件去判断该如何执行文件或用什么程序去打开文件。函数中的参数lpOperation说明所要执行的操作,该值可以设置为"Open"、"Print"、"Explore",分别用来进行"打开"、"打印"、"浏览"操作。下面给出了ShellExecute()函数的一些使用方法:
(1)打开一个应用程序:
ShellExecute(this->m_hWnd,"open","calc.exe","","", SW_SHOW ); 或 ShellExecute(this->m_hWnd,"open","notepad.exe", "c:\MyLog.log","",SW_SHOW ); |
(2)打开一个同系统程序相关连的文档
ShellExecute(this->m_hWnd,"open", "c:\abc.txt","","",SW_SHOW ); |
(3)打开一个网页
ShellExecute(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)显示文件或文件夹的属性
天极yesky
Tags:
作者:佚名评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论