How to stop initial form maximising when run as startup RDP program?

杀马特。学长 韩版系。学妹 提交于 2020-01-04 06:32:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!