C# 无法使用 SetWindowLong 删除外部 RDP 进程上的滚动条

问题描述 投票:0回答:0

我正在尝试从我的 C# 代码启动的 RDP 窗口中删除滚动条。我的代码启动 mstsc.exe,将适当的路径传递给 rdp 文件。但是一旦打开,我的代码就需要删除水平和垂直滚动条。我在下面使用的样式似乎适用于删除粗框,删除最小和最大按钮,但 WS_HSCROLL 和 WS_VSCROLL 似乎被忽略了。

                        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, 不安全本地方法.SWP_NOMOVE |不安全本地方法.SWP_NOSIZE |不安全本地方法.SWP_NOZORDER |不安全本地方法.SWP_NOOWNERZORDER | UnsafeNativeMethods.SWP_FRAMECHANGED);

我有以下定义:

    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);
c# rdp mstsc setwindowlong
© www.soinside.com 2019 - 2024. All rights reserved.