Click here to Skip to main content
11,576,635 members (60,384 online)
Click here to Skip to main content

CResizeCtrl

, 1 Jul 2000 161.3K 3.3K 61
Rate this:
Please Sign up or sign in to vote.
A resize control to implement resizable dialogs with MFC.
<!-- Download Links -->
  • Download source files - 7 Kb
  • Download demo project - 30 Kb
  • <!-- Main HTML starts here -->

    Introduction

    The CResizeCtrl implements the ResizePercentage method of the WCL (the framework of Optima++ alias Power++, which was dropped by Sybase).

    For each control left, top, width and height is specified, to determine how the position and size of the control windows will change when the size of the parent window changes.

    left specifies the change in the position of the left edge of the object relative to the total change in the parent window’s width.
    For example: Suppose that left is 50 and the width of the window increases by 200 pixels, then the left edge of the object moves right by 100 pixels (50% of 200).

    top specifies the change in the top position of the object relative to the total change in the parent window’s height.
    For example: Suppose that top is 40 and the height of the window decreases by 20 pixels, then the top edge of the object moves up by 8 pixels (40% of 20).

    width specifies the change in the width of the object relative to the total change in the parent window’s width.
    For example: Suppose that width is zero. Then the width of the object does not change, regardless of how much the width of the parent window changes. Or suppose that width is 100 and the width of the window decreases by 50 pixels, then the width of the object also decreases by 50 pixels (100% of 50).

    height specifies the change in the height of the object relative to the total change in the parent window’s height.
    For example: Suppose that height is 20 and the height of the parent's window decreases by 50 pixels, then the height of the object also decreases by 10 pixels (20% of 50).

    The valid range for each parameter is 0 to maxPart, but also the sum of left + width and top + height must be less than or equal to maxPart

    In general, the following formula is used

    newValue = oldValue + (( deltaValueParent * partValue) / maxPart )

    where:

    newValue is the new left or top position or new width or height
    oldValue is the old left or top position or old width or height
    deltaValueParentis the changes in parent width or height
    partValueis the left, top, width or height value specified in the Add Method
    maxPartis the value specified by the maxPart parameter of the constructor or the Create method

    The default value for maxPart is 100, for a better degree of granularity another value can be specified in the Constructor or Create method

    Example :

    // Create the control
    m_resize.Create( this );
    // Add the controls to be resized
    //                         l    t    w    h
    m_resize.Add( IDC_EDIT1,   0,   0, 100,  50 );
    m_resize.Add( IDC_LIST1,   0,  50, 100,  50 );
    m_resize.Add( IDOK,       50, 100,   0,   0 );
    // Use the current width and height 
    // for minimum tracking size
    m_resize.SetMinimumTrackingSize();
    

    Sample Image

    When the width of the parent's window increases by 40 pixels and the height increases by 20 pixels:

    IDC_EDIT1: left +=  0 top +=  0 width += 40 height += 10
    IDC_LIST1: left +=  0 top += 10 width += 40 height += 10
    IDOK     : left += 20 top += 20 width +=  0 height +=  0
    

    Usage :

    Add the file 'ResizeCtrl.cpp' and 'ResizeCtrl.h" to your project
    Because CResizeCtrl can change the style of the dialogbox, it is not necessary to add a resizable border to the dialog template.

    Include "ResizeCtrl.h' in the associated header file and add the CResizeCtrl to the instance data of your dialog class

    #include "ResizeCtrl.h"
    
    class CDemoDialog : public CDialog
    {
      // other stuff
      CResizeCtrl m_resize;
      //....
    

    In OnInitDialog add the controls, that should be resized to the CResizeCtrl object

    BOOL CDemoDialog::OnInitDialog()
    {
      CDialog::OnInitDialog();
        
      // TODO: Add extra initialization here
      // Create the control
      m_resize.Create( this );
      // Add the controls to be resized
      //                         l    t    w    h
      m_resize.Add( IDC_EDIT1,   0,   0, 100,  50 );
      m_resize.Add( IDC_LIST1,   0,  50, 100,  50 );
      m_resize.Add( IDOK,       50, 100,   0,   0 );
      // Use the current width and height 
      // for minimum tracking size
      m_resize.SetMinimumTrackingSize();
    

    or

    BOOL CDemoDialog::OnInitDialog()
    {
      CDialog::OnInitDialog();
        
      // TODO: Add extra initialization here
      // Create the control
      m_resize.Create( this );
      // Add the controls to be resized
      CResizeInfo rInfo[] =
      {
        //  id         l    t    w    h
        { IDC_EDIT1,   0,   0, 100,  50 },
        { IDC_LIST1,   0,  50, 100,  50 },
        { IDOK,       50, 100,   0,   0 },
        { 0 },
      };
      m_resize.Add( rInfo );
      // Use the current width and height 
      // for minimum tracking size
      m_resize.SetMinimumTrackingSize();
    

    Because CResizeCtrl is not a derived class from CDialog, it can be used without changing the dialog template.
    It can even be used with the common controls. The demo project includes an example, how to use it with GetOpenFileName.

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    Share

    About the Author

    Herbert Menke
    Germany Germany
    No Biography provided

    You may also be interested in...

    Comments and Discussions

     
    NewsCResizeCtrl used in HexEdit Pin
    Andrew Phillips7-Mar-07 12:58
    memberAndrew Phillips7-Mar-07 12:58 
    GeneralRe: CResizeCtrl used in HexEdit [modified] Pin
    Andrew Phillips27-Mar-08 2:54
    memberAndrew Phillips27-Mar-08 2:54 
    GeneralA simple solution for CalcValue bug Pin
    YoSilver6-Sep-04 7:18
    memberYoSilver6-Sep-04 7:18 
    GeneralNice class Pin
    Dalroi17-Aug-04 12:16
    memberDalroi17-Aug-04 12:16 
    GeneralTransparent grip Pin
    Tomas Rapkauskas8-Jul-04 21:48
    memberTomas Rapkauskas8-Jul-04 21:48 
    GeneralRe: Transparent grip (GDI object leak) Pin
    babonara23-May-06 23:05
    memberbabonara23-May-06 23:05 
    GeneralWM_SIZING Pin
    cungdaus7-Jun-04 22:00
    membercungdaus7-Jun-04 22:00 
    GeneralSticky window Pin
    one_eddie24-Feb-04 11:56
    memberone_eddie24-Feb-04 11:56 
    QuestionCan this be use with SDI MFC form?? Pin
    goel_aparna@rediffmail.com1-Feb-04 23:54
    membergoel_aparna@rediffmail.com1-Feb-04 23:54 
    AnswerRe: Can this be use with SDI MFC form?? Pin
    ronald_philip7-Mar-04 23:35
    memberronald_philip7-Mar-04 23:35 
    GeneralWindows API Pin
    AshC18-Dec-03 3:48
    memberAshC18-Dec-03 3:48 
    GeneralCannot be used in child dialog Pin
    jmarcos13-Oct-03 1:34
    memberjmarcos13-Oct-03 1:34 
    QuestionHow to retrieve all the controls in a dialog? Pin
    melwyn6-May-03 1:00
    membermelwyn6-May-03 1:00 
    AnswerRe: How to retrieve all the controls in a dialog? Pin
    Ravi Bhavnani3-Jun-03 2:53
    memberRavi Bhavnani3-Jun-03 2:53 
    GeneralRe: How to retrieve all the controls in a dialog? Pin
    melwyn3-Jun-03 3:00
    membermelwyn3-Jun-03 3:00 
    GeneralUpdated CResizeControl version Pin
    Moak24-Dec-02 23:28
    memberMoak24-Dec-02 23:28 
    GeneralRe: Updated CResizeControl version Pin
    Anders Rundegren12-Mar-03 17:04
    memberAnders Rundegren12-Mar-03 17:04 
    GeneralRe: Updated CResizeControl version Pin
    Moak12-Mar-03 18:02
    memberMoak12-Mar-03 18:02 
    GeneralRe: Updated CResizeControl version Pin
    Anders Rundegren13-Mar-03 13:48
    memberAnders Rundegren13-Mar-03 13:48 
    GeneralRe: Updated CResizeControl version Pin
    Moak14-Mar-03 15:49
    memberMoak14-Mar-03 15:49 
    GeneralRe: Updated CResizeControl version Pin
    YoSilver6-Sep-04 7:21
    memberYoSilver6-Sep-04 7:21 
    GeneralRe: Updated CResizeControl version Pin
    MoakNotLoggedin8-Sep-04 3:24
    sussMoakNotLoggedin8-Sep-04 3:24 
    GeneralUpdates Pin
    JLB Stevens4-Nov-02 10:58
    sussJLB Stevens4-Nov-02 10:58 
    GeneralRe: Updates Pin
    Anonymous5-Nov-02 14:02
    sussAnonymous5-Nov-02 14:02 
    GeneralNice Class but it doesn't work in OCX Pin
    Osrald14-May-02 1:40
    memberOsrald14-May-02 1:40 
    GeneralVery good! Pin
    J Cardinal18-Apr-02 5:55
    memberJ Cardinal18-Apr-02 5:55 
    GeneralFantastic ! Pin
    Duncan Weir9-Jan-02 7:16
    memberDuncan Weir9-Jan-02 7:16 
    GeneralReally Nice Class Pin
    SG VanWalla4-Jan-02 9:22
    memberSG VanWalla4-Jan-02 9:22 
    GeneralHI I'm programmer of beginner.... Pin
    Anonymous10-Jul-01 17:44
    memberAnonymous10-Jul-01 17:44 
    GeneralVery good! Pin
    Liam OHagan19-Apr-01 18:17
    memberLiam OHagan19-Apr-01 18:17 
    GeneralRe: Very good! Pin
    Yann Thomas28-Apr-01 10:55
    memberYann Thomas28-Apr-01 10:55 
    GeneralClass is setup nicely, BUT Pin
    Robert B.4-Oct-00 8:10
    sussRobert B.4-Oct-00 8:10 
    GeneralGreat class Pin
    FERNANDO LOZOLLA7-Jul-00 6:54
    sussFERNANDO LOZOLLA7-Jul-00 6:54 
    QuestionDoes it work for Property Sheets & Wizards? Pin
    Andy Metcalfe6-Jul-00 2:54
    sussAndy Metcalfe6-Jul-00 2:54 
    GeneralGood Idea, but controls move out when you resizing many timesi Pin
    Yury2-Jul-00 22:53
    sussYury2-Jul-00 22:53 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    | Advertise | Privacy | Terms of Use | Mobile
    Web04 | 2.8.150603.1 | Last Updated 2 Jul 2000
    Article Copyright 2000 by Herbert Menke
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid