首页 | 社区 | 博客 | 招聘 | 文章 | 新闻 | 下载 | 读书 | 代码
亲,您未登录哦! 登录 | 注册

让程序出现windows标准对话框式样的帮助

打印文章

分享到:
unit Unit1;
interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

const
  HH_DISPLAY_TOC   = $0001;
  HH_DISPLAY_TOPIC = $0000;
  HH_CLOSE_ALL     = $0012;
  HH_DISPLAY_INDEX = $0002;
  HH_HELP_CONTEXT  = $000F;
  HH_DISPLAY_SEARCH= $0003;
  HH_DISPLAY_TEXT_POPUP = $000E;

type
  HH_FTS_Query = record
    cbStruct : integer; // sizeof structure
    fUniCodeStrings : bool; // true if all strings are unicode
    pszSearchQuery : PChar; // string with the search query
    iProximity : longint; // word proximity
    fStemmedSearch : bool; // true for stemmed search only
    fTitleOnly : bool; // true for title search only
    fExecute : bool; // true to initiate the search
    pszWindow : PChar; // window to display in
  end; // HH_FTS_Query

  HH_POPUP = record
    cbStruct: integer;       // sizeof this structure
    hinst: longint;          // instance handle for string resource
    idString: UINT;          // string resource id, or text id if pszFile is specified in HtmlHelp call
    pszText: LPCTSTR;        // used if idString is zero
    pt: TPOINT;              // top center of popup window
    clrForeground: COLORREF; // use -1 for default
    clrBackground: COLORREF; // use -1 for default
    rcMargins: TRECT;        // amount of space between edges of window and text, -1 for each member to ignore
    pszFont: LPCTSTR;        // facename, point size, char set, BOLD ITALIC UNDERLINE
   end;


type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;

    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

function HtmlHelp(hwndCaller: HWND; pszFile: PChar; uCommand: UINT;
    dwData: PDWORD): HWND; stdcall; external 'hhctrl.ocx' Name 'HtmlHelpA';

procedure TForm1.Button1Click(Sender: TObject);
begin
  {
  调用缺省主题帮助
  此调用方式用于没有上下文ID号的情形,dwData可指定一个在CHM文件内的缺省htm文件,
  也可取Nil,这是HtmlHelp API最基本的一种用法。
  }
  HtmlHelp(handle,pchar('help.chm'),HH_DISPLAY_TOPIC,PDWORD(pchar('article.htm')));
  //或:HtmlHelp(handle,pchar('help.chm'),HH_DISPLAY_TOPIC,nil);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  {
  调用关键字帮助
  此调用方式中dwData取索引文件(.hhk)中存在的关键字。
  }
  HtmlHelp(handle,pchar('help.chm'),HH_DISPLAY_INDEX,PDWORD(pchar('ambaSio')));
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  dw: DWORD;
begin
  {
  调用上下文敏感帮助
  此调用方式用于含有映射信息的CHM文件, dwData取映射表中存在的ID号。
  }
  dw := 10;
  HtmlHelp(handle,pchar('>help.chm'),HH_HELP_CONTEXT,PDWORD(@dw));
  //这种方式我没试出来,可能是我的chm文件不含映射信息的缘故。
end;

procedure TForm1.Button4Click(Sender: TObject);
var
  query: HH_FTS_Query;
begin
  {
  调用全文搜索帮助
  }
  with query do
  begin
    cbStruct := sizeof(HH_FTS_Query);
    fUniCodeStrings := false;
    iProximity := 1;
    fStemmedSearch := true;
    fExecute := true;
    fTitleOnly := false;
    pszWindow := 'MainWin';
    pszSearchQuery := nil;
  end;
  HtmlHelp(handle,pchar('help.chm'),HH_DISPLAY_SEARCH,PDWORD(@query));
end;

procedure TForm1.Button5Click(Sender: TObject);
var
  popup: HH_POPUP;
begin
  {
  调用弹出式帮助
  PszFile通常取NULL,也可以指定一个CHM和一个在该CHM文件中的TEXT文件,DwData用
  于指定一个指向HH_POPUP结构的指针。
  }
  with popup do
  begin
    cbStruct := sizeof(HH_POPUP);
    hinst:= 0;
    idString:=1;
    pszText:=nil;
    //pt:= pt;
    GetCursorPos(pt);
    clrForeground:=COLORREF(-1);
    clrBackground:=COLORREF(-1);
    rcMargins.Left := 0;
    rcMargins.Top := 0;
    rcMargins.Right := 25;
    rcMargins.Bottom := 25;
    pszFont:=LPCTSTR('BOLD');       
  end;
  HtmlHelp(handle,pchar('test.chm'),HH_DISPLAY_TEXT_POPUP,PDWORD(@popup));
  end;

end. 

本栏文章均来自于互联网,版权归原作者和各发布网站所有,本站收集这些文章仅供学习参考之用。任何人都不能将这些文章用于商业或者其他目的。( Pfan.cn )

编程爱好者论坛

本栏最新文章