问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/9713285/how-to-stop-initial-form-maximising-when-run-as-startup-rdp-program