dcsimg

A General Purpose Ruler Control

WEBINAR:
On-Demand

Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame


Environment:VC++6.0 and later

Introduction

The sample has no executable, so the source would have to be compiled; VC++6.0 automatically registers the control. Below is a list and description of the interfaces and how they may be utilized. The ruler itself consists of one CWnd derived class, CScale. The implementation is about 2000 lines of code, so I won't explain anything here. The function names are pretty intuitive, so you shouldn't have a problem running through them.

void SetRulerInfo( short nLowerLimit,
                   short nUpperLimit,
                   short nScalingFactor,
                   BOOL bHorz,
                   BOOL b3DLook,
                   BOOL AutoResize);

This is the only method I thought needed explaining; as you can see, the rest are just getter and setter methods, with the exception of the message senders -- which I'll get to soon. This method is used to set the properties of the ruler at run time in one atomic operation. The parameters are explained as follows:

short nLowerLimit

As the name suggests, sets the lowerbound of the scale (left/top for horizontal ruler and vertical ruler respectively). The lowerbound is a pixel location in the client coordinate.

short nUpperLimit

This is the partner of the lowerbound.

short nScalingFactor

The scaling factor determines what interval is used to draw major and minor tickers. In the sample, 5 is used. See the demo for an illustration.

BOOL bHorz

TRUE creates a horizontal ruler (default). FALSE creates a vertical ruler.

BOOL  b3DLook

TRUE for 3D borders (default). FALSE for flat. See the demo.

BOOL bAutoResize

This feature allows the ruler's scale to be resized at run time without calling the setter methods. When on, resize handles appear at the sides of the ruler. These are just setter and getter methods for the above properties.

void SetLowerLimit(short nLowerLimit);
void SetUpperLimit(short nUpperLimit);
void SetScalingFactor(short nScalingFactor);
void SetLook(BOOL bLook3D);
void SetAlignment(BOOL bHorz);
void SetAutoResize(BOOL bAutoResize);
short GetLowerLimit();
short GetUpperLimit();
short GetScalingFactor();
BOOL IsHorzAligned();
BOOL Has3DBorders();

Mouse Event Firers

void StartTracking( short nFlag,
                    OLE_XPOS_PIXELS nX, 
                    OLE_YPOS_PIXELS nY);
void StopTracking( short nFlags, 
                   OLE_XPOS_PIXELS nX,
                   OLE_YPOS_PIXELS nY);
void Track( short nFlags, 
            OLE_XPOS_PIXELS nX, 
            OLE_YPOS_PIXELS nY);

The above events are fired as a result of the Mouse down, Mouse up, and Mouse move events, respectively. The nX and nY are the points in the screen coordinates and should be converted into client coordinates before they are used. The nFlag is used to indicate which scaler is being used: 0 for regular arrow movement, 1 for left bar, and 2 for right bar. See the demo for an illustration.

Downloads

Download demo project - 96.0 Kb
Download source - 64.0 Kb


Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date