How to cascade dialogs with MFC C++? RRS feed

  • Question

  • Have a VS2005 MFC C++ application and have been able to program the dialogs to appear in the center of the main window. How can I program to cascade one dialog after another without knowing the order that the dialogs will be displayed in?

    Thursday, March 11, 2010 5:40 PM


All replies

  • You could pass each dialog constructor a CWnd* that points at the previous dialog.  The dialog could then use this pointer in OnInitDialog to locate the previous dialog's screen position (pwnd->GetWindowRect).  The dialog can then move itself to the desired position by calling SetWindowPos.
    Thursday, March 11, 2010 11:27 PM
  • Thank you for your reply, and is there a way to determine what dialogs are "up" or displayed before I start the next one?

    Tuesday, March 16, 2010 1:41 PM
  • Program logic.
    Tuesday, March 16, 2010 2:22 PM
  • If they are modal dialogs (assuming one starts the next) you may have trouble moving the ones pinned behind.  If they are non-modal and can all be accessed I'd create a routine in the parent that just calls MoveWindow() on each of the dialogs offsetting them slightly starting in the center.  You could just move a few pixels down and over for the top left of each dialog.

    Wednesday, March 17, 2010 12:24 AM
  • There is an old API called CascadeWindows that still works.
    Microsoft MVP (Visual C++)
    • Proposed as answer by Nikita Leontiev Wednesday, March 17, 2010 11:33 AM
    • Marked as answer by PXU Wednesday, March 17, 2010 12:02 PM
    Wednesday, March 17, 2010 8:53 AM
  • CascadeWindows great point. Something new for me today.
    Wednesday, March 17, 2010 11:34 AM
  • TileWindows is also cool.
    Another great point for you today. :o)

    Microsoft MVP (Visual C++)
    • Marked as answer by PXU Wednesday, March 17, 2010 12:02 PM
    Wednesday, March 17, 2010 11:49 AM
  • Yes =)
    Wednesday, March 17, 2010 12:02 PM
  • Thank you for the "super" information. I will move forward from here...

    Wednesday, March 17, 2010 12:03 PM