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
Ray
4,99512 gold badges56 silver badges100 bronze badges
-
Calling SetWindowPos() when you make changes to the window frame is requiredHans Passant– Hans Passant2023年02月16日 18:32:04 +00:00Commented 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?Ray– Ray2023年02月16日 22:02:07 +00:00Commented Feb 16, 2023 at 22:02
-
Use SWP_FRAMECHANGED.Hans Passant– Hans Passant2023年02月16日 22:46:44 +00:00Commented Feb 16, 2023 at 22:46
-
@HansPassant I added SWP_FRAMECHANGED but I am still getting scroll bars. See my updated code above.Ray– Ray2023年02月27日 22:02:29 +00:00Commented Feb 27, 2023 at 22:02
-
i note that you are not checking the return codes of any API callpm100– pm1002023年02月27日 22:05:05 +00:00Commented Feb 27, 2023 at 22:05
lang-cs