0
votes

I use Remote Desktop to connect from a laptop with Windows XP Professional SP3 and one screen to a remote PC running Windows 7 Professional with two monitors.

The laptop resolution is around 1024x768 and each monitor on the remote PC is around 1600x900.

Before I start the Remote Desktop session, I move all windows on the second monitor of the Windows 7 PC to the first monitor. (Both laptop and PC are in the same office area.)

The Remote Desktop session works, but after closing the session on the laptop and returning to work on the remote Windows 7 PC, I usually have to relocate and resize many of the windows to get back to the original arrangement.

With my current configuration, how can I avoid the "relocate and resize" step above?

If the laptop had Windows 7 Professional, would that help solve this problem?

1

1 Answers

0
votes

You should probably move this to superuser, but since you asked on StackOverflow, you could implement a program that does what you describe.

In pseudocode:

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);
}

where EnumWindows, SetWindowPos and GetWindowRect are all Win32 functions. See: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633497(v=vs.85).aspx, http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545(v=vs.85).aspx, and http://msdn.microsoft.com/en-us/library/windows/desktop/ms633519(v=vs.85).aspx.