C ++ win32 add hyperlink to dialog

I would like to add the About dialog to my Win32 application (developed using C ++). How to add a hyperlink to the dialog? I am loading a dialog from a resource file (.rc). Is it possible to determine this functionality from a .rc file?

My .rc file now looks like this:

IDD_ABOUTBOX DIALOGEX 0, 0, 218, 118 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_CENTER CAPTION "About My App" FONT 8, "MS Shell Dlg" BEGIN ICON IDI_APP_ICON,IDC_STATIC,13,88,15,15 LTEXT "MY url http://www.myurl.com",IDC_STATIC,15,6,194,24,SS_NOPREFIX DEFPUSHBUTTON "OK",IDOK,95,98,50,14,WS_GROUP END 
+7
source share
2 answers

You can use SysLink Control in Windows XP or later.

You can define it from a .rc file as follows:

In resource.rc:

  CONTROL "<a>Link</a>",IDC_SYSLINK1,"SysLink",WS_TABSTOP,7,7,53,12 

In resource.h:

 #define IDC_SYSLINK1 1001 
+10
source

The best way to make a selection without any external libraries, still looks the same as any control will do it, even makes the mouse cursor point to a finger.

 /* Start of HyperLink URL */ #define PROP_ORIGINAL_FONT TEXT("_Hyperlink_Original_Font_") #define PROP_ORIGINAL_PROC TEXT("_Hyperlink_Original_Proc_") #define PROP_STATIC_HYPERLINK TEXT("_Hyperlink_From_Static_") #define PROP_UNDERLINE_FONT TEXT("_Hyperlink_Underline_Font_") LRESULT CALLBACK _HyperlinkParentProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK _HyperlinkProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); static void CreateHyperLink(HWND hwndControl); /* End of HyperLink URL */ static void CreateHyperLink(HWND hwndControl) { // Subclass the parent so we can color the controls as we desire. HWND hwndParent = GetParent(hwndControl); if (NULL != hwndParent) { WNDPROC pfnOrigProc = (WNDPROC)GetWindowLong(hwndParent, GWL_WNDPROC); if (pfnOrigProc != _HyperlinkParentProc) { SetProp(hwndParent, PROP_ORIGINAL_PROC, (HANDLE)pfnOrigProc); SetWindowLong(hwndParent, GWL_WNDPROC, (LONG)(WNDPROC)_HyperlinkParentProc); } } // Make sure the control will send notifications. DWORD dwStyle = GetWindowLong(hwndControl, GWL_STYLE); SetWindowLong(hwndControl, GWL_STYLE, dwStyle | SS_NOTIFY); // Subclass the existing control. WNDPROC pfnOrigProc = (WNDPROC)GetWindowLong(hwndControl, GWL_WNDPROC); SetProp(hwndControl, PROP_ORIGINAL_PROC, (HANDLE)pfnOrigProc); SetWindowLong(hwndControl, GWL_WNDPROC, (LONG)(WNDPROC)_HyperlinkProc); // Create an updated font by adding an underline. HFONT hOrigFont = (HFONT)SendMessage(hwndControl, WM_GETFONT, 0, 0); SetProp(hwndControl, PROP_ORIGINAL_FONT, (HANDLE)hOrigFont); LOGFONT lf; GetObject(hOrigFont, sizeof(lf), &lf); lf.lfUnderline = TRUE; HFONT hFont = CreateFontIndirect(&lf); SetProp(hwndControl, PROP_UNDERLINE_FONT, (HANDLE)hFont); // Set a flag on the control so we know what color it should be. SetProp(hwndControl, PROP_STATIC_HYPERLINK, (HANDLE)1); } LRESULT CALLBACK _HyperlinkParentProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { WNDPROC pfnOrigProc = (WNDPROC)GetProp(hwnd, PROP_ORIGINAL_PROC); switch (message) { case WM_CTLCOLORSTATIC: { HDC hdc = (HDC)wParam; HWND hwndCtl = (HWND)lParam; BOOL fHyperlink = (NULL != GetProp(hwndCtl, PROP_STATIC_HYPERLINK)); if (fHyperlink) { LRESULT lr = CallWindowProc(pfnOrigProc, hwnd, message, wParam, lParam); SetTextColor(hdc, RGB(0, 0, 192)); return lr; } break; } case WM_DESTROY: { SetWindowLong(hwnd, GWL_WNDPROC, (LONG)pfnOrigProc); RemoveProp(hwnd, PROP_ORIGINAL_PROC); break; } } return CallWindowProc(pfnOrigProc, hwnd, message, wParam, lParam); } LRESULT CALLBACK _HyperlinkProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { WNDPROC pfnOrigProc = (WNDPROC)GetProp(hwnd, PROP_ORIGINAL_PROC); switch (message) { case WM_DESTROY: { SetWindowLong(hwnd, GWL_WNDPROC, (LONG)pfnOrigProc); RemoveProp(hwnd, PROP_ORIGINAL_PROC); HFONT hOrigFont = (HFONT)GetProp(hwnd, PROP_ORIGINAL_FONT); SendMessage(hwnd, WM_SETFONT, (WPARAM)hOrigFont, 0); RemoveProp(hwnd, PROP_ORIGINAL_FONT); HFONT hFont = (HFONT)GetProp(hwnd, PROP_UNDERLINE_FONT); DeleteObject(hFont); RemoveProp(hwnd, PROP_UNDERLINE_FONT); RemoveProp(hwnd, PROP_STATIC_HYPERLINK); break; } case WM_MOUSEMOVE: { if (GetCapture() != hwnd) { HFONT hFont = (HFONT)GetProp(hwnd, PROP_UNDERLINE_FONT); SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont, FALSE); InvalidateRect(hwnd, NULL, FALSE); SetCapture(hwnd); } else { RECT rect; GetWindowRect(hwnd, &rect); POINT pt = { LOWORD(lParam), HIWORD(lParam) }; ClientToScreen(hwnd, &pt); if (!PtInRect(&rect, pt)) { HFONT hFont = (HFONT)GetProp(hwnd, PROP_ORIGINAL_FONT); SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont, FALSE); InvalidateRect(hwnd, NULL, FALSE); ReleaseCapture(); } } break; } case WM_SETCURSOR: { // Since IDC_HAND is not available on all operating systems, // we will load the arrow cursor if IDC_HAND is not present. HCURSOR hCursor = LoadCursor(NULL, IDC_HAND); if (NULL == hCursor) hCursor = LoadCursor(NULL, IDC_ARROW); SetCursor(hCursor); return TRUE; } } return CallWindowProc(pfnOrigProc, hwnd, message, wParam, lParam); } 

Here's how to use it:

 CreateHyperLink(GetDlgItem(Dialog_HWND_GOES_HERE, STATIC_TEXT_IDENIFIER_GOES_HERE)); 

If the static shortcut can be clicked in the main dialog subclass, do something like this.

  if (HIWORD(wParam) == BN_CLICKED) { //Buttons, checkboxs, labels, static labels clicked switch (LOWORD(wParam)) { case STATIC_TEXT_IDENIFIER_GOES_HERE: ShellExecute(NULL, "open", "http://www.google.com", NULL, NULL, SW_SHOWNORMAL); break; } } 
+2
source

All Articles