I make a dialog using visual studio 2017 c++ MFC, and web links by CHtmlEditCtrl.
But, the href links not working...
I expect the following behavior.
- clicking the link
- the browser (ex. chrome) start
- displaying the web page on the browser
How can I fix my code?
BOOL CTestDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// ...
CHtmlEditCtrl* htmledit = new CHtmlEditCtrl();
CEdit* edit = (CEdit*)GetDlgItem(IDC_EDIT_HTML);
CRect rc;
edit->GetWindowRect(&rc);
this->ScreenToClient(&rc);
htmledit->Create(0, (WS_CHILD | WS_VISIBLE), rc, this, IDC_EDIT_HTML, 0);
CComPtr<IHTMLDocument2> document;
htmledit->GetDocument(&document);
WaitForComplete(document);
htmledit->SetDocumentHTML(_T("<a href=\"https://www.google.co.jp/\" target=\"_blank\">Google</a><br><a href=\"https://stackoverflow.com/\" target=\"_blank\">stackoverflow</a>"));
WaitForComplete(document);
return TRUE;
}
void CTestDlg::WaitForComplete(IHTMLDocument2* document)
{
BSTR ready;
document->get_readyState(&ready);
while (wcscmp(ready, L"complete"))
{
AfxPumpMessage();
document->get_readyState(&ready);
};
}
I referred to the following site.