【发布时间】:2019-02-02 15:54:01
【问题描述】:
我使用 Visual Studio 2017 c++ MFC 和 CHtmlEditCtrl 的 Web 链接创建一个对话框。
但是,href 链接不起作用...
我期待以下行为。
- 点击链接
- 浏览器(例如 chrome)启动
- 在浏览器上显示网页
如何修复我的代码?
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);
};
}
我参考了以下网站。
【问题讨论】: