首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >远程桌面会话后窗口大小/位置发生更改

远程桌面会话后窗口大小/位置发生更改
EN

Stack Overflow用户
提问于 2012-11-11 11:00:05
回答 1查看 1.5K关注 0票数 0

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

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

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

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

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

如果笔记本电脑安装了Windows7专业版,这是否有助于解决这个问题?

EN

回答 1

Stack Overflow用户

发布于 2012-11-11 11:24:21

您可能应该将其移动到超级用户,但既然您在StackOverflow上请求,您可以实现一个程序来执行您所描述的操作。

在伪代码中:

代码语言:javascript
复制
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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13328222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档