internal RdpClient(ContainerControl parent, Size size, EventHandler resizeHandler) { this.parent = parent; this.size = size; try { rdpControl = rdpClient6 = new MsRdpClient6(); RDPConfigure(size); // CA-96135: Try adding rdpControl to parent.Controls list; this will throw exception when // MsRdpClient6 control cannot be created (there is no appropriate version of dll present) parent.Controls.Add(rdpControl); } catch { if (parent.Controls.Contains(rdpControl)) { parent.Controls.Remove(rdpControl); } rdpClient6 = null; rdpControl = rdpClient2 = new MsRdpClient2(); RDPConfigure(size); parent.Controls.Add(rdpControl); } rdpControl.Resize += resizeHandler; }
internal static void ReleaseClient(RdpClient client) { try { client._server = null; Program.TheForm.RemoveFromClientPanel(client.Control); } finally { AxHost rdpClient = client._rdpClient5; if (rdpClient != null) { client._rdpClient5 = null; rdpClient.Dispose(); } rdpClient = client._rdpClient6; if (rdpClient != null) { client._rdpClient6 = null; rdpClient.Dispose(); } rdpClient = client._rdpClient7; if (rdpClient != null) { client._rdpClient7 = null; rdpClient.Dispose(); } rdpClient = client._rdpClient8; if (rdpClient != null) { client._rdpClient8 = null; rdpClient.Dispose(); } } }
internal RdpClient(ContainerControl parent, Size size, EventHandler resizeHandler) { this.parent = parent; this.size = size; try { rdpControl = rdpClient9 = new MsRdpClient9(); RDPConfigure(size); //add event handler for when RDP display is resized rdpClient9.OnRemoteDesktopSizeChange += rdpClient_OnRemoteDesktopSizeChange; // CA-96135: Try adding rdpControl to parent.Controls list; this will throw exception when // MsRdpClient8 control cannot be created (there is no appropriate version of dll present) parent.Controls.Add(rdpControl); allowDisplayUpdate = true; needsRdpVersionWarning = false; } catch { //any problems: fall back without thinking too much if (parent.Controls.Contains(rdpControl)) { parent.Controls.Remove(rdpControl); } rdpClient9 = null; rdpControl = rdpClient6 = new MsRdpClient6(); RDPConfigure(size); parent.Controls.Add(rdpControl); needsRdpVersionWarning = true; } rdpControl.Resize += resizeHandler; }
public static stdole.IPictureDisp Convert(System.Drawing.Image image) { StringBuilder sbTrace = new StringBuilder(); try { sbTrace.AppendLine("Start"); Logger.SaveLoggerTrace(sbTrace); return((stdole.IPictureDisp)AxHost.GetIPictureDispFromPicture(image)); } catch (Exception ex) { sbTrace.Clear(); sbTrace.AppendLine("Exception" + ex); Logger.SaveLoggerTrace(sbTrace); Logger.LogWriter(ex.StackTrace); return((stdole.IPictureDisp)AxHost.GetIPictureDispFromPicture(image)); } finally { sbTrace.Clear(); sbTrace.AppendLine("End"); Logger.SaveLoggerTrace(sbTrace); } }
internal override void Execute(AxHost ctl) { if (dirties) { ctl.MakeDirty(); } ctl.DoVerb(id); }
/// <summary> /// convert an Image to an OLE Picture IPictureDisp interface /// </summary> /// <param name="image"></param> /// <returns></returns> public static IPictureDisp ToOLE_IPictureDisp(Image image) { #if !__MonoCS__ return(AxHost.GetIPictureDispFromPicture(image) as IPictureDisp); #else return(ImagePicture.FromImage(image)); #endif }
/// <summary> /// convert an Image to an OLE Picture IPictureDisp interface /// </summary> /// <param name="image"></param> /// <returns></returns> public static IPictureDisp ToOLE_IPictureDisp(Image image) { if (Platform.IsWindows) { return(AxHost.GetIPictureDispFromPicture(image) as IPictureDisp); } return(ImagePicture.FromImage(image)); }
private void Dispose(bool disposing) { if (!disposed && disposing) { if (rdpControl != null) { // We need to dispose the rdp control. However, doing it immediately (in the control's own // OnDisconnected event) will cause a horrible crash. Instead, start a timer that will // call the dispose method on the GUI thread at the next available opportunity. CA-12902 // Do not use too small an interval as the accuracy of System.Windows.Forms.Timer is 55ms. int disposalAttempts = 5; Timer timer = new Timer { Interval = 100 }; timer.Tick += (sender, e) => { if (rdpControl != null) { try { rdpControl.Dispose(); Log.Debug("Disposed of rdpControl in timer's tick."); } catch (Exception ex) { if (disposalAttempts > 0) { disposalAttempts--; Log.Debug($"Failed to dispose of rdpControl. Retrying ({disposalAttempts} left)."); return; } Log.Debug("Failed to dispose of rdpControl. Quitting.", ex); } } rdpControl = null; disposed = true; if (sender is Timer t) { t.Stop(); t.Dispose(); Log.Debug("Stopped and disposed of the timer."); } }; timer.Start(); } else { Log.Debug("RdpControl is null"); } } }
public void SwitchLayoutEngine(String id) { AxHost host = null; String url = "about:blank"; switch (id) { case "trident": if (gecko != null) { url = gecko.LocationURL; this.Controls.Remove(gecko as AxHost); gecko = null; } if (trident == null) { trident = new AxWebBrowser(); host = trident as AxHost; } break; default: if (trident != null) { url = trident.LocationURL; this.Controls.Remove(trident as AxHost); trident = null; } if (gecko == null) { gecko = new AxMozillaBrowser(); host = gecko as AxHost; } break; } if (host != null) { host.BeginInit(); host.TabIndex = 1; host.Dock = DockStyle.Fill; host.EndInit(); this.Controls.Add(host); } // Add appropriate content area listeners AddListeners(); ServiceManager.Preferences.SetStringPref("browser.layoutengine", id); LoadURL(url, false); }
public static void SetExtendedProperty(this AxHost axHost, string propertyName, object value) { try { ((IMsRdpExtendedSettings)axHost.GetOcx()).set_Property(propertyName, ref value); } catch (Exception ex) { SimpleLogHelper.Error(ex, ex.StackTrace); } }
private void TryVersion(RDPClientVersion clientVersion, MethodInvoker doApplyVersion) { try { if (lastDetectedVersion == RDPClientVersion.Unknown || lastDetectedVersion == clientVersion) { doApplyVersion(); parent.Controls.Add((Control)client); // can throw a COMException // Finish initialization - com object proxies TrySetSecuredSettings(client.SecuredSettings, typeof(IMsTscSecuredSettings)); TrySetSecuredSettings(client.SecuredSettings2, typeof(IMsRdpClientSecuredSettings)); TrySetAdvancedSettings(client.AdvancedSettings9, typeof(MSTSCLib.IMsRdpClientAdvancedSettings8)); TrySetAdvancedSettings(client.AdvancedSettings8, typeof(MSTSCLib.IMsRdpClientAdvancedSettings7)); TrySetAdvancedSettings(client.AdvancedSettings7, typeof(MSTSCLib.IMsRdpClientAdvancedSettings6)); TrySetAdvancedSettings(client.AdvancedSettings6, typeof(MSTSCLib.IMsRdpClientAdvancedSettings5)); TrySetAdvancedSettings(client.AdvancedSettings5, typeof(MSTSCLib.IMsRdpClientAdvancedSettings4)); TrySetAdvancedSettings(client.AdvancedSettings3, typeof(MSTSCLib.IMsRdpClientAdvancedSettings2)); TrySetAdvancedSettings(client.AdvancedSettings2, typeof(MSTSCLib.IMsRdpClientAdvancedSettings)); TrySetAdvancedSettings(client.AdvancedSettings, typeof(MSTSCLib.IMsTscAdvancedSettings)); if (AdvancedSettings == null) { throw new NotSupportedException(); } transportSettingsProxy = new InterfaceProxy <ITransportSettings>(); transportSettingsProxy.TargetInstance = client.TransportSettings2; transportSettingsProxy.TargetType = typeof(IMsRdpClientTransportSettings2); TransportSettings = transportSettingsProxy.GetStrongTypedProxy(); host = (AxHost)client; host.Width = host.Parent.ClientRectangle.Width; host.Height = host.Parent.ClientRectangle.Height; host.Visible = false; lastDetectedVersion = clientVersion; } } catch (COMException ex) { if (parent.Controls.Contains((Control)client)) { parent.Controls.Remove((Control)client); // yes, this is required! } host = null; client = null; System.Diagnostics.Debug.WriteLine(clientVersion + " failed to initialize: " + ex.Message); lastDetectedVersion = RDPClientVersion.Unknown; } }
internal virtual void Execute(AxHost ctl) { switch (this.id) { case 1: ctl.ShowPropertyPages(); return; case 2: ctl.ShowAboutBox(); return; case 3: ctl.InvokeEditMode(); return; } }
public void Connect(string rdpIP) { try { RDPSetSettings(); } catch (Exception ex) { if (parent.Controls.Contains(rdpControl)) { parent.Controls.Remove(rdpControl); } rdpControl.Dispose(); rdpControl = null; Log.Error("Setting the RDP client properties caused an exception.", ex); } RDPConnect(rdpIP, size.Width, size.Height); }
public void Dispose(bool disposing) { if (!disposed) { if (disposing) { if (rdpControl != null) { // We need to dispose the rdp control. However, doing it immediately (in the control's own // OnDisconnected event) will cause a horrible crash. Instead, start a timer that will // call the dispose method on the GUI thread at the next available opportunity. CA-12902 Timer t = new Timer(); t.Tick += delegate { try { Log.Debug("RdpClient Dispose(): rdpControl.Dispose() in delegate"); rdpControl.Dispose(); } catch (Exception) { // We often get NullReferenceException here } t.Stop(); RdpCleanupTimers.Remove(t); Log.Debug("RdpClient Dispose(): Timer stopped and removed in delegate"); }; t.Interval = 1; RdpCleanupTimers.Add(t); Log.DebugFormat("RdpClient Dispose(): Start timer (timers count {0})", RdpCleanupTimers.Count); t.Start(); } else { Log.Debug("RdpClient Dispose(): rdpControl == null"); } } rdpControl = null; Log.Debug("RdpClient Dispose(): disposed = true"); disposed = true; } }
//private PowerPointShowControl _axHost = null; public PowerPointForm() { InitializeComponent(); Guid dsoGuid = new Guid("00460182-9E5E-11d5-B7C8-B8269041DD57"); string keyName = @"CLSID\{" + dsoGuid + "}"; using (RegistryKey key = Registry.ClassesRoot.OpenSubKey(keyName)) if (key == null) { Label label = new Label(); label.Text = "В системе не установлен DSO компонент необходимый для просмотра"; label.TextAlign = ContentAlignment.MiddleCenter; label.Dock = DockStyle.Fill; this.panel1.Controls.Add(label); return; } //_axHost = new PowerPointShowControl(); _axHost = new AxHost(); _axHost.Dock = DockStyle.Fill; this.panel1.Controls.Add(_axHost); }
private void InitializeRdpComponent() { TryVersion(MsRdpClientVersion.MsClient80, () => { internalMsClient = new MsRDPClient80(); }); TryVersion(MsRdpClientVersion.MsClient70, () => { internalMsClient = new MsRDPClient70(); }); TryVersion(MsRdpClientVersion.MsClient61, () => { internalMsClient = new MsRDPClient61(); }); TryVersion(MsRdpClientVersion.MsClient60, () => { internalMsClient = new MsRDPClient60(); }); TryVersion(MsRdpClientVersion.MsClient50, () => { internalMsClient = new MsRDPClient50(); }); if (lastDetectedVersion == MsRdpClientVersion.Unknown) { throw new NotSupportedException("MsRrdpClient could not be instanciated"); } System.Diagnostics.Debug.WriteLine("AxRDPClient version instanciated: " + lastDetectedVersion); AxHost component = (AxHost)internalMsClient; component.Dock = DockStyle.Fill; Controls.Add(component); }
private void AdjustBounds(AxHost controlToAdjust) { if (this.CurrentAutoScaleDimensions.Width != 6F) { //Adjust location: ActiveX control doesn't do this by itself controlToAdjust.Left = Convert.ToInt32(controlToAdjust.Left * this.CurrentAutoScaleDimensions.Width / 6F); //Undo the automatic resize... controlToAdjust.Width = controlToAdjust.Width / DPIX() * 96; //...and apply the appropriate resize controlToAdjust.Width = Convert.ToInt32(controlToAdjust.Width * this.CurrentAutoScaleDimensions.Width / 6F); } if (this.CurrentAutoScaleDimensions.Height != 13F) { //Adjust location: ActiveX control doesn't do this by itself controlToAdjust.Top = Convert.ToInt32(controlToAdjust.Top * this.CurrentAutoScaleDimensions.Height / 13F); //Undo the automatic resize... controlToAdjust.Height = controlToAdjust.Height / DPIY() * 96; //...and apply the appropriate resize controlToAdjust.Height = Convert.ToInt32(controlToAdjust.Height * this.CurrentAutoScaleDimensions.Height / 13F); } }
internal virtual void Execute(AxHost ctl) { switch (id) { case HOSTVERB_PROPERTIES: ctl.ShowPropertyPages(); break; case HOSTVERB_EDIT: ctl.InvokeEditMode(); break; case HOSTVERB_ABOUT: ctl.ShowAboutBox(); break; default: Debug.Fail("bad verb id in HostVerb"); break; } }
public static IPictureDisp GetImage(string imagename) { try { Assembly asm = Assembly.GetExecutingAssembly(); foreach (string name in asm.GetManifestResourceNames()) { // Find Resource in the Assembly if (name.EndsWith(imagename)) { // Found, so read it and return Icon icon = new Icon(asm.GetManifestResourceStream(name)); return((IPictureDisp)AxHost.GetIPictureDispFromPicture(icon.ToBitmap())); } } return(null); } catch (Exception ex) { logger.Warn(ex.Message + " Can't Find Icon in resources: " + imagename); return(null); } }
internal new static IPicture GetIPictureFromCursor(Cursor cursor) => (IPicture)AxHost.GetIPictureFromCursor(cursor);
/// <summary> /// Convert OleColor to System.Drawing.Color /// </summary> /// <param name="oleColor"></param> /// <returns></returns> internal static Color GetColorFromOleColor(int oleColor) { return(AxHost.GetColorFromOleColor(CIntToUInt(oleColor))); }
/// <summary> /// Convert System.Drawing.Color to OleColor /// </summary> /// <param name="color"></param> /// <returns></returns> internal static new int GetOleColorFromColor(Color color) { return(CUIntToInt(AxHost.GetOleColorFromColor(color))); }
public static IPictureDisp Convert(Image image) { return((IPictureDisp)AxHost.GetIPictureDispFromPicture(image)); }
/// <summary> /// Convert the dispatch interface into an image object. /// </summary> /// <param name="picture">The picture interface</param> /// <returns>An image instance.</returns> public new static Image GetPictureFromIPicture(object picture) { return(AxHost.GetPictureFromIPicture(picture)); }
/// <summary> /// Convert the image to an picturedisp. /// </summary> /// <param name="image">The image instance</param> /// <returns>The picture dispatch object.</returns> public new static object GetIPictureDispFromPicture(Image image) { return(AxHost.GetIPictureDispFromPicture(image)); }
/// <summary> /// convert a Font to an OLE Font IFontDisp interface /// </summary> /// <param name="f"></param> /// <returns></returns> public static IFontDisp ToOLE_IFontDisp(Font f) { return(AxHost.GetIFontFromFont(f) as IFontDisp); }
/// <summary> /// convert a Font to an OLE Font object /// </summary> /// <param name="f"></param> /// <returns></returns> public static StdFont ToOLEFont(Font f) { return(AxHost.GetIFontFromFont(f) as StdFont); }
protected void SetAboutBoxDelegate (AxHost.System.Windows.Forms.AboutBoxDelegate d);
/// <summary> /// convert an Image to an OLE Picture object /// </summary> /// <param name="i"></param> /// <returns></returns> public static StdPicture ToOLEPic(Image i) { return(AxHost.GetIPictureDispFromPicture(i) as StdPicture); }
internal new static IPicture GetIPictureFromPicture(Image image) => (IPicture)AxHost.GetIPictureFromPicture(image);
internal new static IPictureDisp GetIPictureDispFromPicture(Image image) => (IPictureDisp)AxHost.GetIPictureDispFromPicture(image);
public static stdole.IPictureDisp Convert(System.Drawing.Image image) { return((stdole.IPictureDisp) AxHost.GetIPictureDispFromPicture(image)); }