C# Unable to remove scroll bars on external RDP process using SetWindowLong

52 Views Asked by At

I am trying to remove the scroll bars from an RDP window that my C# code launches. My code launches mstsc.exe passing the appropriate path the the rdp file. But once it's open, my code needs to remove the horizontal and vertical scroll bars. My style that I am using below seems to work for removing the thick frame, removing the min and max buttons, but the WS_HSCROLL and WS_VSCROLL seems to be ignored.

                        Process m_proc = new Process { StartInfo = { FileName = "mstsc.exe", Arguments = rdpFullPath } };
                        m_proc.Start();

                        //Wait until process is started and main rdp window is created.
                        while (m_proc.MainWindowHandle == IntPtr.Zero)
                        {
                            Thread.Sleep(2000);
                        }

                        // Remove thick frame to disallow resizing of the RDP window, and remove minimize and maximize buttons.
                        var currentStyle = UnsafeNativeMethods.GetWindowLong(m_proc.MainWindowHandle, UnsafeNativeMethods.GWL_STYLE);
                        currentStyle &= ~UnsafeNativeMethods.WS_THICKFRAME;
                        currentStyle &= ~UnsafeNativeMethods.WS_MINIMIZEBOX;
                        currentStyle &= ~UnsafeNativeMethods.WS_MAXIMIZEBOX;
                        currentStyle &= ~UnsafeNativeMethods.WS_HSCROLL;
                        currentStyle &= ~UnsafeNativeMethods.WS_VSCROLL;
                        UnsafeNativeMethods.SetWindowLong(m_proc.MainWindowHandle, UnsafeNativeMethods.GWL_STYLE, currentStyle);

UnsafeNativeMethods.SetWindowPos(m_proc.MainWindowHandle,
                                UnsafeNativeMethods.HWND_TOPMOST, 0, 0, 0, 0,
                                UnsafeNativeMethods.SWP_NOMOVE | UnsafeNativeMethods.SWP_NOSIZE | UnsafeNativeMethods.SWP_NOZORDER | UnsafeNativeMethods.SWP_NOOWNERZORDER | UnsafeNativeMethods.SWP_FRAMECHANGED);
                   

I have the following definitions:

    public const int WS_HSCROLL = 0x00100000;
    public const int WS_VSCROLL = 0x00200000;

    [DllImport("user32.dll")]
    public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

[DllImport("user32.dll")]
    public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

    [DllImport("user32.dll", SetLastError = true)]
    public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy,
        SetWindowPosFlags uFlags);
0

There are 0 best solutions below