Click here to Skip to main content
Click here to Skip to main content

Size Grip Control

, 29 Aug 2006 CPOL
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

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)

Share

About the Author

g_drivas
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 Pinmemberbfawad7-Nov-06 11:45 
GeneralRe: I think you continue coding for fun. This app. is useless Pinmemberg_drivas22-Feb-07 23:15 
Generalvikram Pinmembervik2029-Aug-06 20:10 
QuestionWrong category? Pinmembertkdmaster29-Aug-06 14:36 

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
Web03 | 2.8.141220.1 | Last Updated 29 Aug 2006
Article Copyright 2006 by g_drivas
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid