【问题标题】:Window size/positions changed after remote desktop session远程桌面会话后窗口大小/位置发生变化
【发布时间】:2018-09-27 17:36:39
【问题描述】:

我使用远程桌面从一台装有 Windows XP Professional SP3 和一个屏幕的笔记本电脑连接到一台运行 Windows 7 Professional 和两台显示器的远程 PC。

笔记本电脑分辨率约为 1024x768,远程 PC 上的每台显示器约为 1600x900。

在启动远程桌面会话之前,我将 Windows 7 PC 的第二台显示器上的所有窗口移动到第一台显示器。 (笔记本电脑和 PC 都在同一个办公区域。)

远程桌面会话可以工作,但在笔记本电脑上关闭会话并在远程 Windows 7 PC 上恢复工作后,我通常必须重新定位和调整许多窗口的大小才能恢复到原来的排列。

以我目前的配置,如何避免上面的“重新定位和调整大小”步骤?

如果笔记本电脑安装了 Windows 7 Professional,是否有助于解决这个问题?

【问题讨论】:

    标签: remote-desktop


    【解决方案1】:

    您可能应该将其移至超级用户,但由于您在 StackOverflow 上提出要求,因此您可以实现一个执行您所描述的程序。

    在伪代码中:

    class WindowPosition {
        IntPtr hWnd;
        RECT Location;
    }
    
    List<WindowPosition> positions = null;
    
    void OnCaptureWindowPositionHotkey() {
        positions = new List<WindowPosition>();
        EnumWindows(enumStoreWindows, null);
    }
    
    void OnResetWindowPositionHotkey() {
        EnumWindows(enumStoreWindows, null);
    }
    
    void enumSetWindows(IntPtr hwnd, IntPtr obj) {
        positions.Add(new WindowPosition() {
            hWnd = hwnd,
            Location = GetWndLocation(hwnd)
        };
    }
    
    RECT GetWndLocation(IntPtr hwnd) {
        RECT outrect = null;
        GetWindowRect(hwnd, out outrect);
        return outrect;
    }
    
    void enumSetWindows(IntPtr hwnd, IntPtr obj) {
        var loc = (from wl in positions
                  where wl.hWnd == hwnd
                  select wl).FirstOrDefault();
        if (loc == null) return;
        SetWindowPos(hwnd, null, 
            loc.Location.X,
            loc.Location.Y,
            loc.Location.Width,
            loc.Location.Height,
            0);
    }
    

    其中EnumWindowsSetWindowPosGetWindowRect 都是 Win32 函数。看: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633497(v=vs.85).aspxhttp://msdn.microsoft.com/en-us/library/windows/desktop/ms633545(v=vs.85).aspxhttp://msdn.microsoft.com/en-us/library/windows/desktop/ms633519(v=vs.85).aspx

    【讨论】:

      猜你喜欢
      • 2011-06-02
      • 1970-01-01
      • 1970-01-01
      • 2023-02-23
      • 2013-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多