注册 | 登录
收藏 | 帮助
热门文章
编辑推荐
相关文章  
从Melissa到Zotob:Windows蠕虫1
从后台得到webshell技巧大汇总
Qmail邮件系统下防止滥用mail re
Qmail邮件系统下防止滥用mail re
使用telnet 方式连接Imail的SMTP
MDeamon Server 邮件系统迁移完全
用RelayFax搭建传真服务器
Qmail邮件系统下防止滥用mail re
隐藏qmail的SMTP help信息保护你
Sendmail的relay用法汇总
您现在的位置: 顶尖设计 >> IT学院 >> 编程开发 >> Delphi >> 文章正文
Delphi Shell
作者:loveghb  来源:csdn  点击:  更新:2006-12-19
简介:
 

这其实是个很老的话题在这里写。实在有点没意义。不过还是写写。因为

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 ;
begin
ShellExecute(self.FHandle,'open',PChar(self.FExeName),nil,nil, SW_SHOW);
end;

//查找指定文件
procedure TShellExecute.FindExe;
begin
ShellExecute(self.FHandle,'find',PChar(self.FExeName),nil,nil, SW_SHOW);
end;

//打印文件
procedure TShellExecute.PrintExe;
begin
ShellExecute(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.

上面可以看到FileName我是用String定义的。然后用Pchar转意。这样就方便了

程序内部调用的通用信。






  • 上一篇文章:
  • 下一篇文章:
  • 分享此文:该页面添加到 Mister Wong 添加到雅虎Yahoo!收藏 Add to:Del.icio.us Post to Furl Digg this 添加到Google书签 reddit spurl blogmarks 365Key 评论  收藏  分享  打印
     我来说两句
    姓名:       验证码:   
    主页: 
    评分: 1分 2分 3分 4分 5分
    本频道近期热评文章:
      关于我们 | 联系我们 | 站点地图 | 广告投放 | 友情链接 | 在线留言 | 版权申明
    版权所有 © 2004-2007 顶尖设计(bobd.cn)
    未经授权禁止转载,摘编,复制本站内容或建立镜像. 沪ICP备07504942号 
    网络110
    报警服务