0

IHTMLDocument2 write(SAFEARRAY)メソッドを使用して、データベースに格納されている文字列からHTMLページを生成しています。これは問題なく動作します。Ctrl + Fキーを押すと、[検索]ダイアログが期待どおりに表示されますが、一致するものはありません。CTRL + Fで何を検索していますか?おそらく、検索で検索するオブジェクトが欠落している(作成する必要があります)のでしょうか。関連するコードは次のとおりです。

CComPtr<IDispatch> m_spDisp;
CComPtr<IWebBrowser2> m_spWeb2;
HRESULT m_hr;
IHTMLDocument2* m_document;

BOOL CSwiftDlg::OnInitDialog()
{
    CDialog::OnInitDialog();
    m_BackMenuButton.SetToolTipText(_T("Back"));
    m_bInitialised = true;
    m_bBackClicked = false;
    m_svURLList.clear();
    m_nCurrentPage = -1;
    m_bitBack.LoadBitmap(IDB_BACK_BITMAP);
        m_BackMenuButton.SetBitmap(m_bitBack);
    m_spGlobal.CreateInstance(__uuidof(GLOBVARSLib::Global ) ); 
    m_browser.Navigate(CSTR m_sURL, NULL, NULL, NULL, NULL);
    GetDocument();
    WriteHTMLString();
    SetWindowSize(512,384);
    return TRUE;
}



void CSwiftDlg::GetDocument()
{
    m_hr = S_OK;
    m_spDisp = m_browser.get_Application();
    if (m_spDisp != NULL && m_spWeb2 ==NULL)
    {
         m_hr = m_spDisp->QueryInterface(IID_IWebBrowser2,(void**)&m_spWeb2);
    }
    if (SUCCEEDED(m_hr) && m_spWeb2 != NULL)
    {
        // get browser document's dispatch interface
        IDispatch *document_dispatch = NULL;
        m_hr = m_spWeb2->get_Document(&document_dispatch);
        if (SUCCEEDED(m_hr) && (document_dispatch != NULL))
        {           // get the actual document interface
            m_hr = document_dispatch->QueryInterface(IID_IHTMLDocument2, (void **)&m_document);
            // release dispatch interface
            document_dispatch->Release();
        }
    }
}


void CSwiftDlg::WriteHTMLString()
{
    if (m_document == NULL)
        GetDocument();  
    SAFEARRAY *empty_array = SafeArrayCreateVector(VT_VARIANT,0,1);
    // construct text to be written to browser as SAFEARRAY
    SAFEARRAY *safe_array = SafeArrayCreateVector(VT_VARIANT,0,1);
    VARIANT *variant;
    SafeArrayAccessData(safe_array,(LPVOID *)&variant);
    variant->vt      = VT_BSTR;
    variant->bstrVal = m_sHTML.AllocSysString();
    SafeArrayUnaccessData(safe_array);
    // write SAFEARRAY to browser document
    m_document->write(empty_array);
    m_document->close();
    m_document->write(safe_array);
}

回答:@Yahiaが示唆したように、それは焦点の問題でした。m_document-> write(safe_array)ステートメントの後にm_document-> execCommand( "Refresh"、...)を追加しました。これは、コンテキストメニューから "refresh"を実行したときのように、Ctrl-Fが期待どおりに機能しました。これで「フォーカスの問題」が修正されました。

4

1 に答える 1

1

CTRL+Fはフォーカスを認識します...あなたはafterおよび/または...をfocus呼び出す必要がありparentWindowますm_documentWriteHTMLString();SetWindowSize(512,384);

于 2011-09-12T02:56:52.727 に答える