0

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);
asked Feb 16, 2023 at 15:40
6
  • Calling SetWindowPos() when you make changes to the window frame is required Commented Feb 16, 2023 at 18:32
  • I added the SetWindowPos to my code (see my code above), but it still does not remove scrollbars. I added the call to SetWindowPos to make my window TopMost. Should the call be different? Commented Feb 16, 2023 at 22:02
  • Use SWP_FRAMECHANGED. Commented Feb 16, 2023 at 22:46
  • @HansPassant I added SWP_FRAMECHANGED but I am still getting scroll bars. See my updated code above. Commented Feb 27, 2023 at 22:02
  • i note that you are not checking the return codes of any API call Commented Feb 27, 2023 at 22:05

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.