Click here to Skip to main content
15,867,686 members
Articles / Desktop Programming / WTL
Article

WTL CBitmapHyperLink class

Rate me:
Please Sign up or sign in to vote.
4.95/5 (10 votes)
18 Jan 2005CPOL1 min read 54.3K   754   21   9
CHyperLink derived class that displays a bitmap next to the link and allows a different color when hover.

Image

Introduction

WTL has a CHyperLink class that is used to create hyperlinks. Main features of this control are:

  1. Hyperlink looks like the one in IE.
  2. While moving over the link, cursor becomes a hand.
  3. If cursor is kept over the link for a little while, a tooltip will appear.
  4. Class CHyperLink supports a keyboard interface as well.

But it does not allow to do two things that I was looking for - displaying a bitmap next to the link and changing link color when hover. So I've come up with the class CBitmapHyperLink that derives from CHyperLink and lets you do just this.

Using the code

To integrate CBitmapHyperLink into your app, you first need to add the following file to your project, like so:

#include "BitmapHyperLink.h"

Then use the resource editor to add a static control to your dialog and define a variable in your dialog class:

CBitmapHyperLink m_Link;

Add the following lines in the OnInitDialog() function:

LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, 
                       LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
    ...

    m_Link.SetHyperLink(_T("http://www.google.com"));
    m_Link.SetLabel(_T("Looking for something?"));
    m_Link.SubclassWindow(GetDlgItem(IDC_STATIC_URL));
    m_Link.SetExtendedStyle(HLINK_LEFTIMAGE | 
                   HLINK_UNDERLINEHOVER | HLINK_NOTOOLTIP);
    m_Link.SetLinkColor(RGB(0, 0, 0));
    m_Link.SetVisitedColor(RGB(0, 0, 0));
    m_Link.SetHoverColor(RGB(0, 0, 255));
    HBITMAP hBmp = m_Link.AddBitmap(IDB_BITMAP);
    ATLASSERT(hBmp);

    ...

    return TRUE;
}

History

  • 01/18/2005 - Initial release.

Disclaimer

THIS SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO RESPONSIBILITIES FOR POSSIBLE DAMAGES CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE RISK OF USING THIS SOFTWARE.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionBitmap HyperLink Compiling Problem Pin
JohnFike31-Oct-07 0:22
JohnFike31-Oct-07 0:22 
AnswerRe: Bitmap HyperLink Compiling Problem Pin
Igor Vigdorchik31-Oct-07 13:04
Igor Vigdorchik31-Oct-07 13:04 
GeneralResizing Pin
iceman5030-Dec-05 9:28
iceman5030-Dec-05 9:28 
GeneralRe: Resizing Pin
Igor Vigdorchik30-Dec-05 9:53
Igor Vigdorchik30-Dec-05 9:53 
Generalmacro not found Pin
Anthony_Yio18-Aug-05 1:42
Anthony_Yio18-Aug-05 1:42 
GeneralRe: macro not found Pin
Igor Vigdorchik18-Aug-05 4:59
Igor Vigdorchik18-Aug-05 4:59 
GeneralRe: macro not found Pin
Anthony_Yio18-Aug-05 16:05
Anthony_Yio18-Aug-05 16:05 
GeneralJust what I needed Pin
JasonLP12-Apr-05 6:36
JasonLP12-Apr-05 6:36 
GeneralRe: Just what I needed Pin
Igor Vigdorchik12-Apr-05 16:47
Igor Vigdorchik12-Apr-05 16:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.