Thread: Windows moving together.

  1. #1
    Registered User
    Join Date
    Feb 2005

    Lightbulb Windows moving together.

    I have two windows that I want to stay next to each other when they are moved.
    I have an idea how to do it but I have encountered a few problems. If anyone knows what I'm doing wrong or has a better idea how to do it please feel free to let me know.

    I created an event function for whenever the main window's position changes.
    Whevever it changes I want the second window to follow the main one to it's new coordinates by used SetWindowPos().
    void CFXBOXDlg::OnWindowPosChanged(WINDOWPOS* lpwndpos)
    	// TODO: Add your message handler code here
    	m_dialogX = 0; // I want to insert the coordinates into these variables
    	m_dialogY = 0;
    	CWnd * apptr = FindWindow(0, "Guitar FX BOX 2.6"); //gets handle to main window
    	apptr->SetWindowPos(&wndTopMost, m_dialogX, m_dialogY, 0, 0, SWP_NOSIZE); //sets the second window to its new position
    I want to send the SetWindowPos() the new coordinates of the window but I havent had any luck figuring of how to get them.

    Also, even if I were to get the coordinates, everytime the window moves it puts focus on the second window when SetWindowPos() is triggered. This means I can move the main window by little steps at a time and it's very annoying.

  2. #2
    Registered User
    Join Date
    Feb 2005
    I found out how to get the coordinates... I don't know if anyone knows how to fix my second problem...
    m_dialogX = lpwndpos->x;
    m_dialogY = lpwndpos->y;
    I'll probably end up setting the window to snap when I let go of the left mouse button.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Couldn't you just create a window with 2 child windows?

  4. #4
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    University of Waterloo
    I know there's a win32 function, SetFocus(HWND hwnd) that sets the focus to a particular window. There should be an MFC equivalent.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Quote Originally Posted by The Almighty MSDN article about CWnd::SetWindowPos ([url][/url]
    Specifies sizing and positioning options. This parameter can be a combination of the following:
    SWP_NOACTIVATE Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or the nontopmost group (depending on the setting of the pWndInsertAfter parameter).
    should work. so you would say
    apptr->SetWindowPos(&wndTopMost, m_dialogX, m_dialogY, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  2. Moving Lapack++ dependent code to windows
    By confuted in forum C++ Programming
    Replies: 1
    Last Post: 10-16-2007, 10:47 AM
  3. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 09:59 AM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM