1

I've created two windows with CreateWindowEx(), and now I'd like to stick them side-by-side, so that whenever one is moved, the other one moves relative to the other.

What's the right way of implementing this?

At the moment, I'm using this piece of code:

case WM_MOVING: // When the main window is being moved
    GetWindowRect(hWnd, &rWnd); // Get the current position of the main window
    MoveWindow(hwStats, rWnd.right - 1, rWnd.top, 140, 450, 1); // Move the other window relative to the main window
    return 1; // WM_MOVING is handled by the application
    break; // Done.

The problem with this, is that whenever I move the window, the other window is dragged a few pixels behind.
Now, it doesn't look too bad, but I'd really prefer if it looked a bit more solid.

  • Are you working in MDI Mode? – Guy L Jan 26 '13 at 15:45
  • Maybe create you own application and attach 2 windows? http://stackoverflow.com/questions/10773003/attach-form-window-to-another-window-in-c-sharp I've never tried it myself though – Guy L Jan 26 '13 at 15:54
  • I don't quite see how that'd help me. (Or what that is for, for that matter.) - Here's an image to clarify what I want to achieve: http://i.imgur.com/WTkARUi.png , I'd like it so that when I move MainWindow, theOtherWindow would always stay at the side of the MainWindow, without a delay. –  Jan 26 '13 at 16:01
  • 1
    Google for 'Windows API docking' – Martin James Jan 26 '13 at 19:37
  • `WM_WINDOWPOSCHANGING` is the message you need to look for - when you're notified that one window is **about** to move, move the other one as well. – Jonathan Potter Jan 26 '13 at 20:35

1 Answers1

1

To fix this problem, I needed to change the case from WM_MOVING to WM_MOVE, and the function MoveWindow() to SetWindowPos().

Thank you to Martin James, who told me about "Windows API Docking". That was very helpful.