Click here to Skip to main content
12,549,003 members (47,088 online)
Click here to Skip to main content
Add your own
alternative version


32 bookmarked

A general purpose ruler control

, 13 May 2002 CPOL
Rate this:
Please Sign up or sign in to vote.
This is a demostration of a general purpose ruler control in use. It consist of 2 apps and the ActiveX control itself. Control code is included.

Sample Image - ruler_control.jpg


After enduring enough abuse from some people on this site for not including the source in my last article, I guess they have succeeded. Here it is, with source, and all you codeheads have wanted. 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 wont be explaining anything here. The function names are pretty intuitive, so u 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 lower bound of the scale (left/top for horizontal ruler and vertical ruler respectively). The lower bound is a pixel location in client coordinate.

short nUpperLimit

This is the partner of the lower bound.

short nScalingFactor

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

BOOL bHorz

TRUE to create a horizontal ruler (default). FALSE for vertical.

BOOL  b3DLook

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

BOOL bAutoResize

This feature allows the ruler's scale to be resized at runtime without calling the setter methods. When on, resize handles appear at the side 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. nX and nY are the points in screen coordinates and should be converted into client coordinates before 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 demo for illustration.


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


About the Author

Web Developer
United States United States
biography? I am not that old yet.

You may also be interested in...


Comments and Discussions

GeneralASSERT failure Pin
BogMan18-Jun-02 17:34
memberBogMan18-Jun-02 17:34 
GeneralRe: ASSERT failure Pin
Edd18-Jun-02 18:44
memberEdd18-Jun-02 18:44 
Generalthanks Edd Pin
mloibl12-May-02 8:14
membermloibl12-May-02 8:14 
GeneralRe: thanks Edd Pin
Edd12-May-02 8:37
memberEdd12-May-02 8:37 
GeneralRe: thanks Edd Pin
machiav13-May-02 22:19
membermachiav13-May-02 22:19 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161021.1 | Last Updated 14 May 2002
Article Copyright 2002 by mystro_AKA_kokie
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid