Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mailto: label 1

Status
Not open for further replies.

hennep

Programmer
Dec 10, 2000
429
I want to put a label on a form that looks like a URL,
blue color, underline, hand cursor.
How do I implement the "mailto:email@domain.com" action ?

I've already tried ShellExecute but that does not work.

any ideas

thanks,
Hennep
 
Hi Hennep

Here the code to a simple project, place a Label on the Form and set these properties

Caption = "SomeEmail@net.com"
Cursor = crHandPoint

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include &quot;Unit1.h&quot;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
//OnMouseEnter event of Label1
void __fastcall TForm1::Label1MouseEnter(TObject *Sender)
{
Label1->Font->Color=clBlue;
}
//---------------------------------------------------------------------------
//OnMouseLeave event of Label1
void __fastcall TForm1::Label1MouseLeave(TObject *Sender)
{
Label1->Font->Color=clBlack;
}
//---------------------------------------------------------------------------
//OnClick event of Label1
void __fastcall TForm1::Label1Click(TObject *Sender)
{
//You can also use the Hint property to hold the Email address if you like so you would just change Label1->Caption to Label1->Hint

ShellExecute(Handle,
&quot;open&quot;,
String(&quot;mailto:&quot;+Label1->Caption).c_str(),
NULL,
NULL,
SW_SHOW);
/*
Syntax to also include subject

ShellExecute(Handle,
&quot;open&quot;,
String(&quot;mailto:email@net.com?Subject=Test&quot;).c_str(),
NULL,
NULL,
SW_SHOW);

Include subject and body

ShellExecute(Handle,
&quot;open&quot;,
String(&quot;mailto:email@net.com?Subject=Test&Body=Just testing.&quot;).c_str(),
NULL,
NULL,
SW_SHOW);


*/

}
//---------------------------------------------------------------------------

Another snippet

AnsiString Body,Subject=&quot;Test Subject&quot;,Email=&quot;Test@net.com&quot;,FullStr;

Body = &quot;Test1%0ATest2&quot;; // %0A hexadecimal equivalent of Line feed &quot;\r\n&quot; will not work in this case

FullStr = &quot;mailto:&quot;+Email + &quot;?Subject=&quot;+Subject + &quot;&Body=&quot;+Body;

ShellExecute(Handle, NULL, FullStr.c_str(), NULL, NULL, SW_SHOWDEFAULT);


For more info on the parameters of ShellExecute and Outlook parameters


Since the above link is specifically aimed toward command line execution we don't have to worry about the other

Hexadecimal equivalents such as

Space ( ) %20
Comma (,) %2C
Question mark (?) %3F
Period (.) %2E
Exclamation point (!) %21
Colon :)) %3A
Semicolon (;) %3B
 
Hi BTecho,

Thanks alot.
So it can be done with ShellExecute. I do not have an email client installed on my development computer. When I click on a mailto link in the internet browser it generates an error. (mailto is not a registered protocol) This did not happen in CBuilder.
Do I have to use the return value from ShellExecute to check for errors ?

Hennep
 
Hi hennep

Yes, you can check the return value from ShellExecute to check for errors. I only have Outlook Express installed so I can't say for sure , The return value is over 32 if function has been successful.
 
If you want to do something such as display your company url on an about box or a splash screen you want your efforts to work on various email clients. You should perhaps check the registry for the default email client and if it is compatible with your code too execute. I guess you must search for parameters for other email clients.

Have I just overcomplicated things.
 
I have found a very simple method to handle these &quot;alien&quot; mail clients.

The email addres is displayed in a tooltip :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top