Calls to the COM component Remote Desktop RDP module

Source: Internet
Author: User

RDP (Remote Desktop Protocol) is a multi-channel protocol that includes client AV transmission, file transfer, and communication port steering and so on, and the data network transmission via compression is also fairly fast. We use the mstsc.exe, which is often used under the Windows operating system, and also provides the interfaces that COM component calls.

You can create a WinForm project that adds a COM control through the Toolbox, Choose Items.

↑ You can see several versions of the components listed under the tab, here to remind you that they are the difference between the version features, their CLSID is not the same, and represents the different operating system version. This is backwards compatible with the operating system version, in other words, a high-level version of the COM control does not necessarily work in a low-level operating system environment.

The following drag process from the toolbox there should be no objection to WinForm, let's take a look at how WPF adds components, as above, the state of the COM control in the Toolbox is not available, and through the "Add Reference" column of project, an entry is found.

↑terminal service, there is a familiar feeling, Linux is commonly used is the terminal terminal, added in to find a AxInterop.MSTSCLib.dll less. The workaround is simple, add a WinForm window to WPF project, and then pull the control back from the toolbox, and project will automatically add the two interface action files.

In the code below, you'll be typing in a XAML.

1 <  Visibility= "{Binding hostvisible}"  x:name= "Host" HorizontalAlignment = "Stretch" VerticalAlignment = "Stretch" />

Let's add another CS to inherit this ActiveX control. The WndProc handle operation is called when the object is initialized, as well as in the RDP connect process, and the comment is to solve the problem of the mouse focus exception.

1  Public classMyRDP:AxMSTSCLib.AxMsRdpClient2NotSafeForScripting2 {3      Publicmyrdp ()4:Base()5     {6     }7 8     protected Override voidWndProc (refSystem.Windows.Forms.Message m)9     {Ten         //Fix for the missing focus issue on the RDP client component One         if(M.msg = =0x0021)//wm_mouseactivate A         { -             if(! This. Containsfocus) -             { the                  This. Focus (); -             } -         } -  +         Base. WndProc (refm); -     } +}

OK, look at the initialization in ViewModel. Looked at this RDP implements the ISupportInitialize interface, the purpose is to initialize the related dependency properties, the initialization sequence between BeginInit and EndInit, as long as the implementation of this interface, the designer automatically help you do, in doing WinForm things, I don't know if you notice the Designer.cs under form forms.

Private voidInitData () { This. RDP =Newmyrdp (); ((System.ComponentModel.ISupportInitialize) (RDP)).    BeginInit ();  This. rdp. Name ="RDP";  This. rdp. Enabled =true;  This. rdp. Dock =System.Windows.Forms.DockStyle.None;  This. rdp. Location =NewSystem.Drawing.Point (0,0);  This. rdp. Onconnecting + =NewEventHandler ( This.    rdpclient_onconnecting);  This. rdp. onconnected + =NewEventHandler ( This.    rdpclient_onconnected);  This. rdp. ondisconnected + =NewAxmstsclib.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;}

Take a look at the Connect section below.

1 Private voidConnect ()2 {3      This. rdp. Server = This. Address;4      This. rdp. UserName = This. Name;5      This. rdp. Advancedsettings2.rdpport =3389;6      This. rdp. Advancedsettings2.smartsizing =true;7 8      This. rdp. Width =Convert.ToInt32 (System.Windows.SystemParameters.PrimaryScreenWidth);9      This. rdp. Height =Convert.ToInt32 (System.Windows.SystemParameters.PrimaryScreenHeight);Ten      This. rdp. Desktopwidth =Convert.ToInt32 (System.Windows.SystemParameters.PrimaryScreenWidth); One      This. rdp. Desktopheight =Convert.ToInt32 (System.Windows.SystemParameters.PrimaryScreenHeight); A      This. rdp. Fullscreentitle ="This is test"; -Mstsclib.imstscnonscriptable secured =(mstsclib.imstscnonscriptable) RDP. GETOCX (); -Secured. Cleartextpassword = This. Password; the  -     Try -     { -          This. rdp. Connect (); +     } -     Catch +     { A     } at}

OK, let's take a look at the approximate effect.

The code for full screens is easy.

1 Private void Togglefullscreen () 2 {3     this. rdp. fullscreen =!  This . rdp. fullscreen; 4 }

Okay, here's the RDP component probably using the procedure, and here's a control called WindowsFormsHost, which is worth saying, it's the function of XAML to host the WinForm control, because it's a standalone hdwnd, so it's above the XAML control, For example, with ScrollViewer can not wrap it, StackOverflow also someone did the relevant extension. The latest 4.5 Beta framework seems to have expanded this space, and the official documentation has been introduced, not officially released.

Calls to the COM component Remote Desktop RDP module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.