Click here to Skip to main content
13,148,427 members (65,520 online)
Click here to Skip to main content
Add your own
alternative version


19 bookmarked
Posted 1 Feb 2000

A Sizing/Moving widget

, 1 Feb 2000
Rate this:
Please Sign up or sign in to vote.
A class that provides the ability to move and size controls at run-time
  • Download demo project - 29 Kb
  • Download source files - 5 Kb
  • Sample Image - CSizer.gif

    <!-- Article Starts -->


    The class described here is derived from CStatic, to provide the ability to move and size controls at run-time. I wrote this specifically for a dialog editor as part of a much larger project. Admittedly, it is of little value except in the application described but as I looked everywhere for this and couldn't find one, I thought other people might be looking too.

    As you can see I tried to recreate the look of the one to be found in the MSVC dialog editor. Moving the cursor over any of the "sizing handles" changes the cursor to indicate that dragging is supported. Once the left mouse button is pressed, you can size the control as desired. Moving the cursor over any other part of the control displays a IDC_SIZEALL mouse cursor, indicating that moving is supported. Holding the left mouse button down allows you to move the control.

    On moving or sizing the target control is sized/moved, allowing any control to be adjusted. Unlike the one provided in MSVC's dialog editor, the target control is not "obscured" by this control, so it can respond itself to mouse events.

    The guts of this class reside in the OnMouseMove function, taking action there depending on

    1. Cursor Position - Changes the mouse cursor
    2. Action Flags - If the left mouse button is down what action to take

    Known Problems:

    If, once dragging or sizing has started, the mouse is moved too rapidly, the control can't keep up and loses focus, and therefore dragging or sizing stops immediately.

    How to use:

    1. Add the files WidgetSizer.cpp & WidgetSizer.h to your project
    2. Somewhere in your project, define a global pointer var of type CWidgetSizer
    3. In your main class implementation file define this pointer and nullify it
    4. In each of your controls include the header file where the declaration extern CWidgetSizer *myvar lives
    5. Insert code to create the CWidgetSizer class where appropriate to your application. For example when the target control is created
      if (g_pWidgetSizer)
      	delete g_pWidgetSizer;
      	g_pWidgetSizer = NULL;
      g_pWidgetSizer = new CWidgetSizer(m_pParent, this);

      or when left mouse button down is called

      if (g_pWidgetSizer)
      	if (g_pWidgetSizer->AmITheTarget(this))
      	delete g_pWidgetSizer;
      	g_pWidgetSizer = NULL;
      g_pWidgetSizer = new CWidgetSizer(m_pParent, this);


    If anyone has any ideas/suggestions/improvements, please email me so I can improve this.


    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


    About the Author

    Andrew JM Hall
    Web Developer
    United Kingdom United Kingdom
    No Biography provided

    You may also be interested in...

    Comments and Discussions

    GeneralSetFocus() Pin
    Christian Graus14-May-01 17:59
    memberChristian Graus14-May-01 17:59 
    GeneralDoes not compile. Pin
    Julien14-May-01 17:54
    memberJulien14-May-01 17:54 
    GeneralSizing Bug & fix Pin
    KJ5-Feb-00 11:58
    sussKJ5-Feb-00 11:58 
    GeneralRe: Sizing Bug & fix Pin
    Paul Selormey11-Mar-00 18:19
    sussPaul Selormey11-Mar-00 18:19 
    Generalfor G-d sake don't use registry for that Pin
    Poor WIndows User3-Feb-00 19:07
    sussPoor WIndows User3-Feb-00 19:07 
    GeneralOther applications Pin
    KJ3-Feb-00 15:03
    sussKJ3-Feb-00 15:03 
    GeneralThis class already exists with MFC Pin
    Jerome3-Feb-00 3:28
    sussJerome3-Feb-00 3:28 
    GeneralUpdate to CSizer class Pin
    Andrew JM Hall2-Feb-00 23:49
    sussAndrew JM Hall2-Feb-00 23:49 
    GeneralPersistency will improve value Pin
    Mark2-Feb-00 22:11
    sussMark2-Feb-00 22:11 

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

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

    Permalink | Advertise | Privacy | Terms of Use | Mobile
    Web02 | 2.8.170924.2 | Last Updated 2 Feb 2000
    Article Copyright 2000 by Andrew JM Hall
    Everything else Copyright © CodeProject, 1999-2017
    Layout: fixed | fluid