开发者

WTL layout with resizing

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.


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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜