|
INPRISE Online And ZD Journals Present:
By Kent Reisdorph
A Web site is a great way to promote your company. If you have a Web site, you want your users to be able to get to it with the minimum amount of effort. A URL label in your application's About dialog box allows your users to quickly and easily connect to your Web site from your application. In this article, we'll show you how you can create a URL label.
What's a URL label?
For example, Figure A shows the URL label in our sample application's About dialog box.
Figure A: Users can click on a URL label to quickly go to a Web site. Most of the steps required to fulfill this feature list are easy to perform--you certainly don't need any help to drop a label on a form, change the Caption property, and change the font's color. The rest, though, requires some explanation.
Creating and implementing the cursor Using Image Editor, create a resource file (RES) and then create a cursor resource within that resource file. Name the cursor resource something appropriate (WEBPOINTER would be a good name). Save the resource file and close Image Editor. Now, choose C++Builder's Project | Add To Project menu item and add the resource file to your project. Next, you need to load the cursor resource so that it's available to the URL label. Put this code in your main form's OnCreate event handler:
The cursor will be loaded when the application starts and will be ready for you to use. Notice that the code loads the cursor into array index 1 of the Cursors array. To assign the new cursor to the URL label, simply change the label's Cursor property to 1. You can do this either at design time or at runtime.
Starting the Web browser
ShellExecute will open a document based on the document's extension. In order for this function to work, the filename extension must be registered with Windows. A browser document is a special case: Windows recognizes the document name as a URL, automatically executes the default Web browser, and loads the document. If ShellExecute fails, it returns a value of 32 or fewer. You should write your code to account for an error. For example:
All you have to do now is add this code to the OnClick event handler for the URL label. Double-click on the label, and C++Builder will create an event handler for the OnClick event. Enter code similar to the above code snippet, and you're all set.
But wait, there's more!
Not only can you start a Web browser with ShellExecute, you can also use it to let your users send you E-mail. It's just a matter of changing things a little:
Notice that the document string in this example includes mailto: rather than a URL. When this code executes, Windows will start the mail client registered on the user's system and fill in the To field with the E-mail address passed in ShellExecute.
Conclusion |