HtmlHelp MS API搜索字符串

时间:2017-06-08 13:16:52

标签: c++ visual-c++ html-help

2017年是否有人知道如何实现调用HtmlHelp函数,该函数将打开.chm文件"搜索"窗格和查询字符串在其列表框中,是否能够执行此查询?

我试着跟随:

HH_FTS_QUERY query;

query.cbStruct         = sizeof(HH_FTS_QUERY);
query.fUniCodeStrings  = TRUE;
query.pszSearchQuery   = szSearchStr;
query.iProximity       = HH_FTS_DEFAULT_PROXIMITY;
query.fStemmedSearch   = TRUE;
query.fTitleOnly       = TRUE;
query.fExecute         = TRUE;
query.pszWindow        = NULL;

HWND hHelpWnd = ::HtmlHelp(m_hWnd, szFile, HH_DISPLAY_SEARCH, (DWORD_PTR)&query);

但是query.pszSearchQuery中的查询不会被执行。我用" Search"中的query.pszSearchQuery打开了.chm文件。我的屏幕上的窗格列表框,但我必须单击"列出主题"我自己要显示搜索结果。

1 个答案:

答案 0 :(得分:1)

HTMLHelp API - VBA, VB6 and VB2003的帮助下,我会尽力回复。 我相信没有API函数来列出vc ++中的主题。您已将按钮点击事件发送到已启动的帮助窗口。

LRESULT OnSearch(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
        TCHAR szBuf[128];
        GetDlgItem(IDC_EDIT1).GetWindowText(szBuf, sizeof(szBuf));

        if (!_tcslen(szBuf))
            return 0;

        //
        // First, invoke HtmlHelp with HH_DISPLAY_SEARCH. 
        // It doesn't execute search, but it's need for showing 'search' tab.
        //
        HH_FTS_QUERY fq;
        ZeroMemory(&fq, sizeof(fq));
        fq.cbStruct = sizeof(fq);
        fq.fUniCodeStrings = FALSE;
        fq.pszSearchQuery = (LPCTSTR)szBuf;
        fq.iProximity       = HH_FTS_DEFAULT_PROXIMITY;
        fq.fStemmedSearch   = FALSE;
        fq.fTitleOnly       = FALSE;
        fq.fExecute         = FALSE;
        fq.pszWindow        = NULL;
        HWND hwndHelp = ::HtmlHelp(NULL, _T("realplay.chm"), HH_DISPLAY_SEARCH, (DWORD)&fq);

        //
        // Find query combobox and set query text.
        // 
        HWND hPaneWnd, hPaneLast, hTabWnd, hDlgWnd, hCtlWnd;

        hPaneWnd = FindWindowEx(hwndHelp, NULL, _T("HH Child"), NULL);
        for (;;) // last HH Child
        {
            hPaneLast = FindWindowEx(hwndHelp, hPaneWnd, _T("HH Child"), NULL); // last HH Child
            if (!hPaneLast)
                break;
            hPaneWnd = hPaneLast;
        }
        ATLTRACE("hPaneWnd == %x", hPaneWnd);

        hCtlWnd = FindWindowEx(hPaneWnd, NULL, _T("Button"), NULL); // skip Tab Control
        //
        // There are two types of interfaces:
        //
        // 1.
        // Window hierarchy:
        // + Main window 
        //   + HH Child
        //     + Browser ...
        //   + HH Child       <- second "HH Child" window
        //         - Edit     <- we have to fill this edit
        //         - Buttons  <- and press this buttons
        //         ...
        if (hCtlWnd)
        {
            hCtlWnd = FindWindowEx(hPaneWnd, NULL, _T("Edit"), NULL); // skip Tab Control
            // Set window text
            ATLASSERT(hCtlWnd != NULL);
            ::SendMessage(hCtlWnd, WM_SETTEXT, 0, (LPARAM)szBuf);   // fill it by our query

            ::SendMessage(hwndHelp, WM_COMMAND, 0xbc7, 0); // 0x3ee -- 'List Topics' button, it runs search
            if (::SendMessage(GetDlgItem(IDC_CHECK1), BM_GETCHECK, 0, 0) == BST_CHECKED)
                ::SendMessage(hwndHelp, WM_COMMAND, 0xbbe, 0); // 0x3f1 -- 'Display' button, it shows first item
        }
        //2.
        // Window hierarchy:
        // + Main window 
        //   + HH Child
        //     + Browser ...
        //   + HH Child       <- second "HH Child" window
        //     + Tab Control
        //       + Dialog
        //         - Combobox <- we have to fill this combo
        //         - Buttons  <- and press this buttons
        //         ...
        else
        {

            hTabWnd = FindWindowEx(hPaneWnd, NULL, _T("SysTabControl32"), NULL); // skip Tab Control
            hDlgWnd = FindWindowEx(hTabWnd, NULL, NULL, NULL); // skip dialog

            TCHAR szClass[64];
            GetClassName(hDlgWnd, szClass, sizeof(szClass));
            ATLTRACE("hDlgWnd(1) == %x", hDlgWnd);
            if (!_tcsstr(szClass, "#")) // Is it dialog?
                hDlgWnd = FindWindowEx(hTabWnd, hDlgWnd, NULL, NULL); // skip dialog
            hCtlWnd = FindWindowEx(hDlgWnd, NULL, _T("ComboBox"), NULL); // well, it's combobox

            // Set window text
            ATLASSERT(hCtlWnd != NULL);
            ::SendMessage(hCtlWnd, WM_SETTEXT, 0, (LPARAM)szBuf);   // fill it by our query

            //
            // Run search and show first finded page
            //
            ::SendMessage(hwndHelp, WM_COMMAND, 0x3ee, 0); // 0x3ee -- 'List Topics' button, it runs search
            if (::SendMessage(GetDlgItem(IDC_CHECK1), BM_GETCHECK, 0, 0) == BST_CHECKED)
                ::SendMessage(hwndHelp, WM_COMMAND, 0x3f1, 0); // 0x3f1 -- 'Display' button, it shows first item
        }
        return 0;
}

修改

您可以通过spy ++获取List Topic的控件ID enter image description here