WEB开发网
开发学院软件开发VC 如何用Win32 SDK编程创建Tri-pane HTML Help窗口 阅读

如何用Win32 SDK编程创建Tri-pane HTML Help窗口

 2010-01-09 20:31:43 来源:WEB开发网   
核心提示:HTML Help使用户能在一个帮助窗口中使用工具棒、查看目录和帮助主题,目前,如何用Win32 SDK编程创建Tri-pane HTML Help窗口,有两种方法创建Tri-pane类型的HTML Help窗口:使用HTML Help Workshop创建窗口使用HTML Help API编程创建窗口本文将介绍如何使

HTML Help使用户能在一个帮助窗口中使用工具棒、查看目录和帮助主题。目前,有两种方法创建Tri-pane类型的HTML Help窗口:

使用HTML Help Workshop创建窗口

使用HTML Help API编程创建窗口

本文将介绍如何使用这两种方法创建Tri-pane HTML Help窗口。

使用预定义窗口

在HTML Help Workshop环境中很容易创建和修改工程的窗口定义,有关窗口定义的其它信息,请参考微软知识库文章:Q189084 HOWTO: Create a Tri-pane Window with HTML Help Workshop

本文假设在你的应用程序开发工具为 Visual C++,那么要在自己的程序中使用HTML Help帮助,必须借助于HTML Help提供的 API 函数;要调用这些 API 函数,就必须包含 htmlhelp.h 文件,并且将库文件 hhctrl.lib 或者 htmlhelp.lib 链接到自己的程序代码中。只要你安装了HTML Help Workshop环境,这 些文件存放在 HTML Help Workshop下的 \Include 和 \Lib 目录中。

在下面的示范代码中,sample.chm是一个编译好的HTML Help帮助文件,其中有一个叫“mywindow”的窗口定义, 下面的代码示范了如何在一个MFC程序中调用HTML Help API函数:

// CMainFrame message handler
  void CMainFrame::OnHelp()
  {
   // display the topic "intro.htm" in the window defined
   // in the HTML Help Workshop
    HtmlHelp(m_hWnd,"sample.chm::\\intro.htm>mywindow",
     HH_DISPLAY_TOPIC,0);
  }

使用HTML Help API

为了创建three-pane窗口, 必须首先创建和填写HH_WINTYPE结构。HH_WINTYPE结构在HtmlHelp.h中定义,详细说明参见HTML Help Workshop文档。以下是一个例子:

Sample Code
  ///////////////////////////////////////////
  // Create an HH_WINTYPE structure.
  {
    HH_WINTYPE m_hhWinType;
    // Initialize all structure members to zero.
    ZeroMemory(&m_hhWinType, sizeof(HH_WINTYPE));
    // Define a custom message for use with idNotify.
    // You are responsible for ensuring that this ID
    // does not conflict with other Windows/MFC messages.
    #define IDD_HELPTAB 69999
    // Set the size of the structure.
     m_hhWinType.cbStruct = sizeof(HH_WINTYPE);
    // Set up the properties of the HTML window:
    // tripane window, sync topic with index/TOC, and so forth.
    // NOTE: fsValidMembers - HHWIN_PARAM_PROPERTIES must be set.
    m_hhWinType.fsWinProperties = HHWIN_PROP_TRI_PANE |
    HHWIN_PROP_AUTO_SYNC;
    // Put BACK, HOME, FORWARD, and EXPAND buttons on toolbar pane.
    // NOTE: fsValidMembers - HHWIN_PARAM_TB_FLAGS must be set.
    m_hhWinType.fsToolBarFlags = HHWIN_BUTTON_BACK |
     HHWIN_BUTTON_HOME | HHWIN_BUTTON_FORWARD |
     HHWIN_BUTTON_EXPAND;
    // The file is in the right pane. The full path is not needed.
    m_hhWinType.pszFile = "intro.htm";
    // Full Paths or CHM locations of various files (if used).
    // To specify that a file is within a CHM, use the following
    // syntax: "CHMFileName.chm::\\FileName.xxx"
    // Home Page:
     m_hhWinType.pszHome = "c:\\mypath\\intro.htm";
    // Table of Contents:
    m_hhWinType.pszToc = "c:\\mypath\\contents.hhc";
     // Index:
    m_hhWinType.pszIndex = "c:\\mypath\\index.hhk";
     // Expansion width of navigation pane (left pane):
    // NOTE: fsValidMembers - HHWIN_PARAM_NAV_WIDTH must be set.
    m_hhWinType.iNavWidth = 175;
    // Initial display state:
    // NOTE: fsValidMembers - HHWIN_PARAM_SHOWSTATE must be set.
    m_hhWinType.nShowState = SW_RESTORE;
    // TOC should be activated.
    // NOTE: fsValidMembers - HHWIN PARAM_CUR_TAB must be set.
     m_hhWinType.curNavType = HHWIN_NAVTYPE_TOC;
    // Tabs on top.
    // NOTE: fsValidMembers - HHWIN_PARAM_TABPOS must be set.
    m_hhWinType.tabpos = HHWIN_NAVTAB_TOP;
    // ID to use in WPARAM in WM_NOTIFY:
    m_hhWinType.idNotify = IDD_HELPTAB;
    // Title of Help Window:
    m_hhWinType.pszCaption= "My Title";
    // Indicate which fields in structure are valid.
    m_hhWinType.fsValidMembers = HHWIN_PARAM_STYLES |
     HHWIN_PARAM_PROPERTIES | HHWIN_PARAM_RECT |
    HHWIN_PARAM_TB_FLAGS | HHWIN_PARAM_NAV_WIDTH |
    HHWIN_PARAM_SHOWSTATE | HHWIN_PARAM_TABPOS |
     HHWIN_PARAM_CUR_TAB;
    // Specify the name of the window definition.
     m_hhWinType.pszType = "MyWindowName";
    // This call creates the new type from the values in
    // the HH_WINTYPE structure. This example assumes that
    // a valid CHM file, "sample.chm", exists.
    HtmlHelp (m_hWnd, "c:\\mypath\\sample.chm",
     HH_SET_WIN_TYPE, (DWORD) &m_hhWinType);
  }
  // Display the default topic in the window that was defined above
  // MFC''s CFrameWnd::OnHelp message handler.
  void CMainFrame::OnHelp()
  {
  HtmlHelp(m_hWnd, "sample.chm>MyWindowName",
  HH_DISPLAY_TOPIC,0);
  }

1 2  下一页

Tags:如何 Win SDK

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接