Windows moving together.

This is a discussion on Windows moving together. within the C++ Programming forums, part of the General Programming Boards category; I have two windows that I want to stay next to each other when they are moved. I have an ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    22

    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().
    Code:
    void CFXBOXDlg::OnWindowPosChanged(WINDOWPOS* lpwndpos)
    {
    	CDialog::OnWindowPosChanged(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
    Posts
    22
    I found out how to get the coordinates... I don't know if anyone knows how to fix my second problem...
    Code:
      
    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
    Posts
    847
    Couldn't you just create a window with 2 child windows?

  4. #4
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,904
    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
    Posts
    16
    Quote Originally Posted by The Almighty MSDN article about CWnd::SetWindowPos ([url
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cwnd.3a3a.setwindowpos.asp)][/url]
    nFlags
    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
    Code:
    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, 11:47 AM
  3. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 10:59 AM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 01:19 AM
  5. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 06:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21