时间: 2021-07-31 作者:daque
由于shellexecute总仍旧在常常用到。并且平率比拟高。但我不安排中心讲shell
的参数。由于我安排做个面向东西封装。避开不需要参数上面下次挪用。
和其它界面api的参数差不离句柄。要举行的操纵。步调名。反面两个不要害
的参数。而后是动静。shellexecute重要实行的操纵是。翻开。搜索。打字与印刷。
所以我安排做三个因变量辨别封装其简直。因为要翻开各别的运用步调中心
是句柄和步调名。以是两个属性。即是它们了。而后我安排介入一个其余功效
即是封闭运用步调。本来即是对要封闭的运用步调发送wm_close动静。
ok咱们就来封装。
//这边自设置一个特殊以简单咱们运用
unit myshell;
interface
uses windows, sysutils, shellapi;//shellexecute就设置在shellapi单位中type tshellexception = class (exception)end;
type tshellexecute = class private fexename : string ; fhandle : hwnd; procedure setexename(value : string); procedure sethandle (value : hwnd); public constructor create(h : hwnd;prgname : string ); property exename : string read fexename write setexename; property handle : hwnd read fhandle write sethandle; procedure execute ; procedure findexe; procedure printexe; procedure closeprg;end;
implementation
constructor tshellexecute.create(h : hwnd;prgname : string );begin if (h>0) and (prgname<>'') then begin self.exename:=prgname; self.handle :=h; end else raise tshellexception.create('handle or prgname is null');end;
//实行网页,email,普遍步调procedure tshellexecute.execute ;beginshellexecute(self.fhandle,'open',pchar(self.fexename),nil,nil, sw_show);end;
//搜索指定文献procedure tshellexecute.findexe;beginshellexecute(self.fhandle,'find',pchar(self.fexename),nil,nil, sw_show);end;
//打字与印刷文献procedure tshellexecute.printexe;beginshellexecute(self.fhandle,'print',pchar(self.fexename),nil,nil, sw_hide);end;
//封闭步调procedure tshellexecute.closeprg;begin self.fhandle:=findwindow(nil,pchar(self.fexename)); if fhandle<>0 then sendmessage(self.fhandle,wm_close,0,0) else raise tshellexception.create('the programm is null')end;
procedure tshellexecute.setexename(value : string);begin if value <> '' then self.fexename:=value else raise tshellexception.create('the name should not null');end;
procedure tshellexecute.sethandle (value : hwnd);begin if value > 0 then self.fhandle:=value else raise tshellexception.create('the handle should not null');end;
end.