⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 0503001.htm

📁 VC知识库5_chm_decompile_20040520_210715
💻 HTM
字号:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
<link rel="stylesheet" type="text/css" href="../../vckbase.css">
</head>

<body>

<div align="justify">
  <table border="0" width="100%" class="font" height="57">
    <tr>
      <td width="27%" height="6" class="bigfont" bgcolor="#B8CFE7" align="center" bordercolor="#800080">
      <font color="#800080">VC知识库(五)</font>
      </td>
      <td width="73%" height="6" class="bigfont" bgcolor="#B8CFE7" align="center" bordercolor="#800080">
      <font color="#800080">vckbase</font>
      </td>
    </tr>
    <tr>
      <td width="100%" height="4" class="header" valign="top" align="center" colspan="2">
      <hr>
      </td>
    </tr>
    <tr>
      <td width="100%" height="17" class="header" valign="top" align="center" colspan="2">
      <FONT color=#0000c0>
      <p>用VC6.0实现超级链接 </p></FONT>
      </td>
    </tr>
    <tr>
      <td width="100%" height="17" class="info" align="center" colspan="2">
      湖北省襄樊市电信局计算机中心 <BR>张洪征
      </td>  
    </tr>  
    <tr> 
      <td width="100%" height="22" class="font" colspan="2">
        <hr>
      </td>  
    </tr> 
    <tr> 
      <td width="100%" height="5" class="font" colspan="2"> 
      <CENTER></CENTER>
      <P><FONT color=#ffffff>----</FONT> 
      很多windows软件的版权对话框中都设有超级链接,这些链接或提供公司网址,或提供电子邮件信箱,使操作者能够非常方便地与公司和作者联系,同时也为公司作了很好的宣传。如果能在自己写的软件中实现这个功能,定会使程序大增光彩。  
 
      <P><FONT color=#ffffff>----</FONT> 实现这个功能要用到一个WINDOWS  
      API函数ShellExecute,其原形为: <XMP>HINSTANCE ShellExecute(     
    HWND hwnd,            //窗口句柄 
    LPCTSTR lpOperation,    //操作类型 
    LPCTSTR lpFile,         //文件指针 
    LPCTSTR lpParameters,   //文件可带的参数 
    LPCTSTR lpDirectory,    //缺省目录 
    INT nShowCmd         //显示方式 
);	 
</XMP><FONT color=#ffffff>----</FONT>  
      ShellExecute函数用于打开或执行一个文件,在调用此函数时只须指定要打开或执行的文件名,而不必管用什么程序去打开或执行文件,WINDOWS会自动根据要打开或执行的文件去判断该如何执行文件或用什么程序去打开文件。以下给出一个完整实例,具体实步骤:  
 
      <OL> 
        <LI>创建一个基于对话框的应用程序,命名为hyperlink; <BR> 
        <LI>打开资源编辑器,在对话框上添加两个static text控件和两个button控件。 </LI></OL><FONT  
      color=#ffffff>----</FONT> Static1和button1并列排放,Static1和button1并列排放。  
      <P><FONT color=#ffffff>----</FONT>  
      将static1的ID设为ID_STATIC1,caption设为:计算机世界日报:,button1的ID设为ID_BUTTON1,caption设为:http://www.computerworld.com.cn,并选中flat属性。将static2的ID设为:ID_STATIC2,caption设为为:给我写信:,button2的ID设为ID_BUTTON2,caption设为:  
      west_virginia@netease.com,并选中flat属性。  
      <OL start=3> 
        <LI>创建一个新光标,将其图标编辑成一个手的图像,其ID命名为ID_CURSOR1; <BR> 
        <LI>给ChyperlinkDlg类增加一个WM_SETCURSOR消息处理函数,其代码如下: </LI></OL><XMP>   BOOL ChyperlinkDlg::OnSetCursor(CWnd* pWnd,  
	UINT nHitTest, UINT message)  
{ 
	CRect rcButton1,rcButton2; 
	CPoint ptCursor; 
	CWnd *pStatic1=GetDlgItem(IDC_BUTTON1); 
	CWnd *pStatic2=GetDlgItem(IDC_BUTTON2); 
	pStatic1->GetWindowRect (rcButton1); 
	pStatic2->GetWindowRect (rcButton2); 
	GetCursorPos(&ptCursor); 
	if (rcButton1.PtInRect (ptCursor)|| 
	rcButton2.PtInRect (ptCursor)) 
	{ 
	CWinApp *pApp=AfxGetApp(); 
	HICON hIconBang=pApp->LoadCursor (IDC_CURSOR1); 
	SetCursor(hIconBang); 
	return TRUE; 
	} 
	else 
 
  return CDialog::OnSetCursor 
  (pWnd, nHitTest, message); 
} 
其作用是当鼠标位于button1和button2控件上时, 
将其形状设为手形。 
 
5、 给IDC_BUTTON1增加BN_CLICKD消息处理函数,代码如下: 
void ChyperlinkDlg::OnButton1()  
{ 
	// TODO: Add your control notification handler 
       code here 
	ShellExecute(m_hWnd,NULL,  
		"http://www.computerworld.com.cn", 
               NULL,NULL,SW_SHOWMAXIMIZED); 
} 
 
6、 给IDC_BUTTON2增加BN_CLICKD消息处理函数,代码如下: 
void ChyperlinkDlg::OnButton2()  
{ 
// TODO: Add your control notification 
    handler code here 
   ShellExecute(m_hWnd,NULL, 
   "mailto:west_virginia@netease.com", 
           NULL,NULL,SW_SHOWMAXIMIZED); 
} 
</XMP><FONT color=#ffffff>----</FONT>  
      运行此程序,在对话框上显示计算机世界日报的首页链接和作者的电子邮件地址,在其上点鼠标左键后将自动进入计算机日报首页或启动邮件收发程序给作者写信,效果很理想。读者可在此基础上进一步完善,使其更专业化,也可将其写成类,用起来更方便。  
 
      <P><FONT color=#ffffff>----</FONT>  
      ShellExecute是一功能很强大的函数,本文只使用了它的一种用法,更详细全面的用法可参考Visual studio 6.0中所带的MSDN  
      library 。 </P>  
      </td>     
    </tr>    
    <tr> 
      <td width="100%" height="12" class="font" colspan="2">  
      </td>     
    </tr> 
    <tr> 
      <td width="100%" height="6" class="font" colspan="2">  
      </td>     
    </tr> 
    <tr> 
      <td width="100%" height="8" class="font" colspan="2">  
      </td>     
    </tr> 
    <tr>    
      <td width="100%" height="17" class="font" colspan="2"></td>     
    </tr>    
  </table>     
</div>     
     
</body>     
     
</html>     

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -