2

I have read this article:

Article

Sample

It clearly shows hyperlinks are supported in the footer. I can’t work out how to do it. I don’t want a literal URL in the text but other text that hyperlinks to a help article in the program.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • 1
    Have you tried just HTML? `SetFooterText(LR"(Footer information for the dialog.)");` – acraig5075 Mar 26 '19 at 14:24
  • @acraig5075 That does indeed create a hyperlink. Thank you. However, I now realise I can't use this approach because it would be linking to a topic in a CHM file. – Andrew Truckle Mar 26 '19 at 14:37
  • 2
    I suspect if you handle the click with [CTaskDialog::OnHyperlinkClick](https://learn.microsoft.com/en-us/cpp/mfc/reference/ctaskdialog-class?view=vs-2017#onhyperlinkclick) then you should be able to call `AfxGetApp()->HtmlHelp(...)` accordingly. – acraig5075 Mar 26 '19 at 14:53
  • @acraig5075 So you are suggesting I inherit my own task dialog class so that I can override this handler. OK ... – Andrew Truckle Mar 26 '19 at 15:00
  • @acraig5075 Please see my answer. – Andrew Truckle Mar 26 '19 at 21:02

1 Answers1

1

This works:

#include "stdafx.h"
#include "CMyTaskDialog.h"

IMPLEMENT_DYNAMIC(CMyTaskDialog, CTaskDialog)


CMyTaskDialog::CMyTaskDialog(_In_ const CString& strContent, 
                             _In_ const CString& strMainInstruction, 
                             _In_ const CString& strTitle,
                             _In_ int nCommonButtons,
                             _In_ int nTaskDialogOptions, _In_ const CString& strFooter)
    : CTaskDialog(strContent, strMainInstruction, strTitle, nCommonButtons, nTaskDialogOptions, strFooter)
{
}


CMyTaskDialog::~CMyTaskDialog()
{
}




HRESULT CMyTaskDialog::OnHyperlinkClick(const CString& strHref)
{
    HWND hwnd =
        HtmlHelp(
            GetDesktopWindow(),
            _T("d:\\MeetSchedAssist.chm::/") + strHref,
            HH_DISPLAY_TOPIC,
            NULL);

    return S_OK;
}

However, there are two issues still:

  1. CTaskDialog does not have a GetSafeHWnd API call so I don't know how to set it as the parent.

  2. The OnHyperlinkClick is generic so if you have multiple links on the task dialog you might have to test the phrase to decide how you want to handle it.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • 2
    No `GetSafeHwnd` - that's just a limitation of the MFC interface. Underlying callback interface passes the `HWND`. Try to override [CTaskDialog::TaskDialogCallback](https://learn.microsoft.com/en-us/cpp/mfc/reference/ctaskdialog-class?view=vs-2017#taskdialogcallback). Check `uNotification == TDN_HYPERLINK_CLICKED`. – zett42 Mar 26 '19 at 22:58
  • @zett42 I am sorry but I have failed at overriding this callback friend method. – Andrew Truckle Mar 27 '19 at 12:53
  • 1
    It propably is a static method so you can't override it. When MFC gets in the way like this, you always have the option to use the API directly, [here is an example](https://github.com/Microsoft/Windows-classic-samples/blob/master/Samples/Win7Samples/winui/shell/appplatform/taskdialogs/TaskDialogSDKSample.cpp). – zett42 Mar 27 '19 at 22:04
  • @zett42 Thanks. I have gone another route not using `CTaskDialog` so this is a moot point now. But we can leave the answer there as someone may have use of it. – Andrew Truckle Mar 27 '19 at 22:20