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