4

I'd like to know how people with more WTL knowledge would creating something like this:

A dialog that is resizable (-> WS_THICKFRAME) that contains two 'areas'. One area grows in the y-direction when resizing and contains a few components that should be spaced with equal height distance between each other (e.g. at 0%, 25%, 50%, 75% and 100% of the area height).

The other area is below and has fixed height. Both areas should grow in the x-direction when resizing.

The important questions here are: a) what containers etc. to use for those two areas b) how to handle resizing (DLGRESIZE_CONTROL doesn't allow for spacing the control with equal distance for example, afaik)

Thanks.

xnor
  • 41
  • 2
  • You might get some insight from this answer for MFC: http://stackoverflow.com/questions/138040/how-to-create-a-resizable-cdialog-in-mfc/5739620#5739620 – Mark Ransom May 23 '11 at 20:00
  • That helps a bit, yes. Still wondering how to deal with areas/containers though. – xnor May 23 '11 at 20:20
  • The code I posted doesn't do containers, you're expected to handle each control individually. But your layout doesn't seem too hard, the upper controls move by 0%, 25% etc exactly as you've said, and the bottom part always moves by 100%. – Mark Ransom May 23 '11 at 20:30
  • But what classes can be used as containers? And the top container itself shouldn't be resized by %, since the area below is fixed in height. So I'd need some kind of anchor for this too. – xnor May 23 '11 at 20:39

2 Answers2

2

You could use the CDialogResize class for this. Simply inherit from this class in the class definition of your window and define the way in which each control should resize as the window is updated. These resizes cascade, so you can have a window that is resized in one way that also implements CDialogResize.

class CFooWindow : ... public CDialogResize<CFooWindow> {

    BEGIN_MSG_MAP(CFooWindow)
        MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
        ... more messages here
        CHAIN_MSG_MAP(CDialogResize<CFooWindow>)
    END_MSG_MAP()

    // This map defines how the controls within the window are resized.
    // You can also use DLGRESIZE_GROUP() to group controls together.
    BEGIN_DLGRESIZE_MAP(CFooWindow)
       DLGRESIZE_CONTROL(IDC_WINDOW_TOP,    DLSZ_SZIZE_X | DLSZ_SIZE_Y);
       DLGRESIZE_CONTROL(IDC_WINDOW_BOTTOM, DLSZ_SZIZE_X | DLSZ_MOVE_Y);
    END_DLGRESIZE_MAP()


    LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {

       DlgResize_Init();
    }
      .. the rest of your class here
}

You can implement the gaps between the controls by having a DLGRESIZE_GROUP() and separating the controls in the resource file as you would like them to be separated in the final layout. The size of the items will then be updated. If you need anything too complex you can use the dialog resize callback to control the exact placement of an item. Just implement CDlgResize::OnSize(UINT nType, int cx, int cy) in your class and manually update the size of the control.

Will
  • 4,585
  • 1
  • 26
  • 48
0

This can be done with a splitter. Here is a great tutorial: http://www.codeproject.com/KB/wtl/wtl4mfc7.aspx

You can set SPLIT_BOTTOMALIGNED as the extended style to resize only the top pane (the bottom pane is not resized).

Cosmin
  • 21,216
  • 5
  • 45
  • 60