程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 如何讓程序出現windows標准對話框

如何讓程序出現windows標准對話框

編輯:Delphi

  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.  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved