Dialog Resize Helper


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

Environment: Windows 9x, Windows NT/2000

A DlgResizeHelper object helps you keeping a layout while resizing a dialog or - more generally - a window with child windows. For this class I was inspired by an article by John Keogh in DDJ 06/2000 ("Layout Management") and a look at Code Guru revealed some solutions as well. Nevertheless I find my solution more handy (of course ;-): it's C++ (in contrast to Keogh's code) and the class is not derived from CDialog (as most other solutions are) so it can be used with every window.

In the dialog above you some controls want to tell you the meaning of life, but what is it? Now you can simply resize the dialog to read the desired info. Note that you can adjust the resize behaviour of the controls: the lists are resized in height and width, the edit and combo are just resized in width and the buttons stay fixed on the right side where the radio buttons belong to the lower list.

On initialization a DlgResizeHelper stores handles to all child windows of a parent window. Also you can optionally add other windows which shall be resized with the parent window. On resize the DlgResizeHelper resizes the child windows according to the size changes of the parent. By default a child is resized proportional to the parent's size but you can optionally fix the horizontal and/or vertical dimension/position of a child window. E.g. it's reasonable to fix the height of single line edit controls.

Usage (here e.g. with a dialog class):

1. Make your dialog resizable (give it a resizable border)

2. Add a DlgResizeHelper member to your dialog class:

#include "DlgResizeHelper.h"

class CMyDialog : public CDialog
 DlgResizeHelper m_resizeHelper;

3. Initialize the resize helper in OnInitDialog():

BOOL CMyDialog::OnInitDialog()

 // default behaviour is to resize sub windows proportional to the 
 // resize of the parent you can fix horizontal and/or vertical 
 // dimensions for some sub windows by either specifying the 
 // sub window by its hwnd:

 // its item id:

 // or all sub windows with a common class name (especially useful 
 // for single line edit controls)


4. Tell the resize helper when the size has changed:

BEGIN_MESSAGE_MAP(CDlg_resizerDlg, CDialog)

void CMyDialog::OnSize(UINT nType, int cx, int cy) 
 CDialog::OnSize(nType, cx, cy);

That's all. In most cases it is ok if the user enlarges a dialog, but shrinking it would destroy the layout. So you might choose to enforce a minimal dialog size by handling the WM_GETMINMAXINFO message (see demo software for an example).

The demo application is a dialog with a bunch of buttons. The name of the buttons reveal their fixed dimensions.


Download demo project - 66 Kb
Download source - 3 Kb


  • License?

    Posted by sandeep on 09/16/2014 01:53pm

    Is this licensed under the The Code Project Open License (CPOL)? Your article does not specify, and your code says "COPYRIGHT: Stephan Keil " I can't find a way to contact you directly.

    • Re:License?

      Posted by on 09/18/2014 02:53pm

      When code is posted on CodeGuru, the assumption is that it is being made publicly available. If using that code, you should reference the original source of the code (the author).Having said that, we cannot offer legal advice around using someone else's code.

  • enums

    Posted by Amaravathi on 06/27/2012 11:49am

    what are the enums indicate in EHFix, EVFix

  • DlgResizeHelper to resize NTGraph from TabControl

    Posted by wdarsono on 09/19/2011 12:56pm

    Hi, I got some problem to resize NTGraph Control (please refer to: http://www.codeproject.com/KB/miscctrl/ntgraph_activex.aspx?msg=4027575#xx4027575xx) from within TabControl. Basically, I am having a Tab control, and inside the Tab control I have different kind of control. For example: For tab 1, I have NTGraph (Active X control); while for tab 2, I have List Control. For some reason, I can't get the NTGraph Control resized properly (the other tab component, List Control, can be resized fine). I have also tried to resize NTGraph Control as a stand-alone (NOT as a component in a Tab Control) and it works fine. To be more specific about the problem, using the DlgResizeHelper I expected to be able to resize all the components inside my dialog window (including those inside my Tab Control). I am able to resize the List Control (as an element in the second Tab of my TabCtrl), however, I am NOT able to "OnSize" to resize the NTGraph Control (as an element in the first Tab of my TabCtrl). It always gives me the "initialized" (OnInit) size of NTGraph Control. Did you ever have any related experience to what I'm facing now, or any idea that might enlighten me on this problem? Thanks and best regards, Willie

  • Resizing WebBrowser

    Posted by Legacy on 01/13/2003 08:00am

    Originally posted by: Alexey

    It's seems that this class doesn't work with IE.
    I think that the problem in ::GetNextWindow function which didn't returns WebBrowser control.

  • Resize dialog problem

    Posted by Legacy on 10/28/2002 08:00am

    Originally posted by: Satya

    i haev used for the Tab control i haev a list ctrl int the tabs so i have used fo rthat also. it works fine but the The rightside edge of the listctrl is joined with the tabctrl it does not look pretty at all . is ther a solution
    to this

  • Doesn't seem to work with Web Browser Control

    Posted by Legacy on 10/18/2002 07:00am

    Originally posted by: alan

    I added a web browser control to the project which is a regsitered active x control.

    It is inherited from CWnd (Webbrowser2.cpp)

    When I tried to fix the top it wouldn't stay fixed.

    Not sure why?

    It resizes ok but you cant fix any of the sides.

    Please verify this for me.

  • Sizing problem

    Posted by Legacy on 08/16/2002 07:00am

    Originally posted by: David Hubbard

    Has anyone tried using DlgResizeHelper with a dialog box that has 3 list boxes across, the center list box being a fixed width. I have not been able to get this one to work. Any help would be cool...

  • Use in FormWindow

    Posted by Legacy on 08/05/2002 07:00am

    Originally posted by: Normen M�ller

    He folks!

    First of all, that class is a really good one, but i have one problem:

    I use that class in a CFormView, like

    // =====================================================
    void CMyView::OnSize(UINT nType, int cx, int cy)
    //CFormView::OnSize(nType, cx, cy);
    if (!m_bFirstTime) {
    m_bFirstTime = false;
    // =====================================================

    I have a CListCtrl in that View and everything works fine, but when i resize a single column in that list control, there is no horizontal scrollbar.
    Or if i add some items into that list control and the items "scroll" out of the view, there is no vertical scroll bar.

    What am i doing wrong?


  • How to resize the font of the control?

    Posted by Legacy on 06/18/2002 07:00am

    Originally posted by: yy

    Who can tell me?

  • How to manage 2 dialogs at once

    Posted by Legacy on 06/03/2002 07:00am

    Originally posted by: DANIEL

    hello, i have a CTabControl, and would like to know how to make the child dialog on the first tab of the tab control ajust itself along with the parent dialog.
    any way to do this?

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date