Introduction
The
control
allows the user to edit the text and the
URL
independently of each other, or to set them
as always the same. A dialog is included to
assist the user in editing the URL, similar
to those found in some HTML editors.
The control
can be set such that it is only a link when
it has a URL explicitly set, or if the text
looks like a URL. Alternatively, it can set
to be always, or never, a link.
A context
menu item allows the user to invoke the
dialog for editing the URL. The control also
responds to the Ctrl+K accelerator, which
may be changed, in code, to any key
combination.
To use the
control, just create an edit control, and
attach it to a member variable, of type
CHyperEdit
.
Documentation
The control
is fairly simple, and insight into the
workings can easily be gained by looking at
the source code.
The
public
functions are
listed below:
Functions
-
CHyperEdit();
Standard empty constructor.
-
void SetLinkOption(HE_OPTION_LINK optLink);
Sets
when to display the text as a link. For
details of the options, see the
enumeration
HE_OPTION_LINK
.
-
HE_OPTION_LINK GetLinkOption() const;
Returns
the current link option as set in the
above function.
-
void SetUnderlineOption(HE_OPTION_UNDERLINE optUnderline);
Sets
when to display the text underlined. For
details of the options, see the
enumeration
HE_OPTION_UNDERLINE
.
-
HE_OPTION_UNDERLINE GetUnderlineOption() const;
Returns
the current underline option as set in
the above function.
-
void SetVisited(BOOL bVisited = TRUE);
Sets
whether the link should be displayed as
a visited link.
-
BOOL GetVisited() const;
Returns
whether the link has been visited.
-
void SetLinkCursor(HCURSOR hCursor = NULL);
Sets
the cursor to be displayed when moving
the mouse over a link. Specifying
NULL
will cause the control to display its
default 'hand' cursor.
-
HCURSOR GetLinkCursor() const;
Returns
the current link cursor.
-
void SetColours(COLORREF crLink, COLORREF crVisited, COLORREF crHover = -1);
Sets
the link colours.
crLink
specifies the colour for a link,
crVisited
specifies the colour of a visited link,
and
crHover
specifies the link colour when the users
move their mouse over it. If
-1
is specified for
crHover
then the link does not change colour
when the users move their mouse.
-
void GetColours(COLORREF* pcrLink, COLORREF* pcrVisited = NULL,
COLORREF* pcrHover = NULL) const;
This
retrieves the current link colours. You
may specify
NULL
for any of the parameters if you do not
wish to retrieve its value.
-
void SetIEColours();
Sets
the link colours to the colours chosen
in the user's Internet Explorer. If the
user does not use Internet Explorer, or
the colours have not been set, then they
default to blue for the link, purple for
a visited link, and no change on hover.
Calling
GetColours
after this function will return the
actual values set.
-
void SetDblClkToJump(BOOL bDblClkToJump = TRUE);
Sets
whether to jump to the URL only on
double-clicking the link. If
bDblClkToJump
is
FALSE
then a single-click will jump to the URL
(the default case).
-
BOOL GetDblClkToJump() const;
Returns
whether a double-click is needed to jump
to the URL.
-
void SetCtrlClkToJump(BOOL bCtrlClkToJump = TRUE);
Sets
whether to jump to the URL only on
control-clicking the link. If
bCtrlClkToJump
is
FALSE
then a single-click will jump to the URL
(the default case), unless
SetDblClkToJump
has been
set.
-
BOOL GetCtrlClkToJump() const;
Returns
whether a control-click will jump to the
URL.
-
void SetURL(LPCTSTR lpszURL = NULL);
Sets
the current URL to the string passed in.
If
lpszURL
is
NULL
,
the URL is cleared.
-
CString GetURL() const;
Returns
the currently set URL.
-
void EditURL();
Invokes
a dialog to allow the user to edit the
URL. Help is given with the URLs prefix,
similar to the way in which some HTML
editors work.
-
void SetURLIsText(BOOL bURLIsText = TRUE);
If
bURLIsText
is
TRUE
,
then the URL and the displayed text will
always be the same. Editing the URL will
change the window text, and vice versa.
When first calling this with
bURLIsText
set to
TRUE
,
when the URL and text are different,
they will both be set to whichever next
changes.
-
BOOL GetURLIsText() const;
Returns
whether the URL and the text are always
the same.
-
void SetEditURLAccelerator(BYTE fVirt = 0, WORD key = 0);
Allows
an accelerator to be set for editing the
hyperlink. The default key combination
is Ctrl+K. The
fVirt
and
key
parameters are as in the members of the
ACCEL
structure. If
fVirt
is
0
then no accelerator is set.
-
void GetEditURLAccelerator(BYTE& fVirt, WORD& key);
Returns
the current accelerator used for editing
the hyperlink.
-
virtual BOOL IsTextHyperText();
Determines whether the current edit text
is to be treated as a Hyper-link.
Returns
TRUE
if text is a hyper-link, else
FALSE
.
Only called if the link option is set to
HEOL_AUTO
or
HEOL_HASURL
.
Override this function to use different
rules on what makes a valid URL for your
application.
Enumerations
typedef enum {
HEOL_NEVER,
HEOL_ALWAYS,
HEOL_AUTO,
HEOL_HASURL
} HE_OPTION_LINK;
typedef enum {
HEOU_NEVER,
HEOU_ALWAYS,
HEOU_HOVER
} HE_OPTION_UNDERLINE;