Click here to Skip to main content
15,886,864 members
Articles / Desktop Programming / MFC

Size Grip Control

Rate me:
Please Sign up or sign in to vote.
2.31/5 (5 votes)
29 Aug 2006CPOL2 min read 35.1K   261   9   4
A very easy way of resizing CWnd based objects.

Sample Image - Size_Grip_Control.jpg

Introduction

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

Warnings

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.

Future

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

License

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


Written By
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.

Comments and Discussions

 
GeneralI think you continue coding for fun. This app. is useless Pin
bfawad7-Nov-06 10:45
bfawad7-Nov-06 10:45 
GeneralRe: I think you continue coding for fun. This app. is useless Pin
g-drivas22-Feb-07 22:15
g-drivas22-Feb-07 22:15 
Generalvikram Pin
vik2029-Aug-06 19:10
vik2029-Aug-06 19:10 
QuestionWrong category? Pin
tkdmaster29-Aug-06 13:36
tkdmaster29-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.