2

The startup form in my VB6 app is behaving strangely when started in a Terminal Services (Remote Desktop) session, with both the host and client being XP Pro machines. The form is meant to be centered but it actually maximises and its content goes to the top left and it looks very strange. Note, this only happens when the app path is used for the "Start the following program on connection" field under the Program tab in the RDP client.

Apparently there is a solution if you are running Server which has TS Configuration tool: http://www.windows-server-answers.com/microsoft/Windows-Terminal-Services/29117908/start-program-on-connection--it-isnt-centered.aspx

But both machines are XP Pro so I can't get TS Configuration.

See example VB6 project here: Link to zip file on Google Docs

If you simply create an EXE of the above project (which runs with a centered non-maximised form when run normally), and use this EXE path when setting the "Start the following program on connection" field under the Program tab in the RDP client, you will find that the app starts with the form maximised with its content in the upper left.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
CJ7
  • 22,579
  • 65
  • 193
  • 321

1 Answers1

3

Apparently Terminal Server is starting your startup application with ShellExecute function, passing SW_MAXIMIZE for nShowCmd instead of SW_SHOWDEFAULT.

You can fix it with a simple hack in Form_Resize event like this

Option Explicit

Private m_bActivated            As Boolean

Private Sub Command_Click()

Me.Text = "HELLO"

End Sub

Private Sub Form_Resize()
    If Not m_bActivated Then
        m_bActivated = True
        WindowState = vbNormal
    End If
End Sub
wqw
  • 11,771
  • 1
  • 33
  • 41
  • How were you able to work out that SW_MAXIMIZE is being passed - Process Explorer? Is this something that MS would fix in an update if they were told about it? – CJ7 Mar 16 '12 at 01:16
  • I guessed it. Didn't have time to reproduce it with a bootstrap app that starts `TestForRDP.exe` using `ShellExecute` with `SW_MAXIMIZE` but setting border style of `Form1` to `Fixed Dialog` didn't work -- that's a clue. – wqw Mar 16 '12 at 09:06