Print this
window
Installation instructions for:
TWShellLabel.cpp
Purpose:
The TWShellLabel component was created because I got tired of keying in the
same code time and time again when I wanted the user to go to my web site or
e-mail me through Outlook. It took me two programs to figure out that I needed
to do something else, thank goodness for object oriented programming and code reuse. This
component will open a web browser, Outlook, notepad, any other executable, or any
other program as long as the extension is defined in the registry. If
the program cannot be run then a warning message will be displayed to the user
stating that they do not have the proper software to run the program. This component
will have the same attributes as the regular component, plus a few others that I thought
where needed:
1. ColorOn - The color of the label when the mouse pointer is over it.
2. ColorOff - The color of the label when the mouse pointer is taken off of it.
3. CursorOff cursor - The type of cursor when the cursor is taken off of the label.
4. CursorOn cursor - The type of cursor when the cursor is placed over it.
5. ShowCommand - How will the new program will be shown. The directions for this is in the header file, TWShellLabel.h.
6. openProgram method - Will open the specified program
The zip file includes the .cpp, .h, .res, and readme file. The .res file is the resource file that
will give the component its own image on the Palette page.
To install TWShellLabel component:
There are two ways of installing the component: as is or by copying and pasting into your
own named component.
NOTE: Before installing the component please test it to make sure that it does what you
want it to do. I have found that it is a bit of a pain to get rid of one once you have
installed.
As Is:
Open the zip file into CBuilder5\Lib directory. All of the files must go into this directory.
Supposedly you do not have to place them in this location, but I have not had much luck with
placing them anywhere else.
Copying and pasting:
Open Builder 5, choose Component > New Component. Find the correct Ancestor type from the
drop down box, type in a Class name for the component. Please think up a good name for the
component. Select a Palette page or type one in and it will be created for you. You can then
either click on OK or install. If you are sure that this component is the one that you want
then click on install, else click OK. Now start copying and pasting from the downloaded file
to the new component.
To test the component:
Create a new project in the same directory that you placed the new component in and add the
component to the project by: Project > Add to Project and selecting the .cpp file.
Add these two lines to .h of your project:
#include "WShellLabel.h"
and
TWShellLabel *openLabel; // Should be placed in the private or public section of the header
Go to the constructor, FormCreate, or other method of your choosing and add this code. I have
done it in the constructor.
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
openLabel = new TWShellLabel(this);
openLabel->Parent = this;
openLabel->Left = 300;
openLabel->Top = 100;
openLabel->Caption = "Here I am";
openLabel->ColorOff = clBlue;
openLabel->ColorOn = clRed;
openLabel->CursorOff = crDefault;
openLabel->CursorOn = crHandPoint;
openLabel->OnClick = Label1Click;
}
Add a regular label to the form and create an OnClick event for it. Inside of the OnClick
event add this code:
openLabel->openProgam(openLabel->Caption);
The finished method should look similar to below:
void __fastcall TForm1::Label1Click(TObject *Sender)
{
openLabel->openProgram(openLabel->Caption);
}
Run the program and move your mouse over the 'Here I am' label. It should have turned red when
your mouse pointer was over the label and when you removed the pointer it should turn blue.
Click on the 'Here I am' label and a message box should appear stating you do not have the
proper software to run this program. Stop the program and change the openLabel->Caption line
so that it looks like:
openLabel->Caption = "notepad.exe";
Run the program and click on the notepad.exe label. As long as you have notepad loaded on
your system, notepad should come up and run. You can also try placing a file name in the
caption as well or a web address and both of them should come up and run.
To install the component:
Go to Components > Install Component
To place it into an existing package type in the path name to the component or click on
browse and locate the file. Click on OK. On the package form that comes up click on Compile
and then follow the instructions on the screen.
Take a look on the Palatte page and the new component should be located on the page that you
placed it on with the resource file that it is associated with.
If you have any problems with the component please contact me so I can straighten them out.
If you make any enhancements to the component please let me know so that I can share them
with everyone.
Thank you for choosing Widget Technologies.