?? index.htm
字號:
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Download demo project</title>
<link rel="stylesheet" type=text/css href="global.css">
</head>
<body>
<ul class="download">
<li>
<a href="http://www.codeproject.com/buttonctrl/NdtURLLinkButton/URLLinkButton_DemoProject.zip">
Download demo project - 17 Kb </a></li>
<li>
<a href="http://www.codeproject.com/buttonctrl/NdtURLLinkButton/URLLinkButton_Source.zip">
Download source - 5 Kb</a> </li>
<li>
<a href="http://www.codeproject.com/buttonctrl/NdtURLLinkButton/URLLinkButton_Demo.zip">
Download demo - 104 Kb</a> </li>
</ul>
<p>
<img src="URLLinkButton.GIF" border="0" width="498" height="282"></p>
<h2>Introduction</h2>
<p>The <code>CURLLinkButton </code>class extends the functionality of <code>
CButton</code> by providing support for URL links. It displays the URL link and
invokes the shell when clicked. It can be used in your project to link to any
URL such as your website, an application, a folder or your email. You also can
use it like other buttons to show a messagebox, dialogbox or anything you like.</p>
<p>This is a hyperlink control which really act like the ones used in Internet
Explorer<sup>® </sup>with following features:</p>
<ol type="1">
<li>Can be plugged into any dialog, form or view </li>
<li>Link to the any URL and email </li>
<li>Contains a built-in ToolTip </li>
<li>Customize the displayed text, URL-Prefix, URL, Tooltip text. </li>
<li>Customize the colors of Hyperlink (regular, hover, visited) and Tooltip
(text color, background color) </li>
<li>Use a custom cursor or use the standard Hand cursor </li>
<li>Resize a URL link button to the size of the button's caption </li>
<li>Can be focused, navigated and activated using the keyboard </li>
<li>Send a message to parent when clicked </li>
<li>Easy to understand, easy to use </li>
</ol>
<p>Thanks to Niek Albers for <code>_TrackMouseEvent()</code>. Thanks to Paul
DiLascia for default hand cursor from WinHlp32.</p>
<h2>Using the code</h2>
<p>The code is quite short, reuseable and easy to understand. For using this
control in your project, you need to do :</p>
<ol type="1">
<li>Add <b><i>URLLinkButton.h</i></b><i> </i>and <b><i>URLLinkButton.cpp</i></b><i>
</i>to your project. </li>
<li>Include <b><i>URLLinkButton.h</i></b><i> </i>in the header file where the
controls are defined </li>
<li>Add some buttons to the dialog or form. Add a member variable for each
button you want to customize as a hyperlink control. Replace the type of those
variables from <code>CButton</code> to <code>CURLLinkButton</code>. Open “Push
Button Properties” dialog, select “Styles” page and check the option “Owner
draw”. </li>
<li>Use following operators to customize the control: </li>
</ol>
<pre><span class="cpp-comment">//Resize a URL link button to the size of the button's caption</span>
<span class="cpp-keyword">void</span> SizeToContent();
<span class="cpp-comment">//Customize the colors of Hyperlink </span>
<span class="cpp-keyword">void</span> SetLinkColor(COLORREF clrRegular, COLORREF clrHover, COLORREF clrVisited);
<span class="cpp-comment">//Customize the colors of the Tooltip</span>
<span class="cpp-keyword">void</span> SetToolTipColor(COLORREF clrTextColor, COLORREF clrBkColor);
<span class="cpp-comment">//Customize the tooltip text. Use default tooltip if sTip is empty</span>
<span class="cpp-keyword">void</span> SetToolTipText(CString sTip=_T(<span class="cpp-string">""</span>));
<span class="cpp-comment">// Set URL. By default, window text will be used</span>
<span class="cpp-keyword">void</span> SetURL (LPCTSTR lpszURL);
<span class="cpp-comment">//Set URL prefix. For example "mailto:"</span>
<span class="cpp-keyword">void</span> SetURLPrefix (LPCTSTR lpszPrefix); </pre>
<p>If you have a cursor resource in you project, you can customize the cursor or
you can use default hand cursor</p>
<pre><span class="cpp-preprocessor">#if(WINVER >= 0x0500)</span>
<span class="cpp-comment">//Load system hand cursor</span>
m_hCursorHand = AfxGetApp()->LoadCursor (IDC_HAND);
<span class="cpp-preprocessor">#else</span>
<span class="cpp-comment">// Use a custom Hand cursor</span>
<span class="cpp-comment">// Must add a cursor resourse in the project with ID: IDC_CURSOR_HAND</span>
<span class="cpp-comment">//m_hCursorHand = AfxGetApp()->LoadCursor (IDC_CURSOR_HAND);</span>
<span class="cpp-comment">// If you haven't the cursor resourse in your project</span>
<span class="cpp-comment">// load default hand cursor from WinHlp32 module with ID=106</span>
TCHAR szWindowsDir[MAX_PATH];
GetWindowsDirectory(szWindowsDir ,MAX_PATH);
strcat(szWindowsDir,<span class="cpp-string">"\\Winhlp32.exe"</span>);
HMODULE hModule = LoadLibrary(szWindowsDir);
<span class="cpp-keyword">if</span> (hModule)
m_hCursorHand = ::LoadCursor(hModule, MAKEINTRESOURCE(<span class="cpp-literal">106</span>));
<span class="cpp-preprocessor">#endif </span></pre>
<p>When the link button is clicked, <code>ShellExecute </code>is called to open
the URL. If this fails, it sends a registered message to the parent window. </p>
<pre><span class="cpp-keyword">const</span> UINT WM_LINK_CLICKED = ::RegisterWindowMessage (_T (<span class="cpp-string">"WM_LINK_CLICKED"</span>));</pre>
<p>You can create a message handler of the parent window to do anything you want
when the hyperlink is clicked. For example:</p>
<pre>afx_msg LRESULT OnLinkCliked(WPARAM wParam, LPARAM lParam);
ON_REGISTERED_MESSAGE(WM_LINK_CLICKED, OnLinkCliked)
LRESULT CURLLinkDlg::OnLinkCliked(WPARAM wParam, LPARAM lParam)
{
UINT nLinkID = (UINT)wParam;
<span class="cpp-keyword">switch</span>(nLinkID)
{
<span class="cpp-keyword">case</span> IDOK:
OnOK();
<span class="cpp-keyword">break</span>;
<span class="cpp-keyword">case</span> IDC_SHOW_MESSAGE:
MessageBox(_T(<span class="cpp-string">"Hope you find this code useful!"</span>));
<span class="cpp-keyword">break</span>;
}
<span class="cpp-keyword">return</span> <span class="cpp-literal">0</span>;
}</pre>
<h2>History</h2>
<ul>
<li>July 18, 2004: Initial public release to The Code Project.<br>
</li>
</ul>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -