一、非关联的chm帮助 在Delphi中,你可以通过ShellExecute函数直接调用chm帮助文件,具体如下: uses shellapi ....... var HWndHelp:Hwnd; i:integer; begin //检查帮助窗口是否已经存在 HWndHelp:=FindWindow(nil,conHelpTitle); if HwndHelp<>0 then // 如存在则关闭 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 帮助文件损坏!'); end;
function HtmlHelpA (hwndcaller:Longint; lpHelpFile:string; wCommand:Longint;dwData:string): HWND;stdcall; external 'hhctrl.ocx'
3 F1按键响应
//公用函数ShowChmHelp显示不同帮助画面。 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 帮助文件损坏!'); 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; 这样,通过不同窗体的FormHelp事件,就可以实现帮助的关联。