I am stumped on this one!
I have my own CHtmlView derived class and I recently added support for Find. I did it like this:
void CChristianLifeMinistryEditorDlg::OnEditFind()
{
m_pHtmlPreview->ExecWB(OLECMDID_FIND, OLECMDEXECOPT_PROMPTUSER, nullptr, nullptr);
}
Under the hood the code then does the following:
HRESULT CChristianLifeMinistryHtmlView::ExecWB(OLECMDID cmdID, OLECMDEXECOPT cmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
{
ASSERT(m_pBrowserApp != nullptr);
const auto hr = m_pBrowserApp->ExecWB(cmdID, cmdexecopt, pvaIn, pvaOut);
return hr;
}
It works OK. But only if I render my pages this way in the browser control:
if (m_pHtmlPreview != nullptr)
{
CString strURL = strPreviewXML;
if (iBookmarkId != -1)
strURL.Format(_T("%s#week%d"), (LPCTSTR)strPreviewXML, iBookmarkId);
m_pHtmlPreview->Navigate2(strPreviewXML, 0, nullptr);
//m_pHtmlPreview->Navigate2(strURL, 0, nullptr);
}
In short, if I navigate to the XML file itself then the finding works. But if I try to navigate to the same XMl file, but with my anchor, whilst it displays in the right place in the browser control, the Find feature then will not function:
The moment I change it back to navigating to:
m_pHtmlPreview->Navigate2(strPreviewXML, 0, nullptr);
Then the Find tool is guarenteed to work. But then this means I can no longer jump to the right part of the transformed HTML output. I tried doing:
m_pHtmlPreview->Navigate2(strPreviewXML, 0, nullptr);
m_pHtmlPreview->Navigate2(strURL, 0, nullptr);
I thought that if I navigated first to the page and then to the page with the anchor, that Find would work. But no joy. Can anything be done?
CodePudding user response:
It seems that the mechanics of the Find feature does not like it when you try to navigate to the XML file which has a bookmark in the URL.
I already had code to transform the XML to a HTMl so I added that in as a secondary step:
if (m_pHtmlPreview != nullptr)
{
CString strURL = strPreviewXML;
//if (iBookmarkId != -1)
// strURL.Format(_T("%s#week%d"), (LPCTSTR)strPreviewXML, iBookmarkId);
//m_pHtmlPreview->Navigate2(strPreviewXML, 0, nullptr);
CString strFileXSLPath = theApp.GetWorkingPath() strFileXSL;
if (theApp.MSAToolsInterface().TransformXMLToHTML(strFileXSLPath, strPreviewXML, m_strPreviewHTML))
{
strURL = m_strPreviewHTML;
if(iBookmarkId != -1)
strURL.Format(_T("%s#week%d"), (LPCTSTR)m_strPreviewHTML, iBookmarkId);
}
m_pHtmlPreview->Navigate2(strURL, 0, nullptr);
}
I find that:
- The anchors still function correctly and jump where I want them to.
- The Find continues to work correctly whereas it would stop function before.

