• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

Hyperlink launching

Hi all!
How can I launch a browser to a URL address stored in a string?
I mean I've got a static text contol contining a string representing an URL address and I want to go to that address when I click the control...
Thanx a lot!
0
atti75
Asked:
atti75
1 Solution
 
naveenkohliCommented:
Derive a class from Cstatic for you static control. And then handle STN_CLICKED message which is like button click message.

Here is some part of the clss you can derive .....


class CHyperLink : public CStatic {
public:
      CHyperLinkExt();
afx_msg void OnClicked ();
};

BEGIN_MESSAGE_MAP(CHyperLink, CStatic)
      //{{AFX_MSG_MAP(CHyperLink)
      ON_CONTROL_REFLECT(STN_CLICKED, OnClicked)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CHyperLink::OnClicked()
{
// First try to execute the URL from shell.

      HINSTANCE hResult = ShellExecute (NULL, _T("Open"), urlStr, NULL,
            NULL, show);

      // If it fails then get the htm registry key.
      if ((UINT)hResult <= HINSTANCE_ERROR) {
            if (GetRegKey (HKEY_CLASSES_ROOT, _T("urlStr"), key) == ERROR_SUCCESS) {
                  lstrcat (key, _T("\\shell\\open\\command"));
                  if (GetRegKey (HKEY_CLASSES_ROOT, key, key) == ERROR_SUCCESS) {
                        TCHAR *pos;
                        pos = _tcsstr (key, _T("\"%1\""));
                        if (pos == NULL) {            // No quotes found.
                              pos = _tcsstr (key, _T("%1"));      // Check without quotes
                              if (pos == NULL) {
                                    pos = key + strlen(key) - 1;
                              }
                              else {
                                    pos = '\0';
                              }
                        }
                        else {
                              pos = '\0';
                        }

                        lstrcat (pos, _T(" "));
                        lstrcat (pos, urlStr);

                        hResult = (HINSTANCE) WinExec (pos, show);
                  }
            }
      }
}
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now