Compass Control | CodeGuru

Compass Control

Environment: Compiled using VC6.0 Sp3 and tested using Win95/98 WinNT4.0 and Win 2000 This article introduces a simple “cylinder” type of compass control based from CStatic. This will allow the control to be used within a dialog using the MFC Class Wizard Dialog or as a static control within a window. The compass project is […]

Written By
CodeGuru Staff
CodeGuru Staff
Feb 1, 2000
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Environment: Compiled using VC6.0 Sp3 and tested using Win95/98 WinNT4.0 and Win 2000

This article introduces a simple “cylinder” type of compass control based from
CStatic. This will allow the control to be used within a dialog using the MFC
Class Wizard Dialog or as a static control within a window.

The compass project is a simple dialog based project incorporating the compass
control. To illustrate the dynamics of the control, a Proportional, Integer,
Derivative Control (PID control) algorithm has been implemented to command the
compass control to a user specified heading. This gives the affect of a turning
compass.

The compass control is easy to use and has two member functions to control the compass.

Use

From a Dialog

Before you begin, make sure that the compass control class is registered in the
Class Wizard database.

  1. In a dialog, inset a picture control.
  2. Set the picture ID.
  3. Create a member variable using the Class Wizard Dialog. Make sure that the category is Control and that Variable Type is CCompass.

CCompass::SetPos

UINT SetPos( int nPos )

Return Value

Returns the previous heading.

Parameters

nPos

    Heading to set compass to. Any values are valid. If the position is less than 0 or greater than 360, then compass will reflect their reference angles.

Remarks

Use the SetPos method to set the compass heading. Normal compass headings range form 0 to 360 degrees. Other values greater than 360 or less than 0 degrees may be used. The compass control will reflect the reference angle.

CCompass::SetTicAlign

void SetTicAlign( WORD wAlign )

Parameters

wAlign

    Sets the tic alignment. Where:

    COMPASS_TIC_TOP – Aligns tics along top of compass

    COMPASS_TIC_BOTTOM – Aligns tics along the bottom of compass

    COMPASS_TIC_BOTH – Aligns tics on top and bottom of compass

Remarks

Use SetTicAlign to setup the alignment of degree tics on the compass.

Advertisement

Downloads

Download demo project – 41 Kb

Download source – 2 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.