2 questions.

1. When programming for windows, is there a way to insert a link into something.
Say you print out the text to a window "Test" is there a way to turn that into a link that triggers their browser, or have a link beside it like "Test - Details" with details being clickable.

2. Is there a way to allow them to select, copy, cut the text as well?
On the simple textout call it's not allowing the person who runs the application to highlight the text and/or copy and cut.

Thanks.
It seems to me that you need to read about Windows programming. All your questions will be answered. Read Petzold.

The short answers:

1. MS Windows already provides a hyperlink control, but even if it didn't, you could create your own, again by means of what you learn from a book like Petzold's. See http://msdn.microsoft.com/en-us/library/bb773173(VS.85).aspx .

2. Yes. Again, Petzold's.
You'll need help from MSDN, too. Petzold just covers all the basics.

The answer to both your questions is yes!

Andy

P.S. Question 2 suggests you should be using an Edit control for your text, rather than drawing it yourself. Edit controls know how to cut, paste, etc.

See Petzold/MSDN for how to use it (it's described on page 247 of my copy of Petzold.) If you don't own a copy of Petzold already, you should really get one if you want to learn to program GUI apps which use the WIN32 API directly.

For Question 1, as webJose said, the Microsoft common control library provides a Hyperlink control (see MSDN). This allows you create a control for a single hyperlink. Note that it is only supported in Windows XP SP2, Windows Vista SP1, and later.

If you want to include hyperlinks in your text block, things get more complicated. The Edit control does not support them!

Someone has written an MFC edit control that supports hyperlinks, which might provide the required "inspiration" (i.e. nickable code).
Multiline Hyper Edit Control
http://www.codeproject.com/KB/edit/multi_hyperedit.aspx

(codeproject.com, codeguru.com, ... are useful places to go for example code. As people are "self reviewed", the quality is somewhat variable...)
Last edited on
PS The Rich Edit Control (also part of the Microsoft common control library) does support hyperlinks (the help refers to URLs). See MSDN for further info.

Note that the Rich Text Control is more powerful than the Edit control in that it can format the text (font, color, etc). But it is a bit harder to use, and people get caught out by (a) the need to dynamically load the required dll (there are more than one version of the Rich Edit control about), and (b) the need to enable some of its functionality using the EM_SETEVENTMASK message.

If you do plan to use the Rich Edit control, you'll need to read the MSDN entry well beforehand. And it would prob. be worthwhile having a look at some Rich Edit example code.

Andy

P.S. Notepad uses an Edit Control whereas WordPad uses a Rich Edit control.
Last edited on
OK thanks for the answers. I will pick up that book sometime over the weekend and give it a read.

Thanks again for the feedback, I appreciate that.
What is the exact name of the book your recommending?
Programming Windows, 5th edition by Charles Petzold.
Topic archived. No new replies allowed.