com组件远程桌面rdp模块的调用
2015-04-03 16:52
841 查看
rdp(remote desktop protocol)是一个多通道的协议,包括客户端视音传输、文件传输和通讯端口转向等等功能,通过压缩处理的数据网络传输也是相当快。我们在windows操作系统下面,经常用到的mstsc.exe,也提供了com组件调用的接口。
可以建立一个winform的project,通过【工具箱】->【Choose Items】将com控件添加进来。
↑ 可以看到选项卡下面列了多个版本的组件,这里要提醒一下,它们是有版本功能的区别的,他们的clsid都是不一样的,而且代表着不同操作系统版本。这里的向下兼容是对操作系统版本而言,换句话说高一级的版本com控件不一定能在低一级操作系统环境正常运行。
下面从工具箱拖拉过程对于winform应该没有啥异议的地方,我们来看一下wpf如何添加组件,同上的操作,工具箱中com控件的状态是不可用的,通过project的【add reference】列,找到了一项。
↑ terminal service,有种眼熟的感觉,linux下面常用的就是terminal终端,加进来发现少了一个AxInterop.MSTSCLib.dll。解决办法很简单,在wpf project里面加一个winform窗口,让后从工具箱把控件拉过去,project就自动加上这两个接口操作文件。
下面在代码里里敲入一句xaml。
我们再加一个cs,来继承一下这个activex控件。WndProc句柄操作在对象初始化的时候会调用到,以及在rdp的connect等过程也会执行到,看注释是为了解决鼠标焦点异常的问题。
好,在viewmodel里面看一下初始化。看了下这个rdp实现了ISupportInitialize接口,目的是为了初始化相关依赖属性,初始化顺序在BeginInit和EndInit之间完成,只要实现了这个接口,设计器自动帮你完成,在做winform的东西,不知道大家注意到form窗体下面的designer.cs。
下面看一下connect的部分。
ok,咱们看一下大概的效果。
full screen的代码很easy。
好了上面rdp组件大概使用过程,另外这里有个叫WindowsFormsHost的控件值得说一下,xaml里面它的作用是承载winform控件,因为它是独立的hdwnd,所以它是凌驾于xaml控件之上的,比如用scrollviewer根本包不住它,stackoverflow也有人做了相关的扩展。最新4.5 beta framework里面好像对这个空间做了相关扩展,官方文档也有介绍,具体还没有正式发布出来。
可以建立一个winform的project,通过【工具箱】->【Choose Items】将com控件添加进来。
↑ 可以看到选项卡下面列了多个版本的组件,这里要提醒一下,它们是有版本功能的区别的,他们的clsid都是不一样的,而且代表着不同操作系统版本。这里的向下兼容是对操作系统版本而言,换句话说高一级的版本com控件不一定能在低一级操作系统环境正常运行。
下面从工具箱拖拉过程对于winform应该没有啥异议的地方,我们来看一下wpf如何添加组件,同上的操作,工具箱中com控件的状态是不可用的,通过project的【add reference】列,找到了一项。
↑ terminal service,有种眼熟的感觉,linux下面常用的就是terminal终端,加进来发现少了一个AxInterop.MSTSCLib.dll。解决办法很简单,在wpf project里面加一个winform窗口,让后从工具箱把控件拉过去,project就自动加上这两个接口操作文件。
下面在代码里里敲入一句xaml。
<WindowsFormsHost Visibility="{Binding HostVisible}" x:Name="host" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
我们再加一个cs,来继承一下这个activex控件。WndProc句柄操作在对象初始化的时候会调用到,以及在rdp的connect等过程也会执行到,看注释是为了解决鼠标焦点异常的问题。
public class MyRDP : AxMSTSCLib.AxMsRdpClient2NotSafeForScripting { public MyRDP() : base() { } protected override void WndProc(ref System.Windows.Forms.Message m) { // Fix for the missing focus issue on the rdp client component if (m.Msg == 0x0021) // WM_MOUSEACTIVATE { if (!this.ContainsFocus) { this.Focus(); } } base.WndProc(ref m); } }
好,在viewmodel里面看一下初始化。看了下这个rdp实现了ISupportInitialize接口,目的是为了初始化相关依赖属性,初始化顺序在BeginInit和EndInit之间完成,只要实现了这个接口,设计器自动帮你完成,在做winform的东西,不知道大家注意到form窗体下面的designer.cs。
private void InitData() { this.rdp = new MyRDP(); ((System.ComponentModel.ISupportInitialize)(rdp)).BeginInit(); this.rdp.Name = "rdp"; this.rdp.Enabled = true; this.rdp.Dock = System.Windows.Forms.DockStyle.None; this.rdp.Location = new System.Drawing.Point(0, 0); this.rdp.OnConnecting += new EventHandler(this.RDPClient_OnConnecting); this.rdp.OnConnected += new EventHandler(this.RDPClient_OnConnected); this.rdp.OnDisconnected += new AxMSTSCLib.IMsTscAxEvents_OnDisconnectedEventHandler(this.RDPClient_OnDisconnected); host.Child = this.rdp; ((System.ComponentModel.ISupportInitialize)(rdp)).EndInit(); this.BtnContent = "connect"; this.MaskVisible = System.Windows.Visibility.Visible; this.HostVisible = System.Windows.Visibility.Collapsed; }
下面看一下connect的部分。
private void Connect() { this.rdp.Server = this.Address; this.rdp.UserName = this.Name; this.rdp.AdvancedSettings2.RDPPort = 3389; this.rdp.AdvancedSettings2.SmartSizing = true; this.rdp.Width = Convert.ToInt32(System.Windows.SystemParameters.PrimaryScreenWidth); this.rdp.Height = Convert.ToInt32(System.Windows.SystemParameters.PrimaryScreenHeight); this.rdp.DesktopWidth = Convert.ToInt32(System.Windows.SystemParameters.PrimaryScreenWidth); this.rdp.DesktopHeight = Convert.ToInt32(System.Windows.SystemParameters.PrimaryScreenHeight); this.rdp.FullScreenTitle = "this is test"; MSTSCLib.IMsTscNonScriptable secured = (MSTSCLib.IMsTscNonScriptable)rdp.GetOcx(); secured.ClearTextPassword = this.Password; try { this.rdp.Connect(); } catch { } }
ok,咱们看一下大概的效果。
full screen的代码很easy。
private void ToggleFullScreen() { this.rdp.FullScreen = !this.rdp.FullScreen; }
好了上面rdp组件大概使用过程,另外这里有个叫WindowsFormsHost的控件值得说一下,xaml里面它的作用是承载winform控件,因为它是独立的hdwnd,所以它是凌驾于xaml控件之上的,比如用scrollviewer根本包不住它,stackoverflow也有人做了相关的扩展。最新4.5 beta framework里面好像对这个空间做了相关扩展,官方文档也有介绍,具体还没有正式发布出来。
相关文章推荐
- C#调用RDP,实现远程桌面共享及控制
- MFC调用RDP实现远程桌面共享实例
- winxp远程桌面建立与rdp权限的更改
- 更改终端服务(RDP 远程桌面) 默认3389端口
- 调用远程桌面任务管理器
- (转)如何在远程桌面(rdp)映射本地驱动器
- 关于Java RDP协议实现远程桌面连接的开源项目properjavardp
- 一个远程调用api函数的模块(转贴)
- Win7 用远程桌面(rdp+vnc)连接 UBuntu
- Linux下安装FreeRDP,连接windows远程桌面的好软件
- 在 WinForm 中调用 Windows 远程桌面
- 关于Java RDP协议实现远程桌面连接的开源项目properjavardp .
- 修改远程桌面 RDP 端口
- 嗅探、劫持 3389 端口、远程桌面、rdp 协议的一些经验技巧总结
- 【转】Windows 7用远程桌面(RDP+VNC)连接Ubuntu11.04
- CloudStack如何进行RDP(远程桌面)访问,如何登陆系统虚拟机
- 远程桌面协议 (RDP)
- C#调用mstscax.dll编写远程桌面
- html5之应用,纯web rdp 远程桌面连接
- 调戏突破SecureRDP对远程桌面连接的限制