2017-06-08 21 views
1

2017年的任何人都知道如何實現調用HtmlHelp函數,它將打開.chm文件與「搜索」窗格和查詢字符串在它的列表框中,並將能夠執行此查詢?HtmlHelp MS API搜索字符串

我嘗試以下操作:

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查詢將不會被執行。我在屏幕上的「搜索」窗格的列表框中打開了帶有query.pszSearchQuery的.chm文件,但我必須自己單擊「列出主題」以顯示搜索結果。

回答

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; 
} 

編輯:

您可以通過間諜獲得的列表主題的控件ID ++ enter image description here

+0

謝謝您的回答!我也想到了這種方法,但我不明白這篇文章的作者如何確定「0x3ee - '列出主題'按鈕」等等? – brightside90

+0

@ brightside90更新了回答.. –

+0

哦,這很酷 – brightside90