Author: Alexander Stoica (Berlin,
Germany)
Creation Date: Aug 2002
This is my first control i have written in C so there might be some errors. Send me a mail to nitex@freenet.de if you find some. For instructions on how to use this control see below.
Special thanks to John Findlay, who helped me a lot with his tips. Visit his site at: www.john.findlay1.btinternet.co.uk
How to use:
You are done, of course you can add more properties. These will be explained next.
The struct members:
UCHAR* ucLink;
Required. This value sets the link including
the protocol. You can use for example http://www.somelink.tld or
mailto:mail@somelink.tld.
UCHAR* ucText;
Optional. This text will be displayed as hyperlink. If not set, the value of ucLink will be used.
UCHAR* ucTooltip;
Optional. If set, a tooltip will be displayed with the given text.
COLORREF fgcNormal;
Optional. This color will be used for the
text in normal state. The default is blue.
COLORREF fgcHover;
Optional. This color will be used for the
text in hoverstate. The default is red.
COLORREF bgcNormal;
Optional. This color will be used for the
background in normal state. The default is transparent.
COLORREF bgcHover;
Optional. This color will be used for the background in hover state. The default is transparent.
ULSTYLE ulStyle;
Optional. If set to ulHover, the text will be underlined when the mouse moves over the link. If set to ulAlways the text will always be underlined. If set to ulNone no text will be underlined. Default is ulAlways.
UINT dtStyle;
Optional. Sets the text drawing flags. These are the same as DrawText() uses. Default is DT_LEFT | DT_TOP. This is what the PSDK says:
Value |
Description |
---|---|
DT_BOTTOM |
Justifies the text to the bottom of the rectangle. This value is used only with the DT_SINGLELINE value. |
DT_CALCRECT |
Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the lpRect parameter and extends the base of the rectangle to bound the last line of text. If the largest word is wider than the rectangle, the width is expanded. If the text is less than the width of the rectangle, the width is reduced. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text. |
DT_CENTER |
Centers text horizontally in the rectangle. |
DT_EDITCONTROL |
Duplicates the text-displaying characteristics of a multiline edit control. Specifically, the average character width is calculated in the same manner as for an edit control, and the function does not display a partially visible last line. |
DT_END_ELLIPSIS |
For displayed text, if the end of a string does not fit in the rectangle, it is truncated and ellipses are added. If a word that is not at the end of the string goes beyond the limits of the rectangle, it is truncated without ellipses. The string is not modified unless the DT_MODIFYSTRING flag is specified. Compare with DT_PATH_ELLIPSIS and DT_WORD_ELLIPSIS. |
DT_EXPANDTABS |
Expands tab characters. The default number of characters per tab is eight. The DT_WORD_ELLIPSIS, DT_PATH_ELLIPSIS, and DT_END_ELLIPSIS values cannot be used with the DT_EXPANDTABS value. |
DT_EXTERNALLEADING |
Includes the font external leading in line height. Normally, external leading is not included in the height of a line of text. |
DT_HIDEPREFIX |
Windows 2000/XP: Ignores the ampersand (&) prefix character in the text. The letter that follows will not be underlined, but other mnemonic-prefix characters are still processed. For example: input string: "A&bc&&d" normal: "Abc&d" DT_HIDEPREFIX: "Abc&d" Compare with DT_NOPREFIX and DT_PREFIXONLY. |
DT_INTERNAL |
Uses the system font to calculate text metrics. |
DT_LEFT |
Aligns text to the left. |
DT_MODIFYSTRING |
Modifies the specified string to match the displayed text. This value has no effect unless DT_END_ELLIPSIS or DT_PATH_ELLIPSIS is specified. |
DT_NOCLIP |
Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used. |
DT_NOFULLWIDTHCHARBREAK |
Windows 98/Me, Windows 2000/XP: Prevents a line break at a DBCS (double-wide character string), so that the line breaking rule is equivalent to SBCS strings. For example, this can be used in Korean windows, for more readability of icon labels. This value has no effect unless DT_WORDBREAK is specified. |
DT_NOPREFIX |
Turns off processing of prefix characters. Normally, DrawText interprets the mnemonic-prefix character & as a directive to underscore the character that follows, and the mnemonic-prefix characters && as a directive to print a single &. By specifying DT_NOPREFIX, this processing is turned off. For example, input string: "A&bc&&d" normal: "Abc&d" DT_NOPREFIX: "A&bc&&d" Compare with DT_HIDEPREFIX and DT_PREFIXONLY. |
DT_PATH_ELLIPSIS |
For displayed text, replaces characters in the middle of the string with ellipses so that the result fits in the specified rectangle. If the string contains backslash (\) characters, DT_PATH_ELLIPSIS preserves as much as possible of the text after the last backslash. The string is not modified unless the DT_MODIFYSTRING flag is specified. Compare with DT_END_ELLIPSIS and DT_WORD_ELLIPSIS. |
DT_PREFIXONLY |
Windows 2000/XP: Draws only an underline at the position of the character following the ampersand (&) prefix character. Does not draw any other characters in the string. For example, input string: "A&bc&&d" normal: "Abc&d" DT_PREFIXONLY: " _ " Compare with DT_HIDEPREFIX and DT_NOPREFIX. |
DT_RIGHT |
Aligns text to the right. |
DT_RTLREADING |
Layout in right-to-left reading order for bi-directional text when the font selected into the hdc is a Hebrew or Arabic font. The default reading order for all text is left-to-right. |
DT_SINGLELINE |
Displays text on a single line only. Carriage returns and line feeds do not break the line. |
DT_TABSTOP |
Sets tab stops. Bits 15–8 (high-order byte of the low-order word) of the uFormat parameter specify the number of characters for each tab. The default number of characters per tab is eight. The DT_CALCRECT, DT_EXTERNALLEADING, DT_INTERNAL, DT_NOCLIP, and DT_NOPREFIX values cannot be used with the DT_TABSTOP value. |
DT_TOP |
Justifies the text to the top of the rectangle. |
DT_VCENTER |
Centers text vertically. This value is used only with the DT_SINGLELINE value. |
DT_WORDBREAK |
Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the lpRect parameter. A carriage return-line feed sequence also breaks the line. If this is not specified, output is on one line. |
DT_WORD_ELLIPSIS |
Truncates any word that does not fit in the rectangle and adds ellipses. Compare with DT_END_ELLIPSIS and DT_PATH_ELLIPSIS. |
BOOL bAutoSize;
Optional. If set to TRUE the window will adjust it's size to fit the text. If set to FALSE the size given in CreateHypCtrl() will be used. Default is TRUE.
BOOL bPlayClick;
Optional. If set to TRUE a click sound will be played when clicking on the link. If set to FALSE no sound will be played. Default is TRUE.
Remarks:
You can call InitHypCtrl() with a valid cursor handle or NULL. If you call the function with NULL, it will try to load a hand cursor from winhlp32.exe, if this fails it will use the default arrow. All hyperlink controls will use this cursor.
You can use the same variable of type HYPCTRL to create multiple controls but you have to call InitHypCtrlStruct() for each control. For an example have a look in test.c.
You only need to change the struct members you need. The only required member is ucLink.
I have included in the "\bin" directory "click.wav" and "hand.cur" if you want to include them in your resource section. These are NOT needed until you change the code for the hyperlink.
If you have an old version of LCC-Win32 (earlier as June 28th 2002) you'll have to manually link with "winmm.lib", "shell32.lib", "shlwapi.lib" and "comctl32.lib".
Have fun and send me some comments... Alex