基于阻塞Socket(Indy)的远程控制类库-TNetCommand世界中的礼仪-0

2016-02-19 12:47 17 1 收藏

岁数大了,QQ也不闪了,微信也不响了,电话也不来了,但是图老师依旧坚持为大家推荐最精彩的内容,下面为大家精心准备的基于阻塞Socket(Indy)的远程控制类库-TNetCommand世界中的礼仪-0,希望大家看完后能赶快学习起来。

【 tulaoshi.com - 编程语言 】

TNetImage类?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

源代码

// uNetImge .pas 屏幕图像相关操作

{{

作者:蛐蛐

时间:2004.5.26

}

unit uNetImage;

 

interface

uses

  Classes, Windows, Graphics, Forms, Jpeg, SysUtils,

  IdTCPServer, IdTCPClient,uNetCommand;

type

  TNetImage = class (TNetCommand)

  public

    Compress: Integer;

    ImageStream: TMemoryStream;

    ImageTime: string;

    JpegImage: TJpegImage;

    RemoteImageStream: TMemoryStream;

    RemoteJpegImage: TJpegImage;

    constructor Create;

    destructor Destroy; override;

   

    function ReadData(Client: TIdTCPClient): Boolean; override;

function ReadImage(Client: TIdTCPClient): Boolean;

 

    // : 截取屏幕到Bitmap

    {{

    function SnapScreen.

    BmpScreen 返回值.

    Returns: 调用成功为true,否则为false.

    }

function SnapScreen(var BmpScreen: TBitmap): Boolean; overload;

 

    // : 截取屏幕到JPEG

    {{

    function SnapScreen.

    JpegScreen 返回值 , JpegCompress 图像压缩比.

    Returns: 调用成功为true,否则为false.

    }

    function SnapScreen(var JpegScreen: TJpegImage; JpegCompress: integer=100):

        Boolean; overload;

 

    // : 截取屏幕到Stream

    {{

    function SnapScreenToStream.

    Stream 返回值, JpegCompress 图像压缩比.

    Returns: 调用成功为true,否则为false.

    }

    function SnapScreenToStream(var Stream: TMemoryStream; JpegCompress:

        integer=100): Boolean;

    function WriteData(Server: TIdTCPServerConnection): Boolean; override;

    function WriteImage(Server: TIdTCPServerConnection): Boolean;

  end;

 

const

  CM_GETSCREEN=101;

 

implementation

{

********************************** TNetImage ***********************************

}

constructor TNetImage.Create;

begin

  inherited Create;

  ImageStream:=TMemoryStream.Create;

  JpegImage:=TJpegImage.Create;

  RemoteJpegImage:=TJpegImage.Create;

  RemoteImageStream:=TMemoryStream.Create;

end;

 

destructor TNetImage.Destroy;

begin

  ImageStream.Free;

  JpegImage.Free;

  RemoteJpegImage.Free;

  RemoteImageStream.Free;

  inherited Destroy;

end;

 

function TNetImage.ReadData(Client: TIdTCPClient): Boolean;

begin

  result:=true;

  //

  Client.WriteInteger(TCP_NETIMAGE);    // Client: 1. 通知主人,是我来拜访

  RemoteCommandTime:=Client.ReadLn();

  Client.WriteInteger(CommandType);  // Client 2. 看看老兄的屏幕

 

  case CommandType of    //

// Client: 3. 收到了,把它装到RemoteJpegImage

    CM_GETSCREEN: Result:=ReadImage(Client);

    {  预留操作项

    1: ;

    2: ;

    3: ;

    }

  end;    // case

end;

 

function TNetImage.ReadImage(Client: TIdTCPClient): Boolean;

var

  Size: Integer;

begin

  result:=true;

  try

  with Client do

  begin

    WriteInteger(Compress);   // 2  compress

    Size:=ReadInteger();      // 3  StreamSize

    ReadStream(RemoteImageStream,Size);

    RemoteImageStream.Position:=0;

    RemoteJpegImage.LoadFromStream(RemoteImageStream);

  end;

  except

    result:=false;

  end;

end;

 

function TNetImage.SnapScreen(var BmpScreen: TBitmap): Boolean;

var

  FullScreenCanvas: TCanvas;

  dc: HDC;

  SourceRect, DestRect: TRect;

begin

  result := true;

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)

 

  try

    dc := GetDC(0);

    FullScreencanvas := Tcanvas.Create;

    FullScreencanvas.Handle := dc;

 

    BmpScreen.Width := Screen.Width;

    BmpScreen.Height := Screen.Height;

    SourceRect := Rect(0, 0, Screen.Width, Screen.Height); ;

    DestRect := Rect(0, 0, Screen.Width, Screen.Height); ;

    BmpScreen.Canvas.CopyRect(SourceRect, FullScreenCanvas, DestRect);

  except

     result := false;

  end;

end;

 

function TNetImage.SnapScreen(var JpegScreen: TJpegImage; JpegCompress:

    integer=100): Boolean;

begin

{… }

end;

 

function TNetImage.SnapScreenToStream(var Stream: TMemoryStream; JpegCompress: 

    integer=100): Boolean;

begin

{… }

end;

 

function TNetImage.WriteData(Server: TIdTCPServerConnection): Boolean;

begin

  result:=true;

 

  Server.WriteLn(TimeToStr(GetTime));  // Send Time

  case Server.ReadInteger of    //  Get Commandtype

    // Server: 2. 小事一桩,把屏幕传给你,准备接受

    CM_GETSCREEN: Result:=WriteImage(Server) ;

    1: ;

    2: ;

    3: ;

  end;    // case

 

end;

 

function TNetImage.WriteImage(Server: TIdTCPServerConnection): Boolean;

var

  Stream: TMemoryStream;

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)

begin

  Stream:= TMemorySTream.Create;

 

  Compress:=Server.ReadInteger();    // 1  compress

 

  if SnapScreenToStream(Stream,Compress) then

  begin

    with Server do

    begin

      WriteInteger(Stream.Size);

      WriteStream(Stream);

    end;

    result:=true;

  end

  else

    result:= false;

 

  Stream.Free;

end;

 

end.

 

 

Server端核心程序

procedure TFrmServer.cpsServerExecute(AThread: TIdPeerThread);

var

  intCommand: Integer;

  netCommand: TNetCommand;

begin

  With AThread.Connection do

  begin

    intCommand:=ReadInteger();      //  Server: 1. 究竟是谁来拜访

    case intCommand of

      TCP_NETIMAGE:     //  1.1原来是TNetImage

    netCommand:=TNetImage.Create;  // “主随客便”干脆换上TNetImage的行头

      TCP_NETSYSTEMINFO:

    netCommand:=TNetSystemInfo.Create;

      TCP_NETPROCESS:

    netCommand:=TNetProcess.Create;

      TCP_NETFILE:

    netCommand:=TNetFile.Create;

      {

      //if you have new class ,you can do like this

      TCP_NETEXITWINDOWS:

    netCommand:=TNetExitWindows.Create;

      TCP_NETMOUSE:

    netCommand:=TNetMouse.Create;

 

      }

      TCP_QUIT:

    Disconnect;

    else

      exit;

    end;

  end;

// Server : 1.2总要招待一下客人,问问需要些什么

  netCommand.WriteData(AThread.Connection);

end;

 

Client端请求得到对方屏幕

procedure TFrmClient.aNetImageGetScreenExecute(Sender: TObject);

var

  netImage: TNetImage;

begin

  netImage:=TNetImage.Create;

netImage.CommandType:=CM_GETSCREEN; // 事件 Client: 想看看老兄的屏幕

  netImage.Compress:=netImageCompress;

  if not netImage.ReadData(cpcClient) then

  begin

    ShowMessage('截取屏幕失败!');

  end

  else begin

    imgScreen.Picture.Assign(netImage.RemoteJpegImage);

 

    sbInfo.Panels[0].Text:='截取屏幕成功';

  end;

  netImage.Free;

end;

 

TNetCommand世界中的礼仪

 

事件 Client: 想看看老兄的屏幕

netImage.CommandType:=CM_GETSCREEN; netImage.ReadData(cpcClient)

 

   

Client:

    1. 通知主人,是我来拜访Client.WriteInteger(TCP_NETIMAGE);

Server:

    1. 究竟是谁来拜访? intCommand:=ReadInteger(); 

    1.1原来是TNetImage,“主随客便”干脆换上TNetImage的行头

    netCommand:=TNetImage.Create;

    1.2总要招待一下客人,问问需要些什么

    netCommand.WriteData(AThread.Connection);

    1.3嘘寒问暖,一笔带过吧

    Server.WriteLn(TimeToStr(GetTime));…

           

Client:

    2. 看看老兄的屏幕

    Client.WriteInteger(CommandType); // CommandType:=CM_GETSCREEN

    Server:

    2. 小事一桩,把屏幕传给你,准备接受

    case Server.ReadInteger of   

        CM_GETSCREEN: Result:=WriteImage(Server) ;

    end; 

    

Client:

    3. 收到了,把它装到RemoteJpegImage

    case CommandType of  

        CM_GETSCREEN: Result:=ReadImage(Client);

    end;   

 

得到屏幕图像….    

   

来源:http://www.tulaoshi.com/n/20160219/1601932.html

延伸阅读
iPhone如何远程控制电脑?   相信大部分的机友们都知道iOS设备可以作为遥控器所使用,但是如何利用它进行远程控制电脑开机呢?也许还有很多朋友对这一功能不是很了解,所以接下来图老师小编来和大家分享下iPhone如何远程控制电脑,以下图老师小编为大家总结了远程控制电脑开机方法,有需要的朋友们可以来参考下。 【iPhone远程控...
标签: 电脑入门
    为系统添加远程桌面 默认状态下,Windows 2000及其之前的系统并没有安装远程桌面,要想在这些系统中使用远程桌面,需要自己手工添加。 在Windows XP系统安装光盘的“SUPPORTTOOLS”目录中,可找到一个名为“Msrdpcli.exe”的程序,它实际上就是远程桌面连接登录器。将此程序复制到没有远程桌面的系统中并运行后,即可自...
iphone远程控制电脑教程 想用你的IPHONE就能远程查看并控制PC吗?呵呵!教程如下: 1.下载TightVNC文件;远程桌面软件(TightVNC)2.5.1绿色汉化版 2.安装完后屏幕右下角多了一个V的图标,鼠标移动至V的上面不要按左右键,即可显示PC的IP地址并用笔记录一下; 3.双击屏幕右下角的V,为了安全起见,请更改远程控制密码,在P...
iPhone如何远程控制电脑   电脑上设置: 首先开机按del,进入bios找到wake on lan或者wake on pci打开它,并且关闭主板上的节能选项。(电脑必须连网线才能唤醒,路由器不能关)。接下来开机右键我的电脑-属性-远程,打开远程控制选项。. 接下来设置网卡wake on lan选项,进本地连接-属性-配置网卡。 开启wake ...
在安装redhat9的时候,把vnc服务安装上 在win端安装cwinvnc软件 在linux上执行: vncserver 提示输入密码(这就是以后远程控制这个linux的密码) 可以使用vncpasswd修改密码 在win端执行vnc查看器,输入:serverIP:X 这个“X”就是执行vncserver命令的时候的输出,例如: New 'X' desktop is rh9:2 Starting applications specified in /root/...

经验教程

169

收藏

71
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部