4

I am using AxMSTSCLib to develop a Windows App for creating RDP connections.

The steps listed below caused my remote desktop display disappear:

  1. Start an RDP connection with full-screen mode
  2. Click "restore down" button from connection bar
  3. Click "maximize" button again to re-enter full-screen mode
  4. Click "minimize" button
  5. Then my app disappears, I can't see it in taskbar (but still be listed / running in taskmanager)

enter image description here

If I skip steps 2 & 3, it won't disappear when I click "minimize" button from connection bar, it's really weird.

I post some part of my code here, hope anyone can help me to find out the problem.

public partial class RdpShowForm : Form
{
  public AxMSTSCLib.AxMsRdpClient9NotSafeForScripting oRemote;
  public RdpShowForm()
  {
    InitializeComponent();
    oRemote = new AxMSTSCLib.AxMsRdpClient9NotSafeForScripting();
    ((System.ComponentModel.ISupportInitialize)(this.oRemote)).BeginInit();
    oRemote.Dock = System.Windows.Forms.DockStyle.Fill;
    oRemote.Enabled = true;
    oRemote.Name = "WindowsVM";
    this.Controls.Add(oRemote); // Controls contains 'panel1' and 'oRemote'
    ((System.ComponentModel.ISupportInitialize)(this.oRemote)).EndInit();            
    oRemote.CreateControl();
    this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
  }

  private void RdpShowForm_Load(object sender, EventArgs e)
  {
    NewRdpConnectionInstance();
  }

  private void NewRdpConnectionInstance()
  {
    oRemote.Server = 'xxx';
    ...
    oRemote.FullScreen = true;
    oRemote.AdvancedSettings7.DisplayConnectionBar = true;
    oRemote.AdvancedSettings7.ConnectionBarShowMinimizeButton = true;
    oRemote.AdvancedSettings7.ConnectionBarShowRestoreButton = true;
    oRemote.OnConnected += rdpClient_OnConnected;
    oRemote.OnLeaveFullScreenMode += rdpClient_OnLeaveFullScreenMode;

    oRemote.Connect();
    oRemote.Show();
    oRemote.Focus();
  }

  private void rdpClient_OnConnected(object sender, EventArgs e)
  {
    this.panel1.Visible = false;
    this.Visible = false;            
  }

  private void rdpClient_OnLeaveFullScreenMode(object sender, EventArgs e)
  {
    this.Visible = true;
  }

  protected override void WndProc(ref Message m)
  {
    if (m.Msg == WM_SYSCOMMAND)
    {
      if (m.WParam.ToInt32() == MAXIMIZE)
      {
        this.Visible = false;
        oRemote.FullScreen = true;
        oRemote.Show();
      }
    }
    base.WndProc(ref m);
  }
}

I've tried some methods, but none of them worked.

oRemote.Bounds = Screen.PrimaryScreen.WorkingArea;
oRemote.IsAccessible = true;
this.ShowInTaskbar = true;

or

this.Visible = ture; // do not hide the main form

or

if (m.WParam.ToInt32() == MAXIMIZE)
{
  oRemote.FullScreen = true;
  oRemote.Show();
  oRemote.Update();
  oRemote.Refresh();
}

So far, the only solution that came into my mind is to disable the restore button, like this:

oRemote.AdvancedSettings7.ConnectionBarShowRestoreButton = false;

This way isn't fix the problem, just avoid the issue to be triggered.

I would appreciate any help.

Corey
  • 1,217
  • 3
  • 22
  • 39

1 Answers1

0

Since AxMSTSCLib has a restore down issue, I turn to use a form to handle its fullscreen mode. In this way, I can get extensive control over full-screen mode behavior, write code to tell the container what to do when the restore down button is called.

// enable container-handled full-screen mode
oRemote.AdvancedSettings7.ContainerHandledFullScreen = 1;

Then, customize OnRequestGoFullScreen, OnRequestLeaveFullScreen, OnRequestContainerMinimize.

oRemote.OnRequestGoFullScreen += corey_OnRequestGoFullScreen;
oRemote.OnRequestLeaveFullScreen += corey_OnRequestLeaveFullScreen;
oRemote.OnRequestContainerMinimize += corey_OnRequestContainerMinimize;

private void corey_OnRequestGoFullScreen(object sender, EventArgs e)
{
    // set the form to fullscreen
}

private void corey_OnRequestLeaveFullScreen(object sender, EventArgs e)
{
    // set the form back to non-fullscreen mode
}

private void corey_OnRequestContainerMinimize(object sender, EventArgs e)
{
    // minimize the form
}

The method I posted here can be a workaround to this issue.

Corey
  • 1,217
  • 3
  • 22
  • 39