A General Purpose Ruler Control

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


Comments

  • Very bad project

    Posted by leodubrovin on 03/16/2007 05:04am

    I didn't found this class in project. It's for author: why do you sending its. Its row solution. I'v destroyed time

    Reply
  • How to build that in C# ?

    Posted by Legacy on 09/10/2003 12:00am

    Originally posted by: wuselrob

    Hi,

    i have an MDI Project in C# .NET and want to build those Rulers. i found some samples on this site, but i didn't figure it out that i have these rulers in my dialogs :(
    isn't there a simple Class like "Button, TreeView...." that i can drag the ruler on my Application ?
    i use the Visual Studio .NET Enterprise Architect.
    Thanks for any help

    Wuselrob

    Reply
  • A General Purpose Ruler Control

    Posted by Legacy on 02/13/2003 12:00am

    Originally posted by: Jay

    I have the following questions about the ruler control
    1) How do you obtain the value of the tab indicators that are placed on the ruler at run-time?
    2) Can you adjust the edge constraints/border in code? I am referring to the left/top and right/bottom edges that can be resized at run-time.
    3) Can you scale the entire ruler so that the actual distance between each increment looks larger. The ScalingFactor seems only to adjust the distance between markers, but I need to actually increase the size of the ruler.

    Thanks in advance.

    Reply
  • cannot register ocx

    Posted by Legacy on 09/10/2002 12:00am

    Originally posted by: yusuf

    On my machine (NT Workstation, VS 6.0) i'm not able to register OCX. can anyone plz look into it. i get following error..
    Registering ActiveX Control...
    RegSvr32: LoadLibrary(".\Release\Bugfree_Ruler.ocx") failed.
    GetLastError returns 0x0000007e.

    Reply
  • great work but ocx will not register on NT machines, try this...

    Posted by Legacy on 09/10/2002 12:00am

    Originally posted by: yusuf

    I just found that the program uses MSIMG32.DLL which is shipped with win 98/2000 but not with NT machines, so that is why it doesnot register on NT machine.
    The program makes call to TransparentBlt which is defined in MSIMG32.DLL. I commented out all the TransparentBlt API call and the code runs fine... Also don't forget to remove link to msimg32.lib from project>settings>link

    Reply
  • You must compile the control code, so the control can be registered b4 use.

    Posted by Legacy on 06/19/2002 12:00am

    Originally posted by: Author

    VC6++ registers control automatically.

    Reply
  • I can't run the smaple

    Posted by Legacy on 06/13/2002 12:00am

    Originally posted by: Ehsan

    I compiled the sample but i could not run it.
    When i run this sample an Assertion pops about InvokeHelpers unsuccessful invocation and then just crash.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

  • Best-in-Class organizations execute on a strategy that supports the multi-channel nature of customer requests. These leading organizations do not just open up their service infrastructures to accommodate new channels, but also empower their teams to deliver an effective and consistent experience regardless of the channel selected by the customer. This document will highlight the key business capabilities that support a Best-in-Class customer engagement strategy.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds