从应用程序c ++开始时,chm文件中没有工作链接

时间:2017-01-25 12:40:38

标签: c++ mfc chm

我正在重写用C ++和MFC编写的旧应用程序。我添加的一项新功能是基于.chm文件的帮助。假设该文件名为myHelp.chm。当我通过双击文件夹将其作为用户打开时,一切正常。但是,如果我开始使用:

::HtmlHelp( NULL, _T("myHelp.chm"), HH_HELP_CONTEXT, uiNumber ) 

在我的应用程序中,帮助部分之间的内部链接不起作用(所有帮助都在一个.chm文件中)。

我有什么:

InitInstance()我得到了:

EnableHtmlHelp();

我在CMainFrame::OnHelp()中运行我的HtmlHelp。

问题可能不在.chm文件中 - 我将其替换为其他工作应用程序,并且它的工作方式相同 - 它打开,但没有内部链接工作。

也许这是项目配置或初始化的东西?这个项目真的很古老 - 1995年 - 现在我在VS2012重写它。我在胜利10下工作。

1 个答案:

答案 0 :(得分:1)

InitInstance处理程序中,您可以执行以下操作:

#ifdef _WIN64 // AJT v11.3.4
    CString strHelp = m_pszHelpFilePath;

    strHelp.MakeLower();
    strHelp.Replace(_T("_x64.chm"), _T(".chm"));

    free((void*)m_pszHelpFilePath);//Change the name of the .HLP file.

    m_pszHelpFilePath = _tcsdup(strHelp);
#endif // _WIN64

因此,您可以更新帮助文件的路径。

然后,在您想要显示帮助的各种窗口中,您可以执行以下操作:

void CMinistryInfoDlg::OnButtonHelp() 
{
    HtmlHelp( (DWORD_PTR)_T("HelpMinistry.htm"),HH_DISPLAY_TOPIC );
}

这对我有用。

上下文帮助

您的问题提到了上下文帮助。在我的应用程序中,我这样做:

BOOL CCommunityTalksApp::ShowContextHelp(CWnd *pParent, HELPINFO* pHelpInfo)
{
    CPoint          ptControl ;
    CRect           rctControl ;
    CWnd            *pControl ;
    CString         strNoHelp, strHelpCommand ;
    HWND            hPopup ;
    HH_POPUP        sPop;
    BOOL            bOK = FALSE;

    if( pParent != NULL && pHelpInfo != NULL )
    {
        memset( &sPop, 0, sizeof(sPop) );

        sPop.clrBackground = GetSysColor( COLOR_INFOBK );

        sPop.clrForeground = -1;
        sPop.rcMargins.top = 5;
        sPop.rcMargins.left = 5;
        sPop.rcMargins.bottom = 5;
        sPop.rcMargins.right = 5;
        sPop.pt = pHelpInfo->MousePos;
        sPop.idString = pHelpInfo->iCtrlId;
        sPop.pszFont = NULL;

        pControl = pParent->GetDlgItem( pHelpInfo->iCtrlId );
        if( pControl != NULL )
        {
            pControl->GetWindowRect( &rctControl ); // Screen co-ords.

            ptControl.x = rctControl.left + (rctControl.Width() / 2);
            ptControl.y = rctControl.bottom ;    // Below control.

            sPop.pt = ptControl;
        }

        if( pHelpInfo->iCtrlId == IDC_STATIC ||
            pHelpInfo->iCtrlId == IDOK ||
            pHelpInfo->iCtrlId == IDCANCEL ||
            pHelpInfo->iCtrlId == IDCLOSE ||
            pHelpInfo->iCtrlId == IDC_HOME_STATIC ||
            pHelpInfo->iCtrlId == IDC_AWAY_STATIC ||
            pHelpInfo->iCtrlId == IDC_TALK_STATIC ||
            pHelpInfo->iCtrlId == ID_STATIC_WEEKS ||
            pHelpInfo->iCtrlId == IDC_STATIC_ENTRIES ||
            pHelpInfo->iCtrlId == IDC_STATIC_AWAY ||
            pHelpInfo->iCtrlId == IDC_STATIC_HOME ||
            pHelpInfo->iCtrlId == IDC_STATIC_TALK_HIST ||
            pHelpInfo->iCtrlId == IDC_LBL_STATIC ||
            pHelpInfo->iCtrlId == IDC_LBL_STATIC2 ||
            pHelpInfo->iCtrlId == ID_LBL_SORT_FIELD_LEGEND ||
            pHelpInfo->iCtrlId == IDC_STATIC_CONG_NOTES ||
            pHelpInfo->iCtrlId == IDC_STATIC_SPK_NOTES ||
            pHelpInfo->iCtrlId == IDC_STATIC_ADD_NEW_TALK ||
            pHelpInfo->iCtrlId == IDC_STATIC_MODIFY_NEW_TALK ||
            pHelpInfo->iCtrlId == ID_BTN_CONGS_SHOW_BOOKED)
        {
            // These control IDs do not have any associated help strings
            // so we use our own, otherwise we get a nasty HtmlHelp
            // error message displayed to the user.
            strNoHelp.LoadString( IDS_STR_NO_CONTEXT_HELP );
            sPop.idString = 0;
            sPop.pszText = strNoHelp;

            hPopup = ::HtmlHelp((HWND)pHelpInfo->hItemHandle,
                m_pszHelpFilePath,
                HH_DISPLAY_TEXT_POPUP,
                (DWORD_PTR)&sPop );
        }
        else
        {
            // This control ID _should_ be in the help strings.
            switch( GetProgramLanguage() )
            {
            case LANGUAGE_SPANISH:
                strHelpCommand.Format( _T("%s::/cshelpESP.txt"), m_pszHelpFilePath );
                break;
            case LANGUAGE_GERMAN:
                strHelpCommand.Format( _T("%s::/cshelpDEU.txt"), m_pszHelpFilePath );
                break;
            case LANGUAGE_ITALIAN:
                strHelpCommand.Format( _T("%s::/cshelpITA.txt"), m_pszHelpFilePath );
                break;
            case LANGUAGE_DUTCH:
                strHelpCommand.Format( _T("%s::/cshelpDEU.txt"), m_pszHelpFilePath );
                break;
            case LANGUAGE_PORTUGUESE:
                strHelpCommand.Format( _T("%s::/cshelpPTB.txt"), m_pszHelpFilePath );
                break;
            case LANGUAGE_SWEDISH:
                strHelpCommand.Format( _T("%s::/cshelpSVE.txt"), m_pszHelpFilePath );
                break;
            case LANGUAGE_DANISH:
                strHelpCommand.Format( _T("%s::/cshelpDAN.txt"), m_pszHelpFilePath );
                break;
            case LANGUAGE_RUSSIAN:
                strHelpCommand.Format( _T("%s::/cshelpRUS.txt"), m_pszHelpFilePath );
                break;
            case LANGUAGE_TURKISH:
                strHelpCommand.Format( _T("%s::/cshelpTRK.txt"), m_pszHelpFilePath );
                break;
            case LANGUAGE_FRENCH:
                strHelpCommand.Format( _T("%s::/cshelpFRA.txt"), m_pszHelpFilePath );
                break;
            case LANGUAGE_FINNISH:
                strHelpCommand.Format( _T("%s::/cshelpFIN.txt"), m_pszHelpFilePath );
                break;
            case LANGUAGE_ALBANIAN:
                strHelpCommand.Format( _T("%s::/cshelpALB.txt"), m_pszHelpFilePath );
                break;
            case LANGUAGE_ROMANIAN:
                strHelpCommand.Format( _T("%s::/cshelpROM.txt"), m_pszHelpFilePath );
                break;
            case LANGUAGE_ENGLISH:
            default:
                strHelpCommand.Format( _T("%s::/cshelpENG.txt"), m_pszHelpFilePath );
                break;
            }

            hPopup = ::HtmlHelp( (HWND)pHelpInfo->hItemHandle,
                            strHelpCommand,
                            HH_DISPLAY_TEXT_POPUP,
                            (DWORD_PTR)&sPop );
        }

        if( hPopup != NULL )
            bOK = TRUE;
    }

    return bOK;
}

我的方法很冗长,因为我支持多种翻译。但你应该能够看到原则。

我发现你使用的HH_HELP_CONTEXT的工作方式略有不同。我不再使用该调用,但是当我这样做时:

void CMainFrame::HtmlHelp(DWORD_PTR dwData, UINT nCmd)
{
    HWND hWnd;

    hWnd = ::HtmlHelp(GetDesktopWindow()->GetSafeHwnd(), theApp.m_pszHelpFilePath,
                    HH_HELP_CONTEXT, nCmd == HELP_CONTEXT ? dwData : 0);

    if(hWnd == NULL)    // show default topic
        ::HtmlHelp(GetDesktopWindow()->GetSafeHwnd(), theApp.m_pszHelpFilePath,
                    HH_HELP_FINDER, 0 );

//  CMDIFrameWndEx::HtmlHelp(dwData, nCmd);
}