基本信息
源码名称:tcp 远程桌面实例源码
源码大小:0.42M
文件格式:.rar
开发语言:C#
更新时间:2014-06-19
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; using TCPCommunication; namespace RemoteDeskClient { public partial class Form1 : Form { TCPClientSocket _tcpClientSocket; TCPClientSender _tcpClientSender; MyDataClientAnalyse _myDataClientAnalyse; MyDataClientDeal _myDataClientDeal; GlobalHook _gloabalhook; System.Threading.Timer _timer; bool _monitor = false; //监控状态 public Form1() { InitializeComponent(); _tcpClientSocket = new TCPClientSocket(); _tcpClientSender = new TCPClientSender(_tcpClientSocket); _myDataClientAnalyse = new MyDataClientAnalyse(_tcpClientSocket); _myDataClientDeal = new MyDataClientDeal(_myDataClientAnalyse); _timer = new System.Threading.Timer(new TimerCallback(TimerCallBack), null, 0, 100); _tcpClientSocket.ConnectResponsed = new ConnectResponsedEventHandler(_tcpClientSocket_ConnectResponsed); _tcpClientSocket.DisConnected = new DisConnectedEventHandler(_tcpClientSocket_DisConnected); _myDataClientDeal.SimulateKeybdDown = new SimulateKeybdDownEventHandler(_myDataClientDeal_SimulateKeybdDown); _myDataClientDeal.SimulateKeybdUp = new SimulateKeybdUpEventHandler(_myDataClientDeal_SimulateKeybdUp); _myDataClientDeal.SimulateMouseLeftDown = new SimulateMouseLeftDownEventHandler(_myDataClientDeal_SimulateMouseLeftDown); _myDataClientDeal.SimulateMouseLeftUp = new SimulateMouseLeftUpEventHandler(_myDataClientDeal_SimulateMouseLeftUp); _myDataClientDeal.SimulateMouseMove = new SimulateMouseMoveEventHandler(_myDataClientDeal_SimulateMouseMove); _myDataClientDeal.SimulateMouseRightDown = new SimulateMouseRightDownEventHandler(_myDataClientDeal_SimulateMouseRightDown); _myDataClientDeal.SimulateMouseRightUp = new SimulateMouseRightUpEventHandler(_myDataClientDeal_SimulateMouseRightUp); _myDataClientDeal.SimulateMouseWheel = new SimulateMouseWheelEventHandler(_myDataClientDeal_SimulateMouseWheel); _myDataClientDeal.StartMonitor = new StartMonitorEventHandler(_myDataClientDeal_StartMonitor); _myDataClientDeal.StopMonitor = new StopMonitorEventHandler(_myDataClientDeal_StopMonitor); //钩子消耗系统性能 注销掉钩子代码后 服务端无法监控鼠标和键盘输入信息 //_gloabalhook = new GlobalHook(); //_gloabalhook.KeyDown = new KeyEventHandler(_gloabalhook_KeyDown); //_gloabalhook.KeyUp = new KeyEventHandler(_gloabalhook_KeyUp); //_gloabalhook.OnMouseActivity = new MouseEventHandler(_gloabalhook_OnMouseActivity); _myDataClientDeal.Start(); } #region socket状态 void _tcpClientSocket_ConnectResponsed(System.Net.EndPoint remoteEP, bool result) { if (result) { _monitor = true; } } void _tcpClientSocket_DisConnected() { _monitor = false; } #endregion #region 钩子 void _gloabalhook_OnMouseActivity(object sender, MouseEventArgs e) { if (_monitor) { if (e.Button == MouseButtons.Left) { _tcpClientSender.SendString(Msg.ZMsg5, ""); //左键按下 _tcpClientSender.SendString(Msg.ZMsg6, ""); //左键松开 } if (e.Button == MouseButtons.Right) { _tcpClientSender.SendString(Msg.ZMsg7, ""); //右键按下 _tcpClientSender.SendString(Msg.ZMsg8, ""); //右键松开 } if (e.Button == MouseButtons.None && e.Delta == 0) { _tcpClientSender.SendString(Msg.ZMsg4, e.X " " e.Y); //鼠标位置 } //if (e.Delta == 0) //{ // _tcpClientSender.SendString(Msg.ZMsg9, e.Delta.ToString()); //鼠标滚动 //} } } void _gloabalhook_KeyUp(object sender, KeyEventArgs e) { if (_monitor) { _tcpClientSender.SendString(Msg.ZMsg3, e.KeyData.ToString()); } } void _gloabalhook_KeyDown(object sender, KeyEventArgs e) { if (_monitor) { _tcpClientSender.SendString(Msg.ZMsg2, e.KeyData.ToString()); } } #endregion #region 数据处理 void _myDataClientDeal_StopMonitor(string extrainfo, string remoteIP, int remotePort) { _monitor = false; } void _myDataClientDeal_StartMonitor(string extrainfo, string remoteIP, int remotePort) { _monitor = true; } void _myDataClientDeal_SimulateMouseWheel(string mouseinfo, string remoteIP, int remotePort) { string[] infos = mouseinfo.Split(' '); NativeMethods.MouseWheel(int.Parse(infos[2]), int.Parse(infos[0]), int.Parse(infos[1])); } void _myDataClientDeal_SimulateMouseRightUp(string mouseinfo, string remoteIP, int remotePort) { string[] infos = mouseinfo.Split(' '); NativeMethods.MouseRightUp(int.Parse(infos[0]), int.Parse(infos[1])); } void _myDataClientDeal_SimulateMouseRightDown(string mouseinfo, string remoteIP, int remotePort) { string[] infos = mouseinfo.Split(' '); NativeMethods.MouseRigthDown(int.Parse(infos[0]), int.Parse(infos[1])); } void _myDataClientDeal_SimulateMouseMove(string mouseinfo, string remoteIP, int remotePort) { string[] infos = mouseinfo.Split(' '); NativeMethods.MouseMove(int.Parse(infos[0]), int.Parse(infos[1])); } void _myDataClientDeal_SimulateMouseLeftUp(string mouseinfo, string remoteIP, int remotePort) { string[] infos = mouseinfo.Split(' '); NativeMethods.MouseLeftUp(int.Parse(infos[0]), int.Parse(infos[1])); } void _myDataClientDeal_SimulateMouseLeftDown(string mouseinfo, string remoteIP, int remotePort) { string[] infos = mouseinfo.Split(' '); NativeMethods.MouseLeftDown(int.Parse(infos[0]), int.Parse(infos[1])); } void _myDataClientDeal_SimulateKeybdUp(string keyinfo, string remoteIP, int remotePort) { NativeMethods.KeybdUp(keyinfo); } void _myDataClientDeal_SimulateKeybdDown(string keyinfo, string remoteIP, int remotePort) { NativeMethods.KeybdDown(keyinfo); } #endregion #region 屏幕截图 private void TimerCallBack(object obj) { if (_monitor) { Bitmap b = PrintSystemScreen(); _tcpClientSender.SendObject(Msg.ZMsg1, b); } } #endregion private void Form1_Load(object sender, EventArgs e) { } private Bitmap PrintSystemScreen() { Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); Graphics screenG = Graphics.FromImage(bmp); screenG.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy); return bmp; } private void button1_Click(object sender, EventArgs e) { _tcpClientSocket.Start(textBox1.Text, 9999); } } }