Simple implementation of association between Delphi program and Chm help Author: Li Xin [email protected] QQ: 1348513 Chm format help is a new format that only appeared after windows98. Compared with .hlp format, it has a simpler editing method and more Rich graphics. It is obtained by compiling web page files through the Chm production tool, so in theory you can make the help file as beautiful as the web page. The simplest production method: first use FronPage to make the help file, and then use HTMLHelpWorkshop to compile it to get the *.chm help file. HTMLHelpWorkshop can be downloaded from Microsoft's website. Help in applications can be divided into context-sensitive and non-contextual types. Context-sensitive means that after the user presses the F1 key, a help screen related to the currently focused object (such as a form, text box, drop-down list box) appears; different help appears for different objects. Non-associative help means that after pressing the F1 key anywhere in the program, the same help screen appears. Let's talk about these two methods and simple implementation methods in Delphi. 1. Non-associated chm help In Delphi, you can directly call the chm help file through the ShellExecute function, as follows: usesshellapi
.......var HWndHelp:Hwnd; i:integer;begin //Check whether the help window already existsHWndHelp:=FindWindow(nil,conHelpTitle); if HwndHelp<>0 then //If it exists, close SendMessage(HwndHelp ,WM_CLOSE,0,0); i:=ShellExecute(handle, 'open',Pchar(strCurExePath+'/help.chm''),nil, nil, sw_ShowNormal); if i<>42 then Showmessage('help.chm help file is damaged!');end; 2. Context-sensitive chm To implement context-sensitive chm help in Delphi, you can call the HtmlHelpA function in the HHCTRL.OCX control under the Windows system directory System32. The following steps are required: 1. Set the HelpContext property of the relevant control. For example, the main form frmMain::10100, the text box edtInput: 10101, the dialog box dlgReport: 10200, the combo list box cbReportEdit: 102012, declare the HtmlHelpA function function HtmlHelpA (hwndcaller:Longint; lpHelpFile:string; wCommand:Longint;dwData :string): HWND;stdcall; external 'hhctrl.ocx'3 F1 key response //Public function ShowChmHelp displays different help screens. PRocedure ShowChmHelp(sTopic:string); var i:integer;begin i:=HtmlHelpA(application.Handle,Pchar(ExePath+'/help.chm'),HH_DISPLAY_TOPIC,sTopic); if i=0 then begin Showmessage(' help. chm help file is damaged! '); exit; end;end;….function TfrmMain.FormHelp(Command: Word; Data: Integer; var CallHelp: Boolean): Boolean;begin case Data of 10100: ShowChmHelp(frmMain.htm); 10101: ShowChmHelp('edtInput.htm');… else ShowChmHelp(default. htm'); end;end;function TdlgReport.FormHelp(Command: Word; Data: Integer; var CallHelp: Boolean): Boolean;begin case Data of 10200: ShowChmHelp('dlgReport.htm');10201: ShowChmHelp(cbReportEdit.htm');… else ShowChmHelp(default .htm'); end;end;