Click here to Skip to main content
13,195,379 members (67,014 online)
Click here to Skip to main content
Add your own
alternative version


9 bookmarked
Posted 29 Aug 2006

Size Grip Control

, 29 Aug 2006
Rate this:
Please Sign up or sign in to vote.
A very easy way of resizing CWnd based objects.

Sample Image - Size_Grip_Control.jpg


First of all, let me say that as an original MFC fan, I am also a great fan of this site. For a very long time, I have been looking for a chance to submit an article. I have developed very interested things, but the majority of those code are specialized to very specific aspects.

The reason

Recently, I was faced with the following issue. How could I resize a control bar or even a singe child control in a visual way (by moving the mouse)? Indeed, there are some great controls here in CodeProject, but they have a lot of code and they are oriented to specific controls.

All of us that use MFC know the peculiarities of CWnd based controls. I have, many times, been stuck for hours or days, trying to figure out how a control behaves. After all these years, I concluded that the most stable control is CWnd, and whenever possible, I skip classic controls and make my own directly from CWnd.

The concept

The files that contain HCSizeGrip are:

  • HCSizeGrip.h
  • HCSizeGrip.cpp

HCSizeGrip is derived directly from the CWnd class. It can be created very simply (by calling the CWnd::Create function), and it can be handled as a classical CWnd object. It uses a hook to capture mouse events.

When you hover the mouse above a HCSizeGrip object, you will see the mouse pointer change (to a sizing arrow). If you press the left button and start dragging the parent CWnd based control of HCSizeGrip, it will start resizing.

There are four orientations of resizing: LEFT, RIGHT, TOP, BOTTOM. The default is RIGHT. If you want to change the resize orientation, use:

BOOL SetResizeOrientation(TResizeOrientation val)

The functions BOOL SetMaxScale(float newVal) and BOOL SetMinScale(float newVal) set the maximum and minimum resize (0 up to 1).


I had no time to test this class extensively, but I am sure that t does not work correctly with top level windows like CDialog or CFrameWnd. But I think that it works fine with CDialogBar controls.


In the future, I want to do (when I have the time) virtual resize like all modern task bars have (not actual resize before the mouse movement is complete).


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
Greece Greece
My name is George Drivas.
The programming was for me the main job. Now I am coding mostly for fun. My main language is C\C++ and I am using the most common developments tools. I am interesting mostly for the MFC development. This site is (in my opinion) the best for MFC development. I hope that I will be able to contribute in this community.

You may also be interested in...


Comments and Discussions

GeneralI think you continue coding for fun. This app. is useless Pin
bfawad7-Nov-06 10:45
memberbfawad7-Nov-06 10:45 
GeneralRe: I think you continue coding for fun. This app. is useless Pin
g_drivas22-Feb-07 22:15
memberg_drivas22-Feb-07 22:15 
Generalvikram Pin
vik2029-Aug-06 19:10
membervik2029-Aug-06 19:10 
QuestionWrong category? Pin
tkdmaster29-Aug-06 13:36
membertkdmaster29-Aug-06 13:36 

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
Web01 | 2.8.171019.1 | Last Updated 29 Aug 2006
Article Copyright 2006 by g-drivas
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid