我是在程序中运用shellExecute调用CHM帮助文件的,但是如果不是手动关闭CHM帮助文件,而是直接关闭主窗体程序,则CHM帮助文件不能关闭,请问各位高手如何解决?望不惜赐教!(最好具体点)
解决方案 »
- 急!急,ocx问题
- 紧急求助~~
- JPEG调压缩比的怪现象,请帮忙解决,急急急
- 请教各位高手,该学好VB还是Delphi好啊?北京那边做软件技术支持好找吗?
- 好久没上坛子了,请教如何自己绘制TListView的Item,回复者给分.我想绘制不同的颜色哦,请进吧!!
- Dbgrid是否会更新数据,怎么不让他更新,同样的, dbedit等呢?
- Delphi:如何做成PDF格式的文件?解决送分!Come on
- 怎样设置控件的初始字体
- 好消息,可以通过读邮件来点钱,大家若没事干可以试一下!
- 求教:有无函数可控制webbrowser控件滚动条的滚动?!!
- 在delphi中怎样把字符型的的数据插入数据库中类型为uniqueidentifier的字段。急
- 请问一个多媒体播放问题//解决后马上送分
Delphi5并不支持HTML HELP帮助系统,它仍然使用WinHelp。笔者通过反复尝试,发现调用Windows系统目录System32下的HHCTRL.OCX,利用其中的HtmlHelpA函数接口可以自行实现HTML HELP帮助。
公共模块代码如下:
unit HTMLHELPCOMMON
interface
uses Windows;
type
DWORD_PTR = ^DWORD;
Function
HtmlHelp(hwndCaller:HWND;strFile:String;
uCommand:UINT; dwData:DWORD_PTR ):HWND;
procedure CloseHtmlHelp;
implementation
uses
SysUtils;
const
HHControlInstance:THandle=0;
dwCookie :DWORD = 0;
var
HtmlHelpA:function ( hwndCaller:HWND; pszFile:PChar ;
uCommand:UINT; dwData:DWORD_PTR ):HWND;stdcall;
function HtmlHelp(hwndCaller:HWND;strFile:String;
uCommand:UINT; dwData:DWORD_PTR ):HWND;
var
LFileName:String;
p:PChar;
begin
if HHControlInstance=0 then
begin
LFileName := StringOfChar( ' ', 256);
p := PChar( LFilename );
GetSystemDirectory(p,255);
StrCat(p,'\HHCTRL.OCX');
HHControlInstance := LoadLibrary( P );
if HHControlInstance = 0 then
raise exception.Create('Help system not installed!'#13' HTMLHELP cannot displayed!');
@HtmlHelpA := GetProcAddress( HHControlInstance, 'HtmlHelpA');
if @HtmlHelpA = nil then
raise exception.Create('Function HTMLHELP cannot loaded!');
HtmlHelpA( 0, nil,$001C , (@dwCookie));
end;
result := HtmlHelpA( hwndCaller, PChar( strFile ), uCommand, dwData );
end;
procedure CloseHtmlHelp;
begin
if HHControlInstance<>0 then
begin
HtmlHelpA( 0, nil, $001D, DWORD_PTR(dwCookie));
FreeLibrary(HHControlInstance);
end;
end;
end.
两个函数分别初始化和释放调用接口。其它模块只须按约定调用即可。例如:
HtmlHelp( handle, htmlhelpfilename+'::/welcome.htm',$0000, nil);
显示htmlhelpfilename对应的帮助文件的welcome页面。
上下文敏感帮助需要借用Delphi对WinHelp的支持。当用户按 F1 键时,程序将自动触发OnHelp事件,截获它,编写自己的处理代码即可。
... ...
Application.HelpFile := htmlhelpfilename;
tmpOnHelp := Application.OnHelp;
Application.OnHelp := AppHtmlHelp;
... ...
function TForm1.AppHtmlHelp(Command: Word; Data: Longint;
var CallHelp: Boolean): Boolean;
var ret:integer;Hfile:string;
begin
if not CallHelp then exit;
AppPath := ExtractFilePath(Application.ExeName);
Hfile := AppPath + Application.HelpFile;
case Command of
HELP_FINDER, HELP_CONTENTS:
ret := HtmlHelp(handle, pchar(Hfile), $0001, nil);
HELP_QUIT:
ret := HtmlHelp(0, '', $0012, nil);
HELP_CONTEXT:
ret := HtmlHelp(handle, pchar(Hfile), $000f, DWORD_PTR(data));
end;
result:=ret<>0;
CallHelp := False;
end;
这样,我们就有另一种方法调用帮助文件,与传统WinHelp调用方法一样:
application.helpcommand(HELP_FINDER, 0);
application.helpcommand(HELP_quit, 0);
... ...
// 调用方法:
//HtmlHelp(Handle, 'MyHelp.chm::/HelpContent\index.htm',
HH_DISPLAY_TOPIC, nil);
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
wnd:HWnd;
begin
wnd:=FindWindow(nil,'my help');//'my help'是帮助文件的标题
if wnd>0 then
sendmessage(wnd,WM_QUIT,0,0);
canClose:=true;
end;
用以下方法可以根据文件名杀掉其进程,适合关闭有窗口或者无窗口的程序。
function TForm1.KillExteriorProcess():Boolean;
var
FSnapshotHandle:THandle;
FProcessEntry32:TProcessEntry32;
FName :string;
ContinueLoop:Boolean;
ProcessID : integer;
ProcessHndle : THandle;
begin
Result := false;
FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);
ContinueLoop:=Process32First(FSnapshotHandle,FProcessEntry32);
while ContinueLoop do //找到进程不设置跳出,是为了遍历进程,杀掉所有同文件名的进程
begin
FName:=ExtractFileName(FProcessEntry32.szExeFile);
ProcessID := FProcessEntry32.th32ProcessID;
if CompareText(FName,ExteriorFileName) = 0 then
begin
ProcessHndle:=OpenProcess(PROCESS_TERMINATE,BOOL(0),ProcessID);
Result:=TerminateProcess(ProcessHndle,0);
if Not Result then
begin //如果找到进程可是不能杀掉它,直接跳出循环,不再继续查找下一个可能符合条件的进程
WriteLog('找到进程,可是不能杀掉!');
Break;
end;
end;
ContinueLoop:=Process32Next(FSnapshotHandle,FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;