Click here to Skip to main content
Click here to Skip to main content
Go to top

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

    Description:

    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))
      		return;
      
      	delete g_pWidgetSizer;
      	g_pWidgetSizer = NULL;
      }
      
      g_pWidgetSizer = new CWidgetSizer(m_pParent, this);
      

    Request:

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

    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

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

    Comments and Discussions

     
    GeneralSetFocus() PinmemberChristian Graus14-May-01 17:59 
    GeneralDoes not compile. PinmemberJulien14-May-01 17:54 
    GeneralSizing Bug & fix PinsussKJ5-Feb-00 11:58 
    GeneralRe: Sizing Bug & fix PinsussPaul Selormey11-Mar-00 18:19 
    Generalfor G-d sake don't use registry for that PinsussPoor WIndows User3-Feb-00 19:07 
    GeneralOther applications PinsussKJ3-Feb-00 15:03 
    GeneralThis class already exists with MFC PinsussJerome3-Feb-00 3:28 
    GeneralUpdate to CSizer class PinsussAndrew JM Hall2-Feb-00 23:49 
    GeneralPersistency will improve value PinsussMark2-Feb-00 22:11 

    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 | Mobile
    Web04 | 2.8.140916.1 | Last Updated 2 Feb 2000
    Article Copyright 2000 by Andrew JM Hall
    Everything else Copyright © CodeProject, 1999-2014
    Terms of Service
    Layout: fixed | fluid