Saturday, March 10, 2012

Adding a HTML link in your Windows application

Desperately seeking for an audience, I wanted to do include a link to this site in the "about" box of a Windows application developed with Rad Studio Builder :


I did use in the past Windows API function "ShellExecute", passing to it the application to launch (ex. firefox.exe) and the given parameters, (ex: http://mysite.com). but my problem was to find the user's default browser to launch it. Remembering how difficult it was to find out the local IP address, I said to myself "Guyt, your in for a treat".

Well, actually reading more carefully Microsoft's documentation on "ShellExecute" taught me that I didn't need to know the defaut browser!

http://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx

The trick is simply to specify the "open" operation on given link and it's done.

Here's the code that handles my "OnClick" event on the label that contains the link in its "Caption":
void __fastcall TfrmAbout::lbLinkClick(TObject *Sender)
{
ShellExecute(NULL, L"open",lbLink->Caption.c_str(),NULL, NULL, SW_SHOWNORMAL);
}
Don't we love it when it's that easy?

No comments:

Post a Comment