★ wanayoo — archive 1999 http://codeguru.developer.com/controls/LatLong.shtmlNouvelle recherche | Portail wanayoo
EarthWeb
Developer.com Click Here!
Click Here!
Find:
 

EXPERT SEARCH
SEARCH THE IT WEB -----
Site
windows 2000
visual c++
java
visual basic
javascripts
recommend it
 
Contest
mfc codeguru
submission guidelines
 
Book
thinking in c++
stl programmer's guide
reviews
 
Interact
forums
newsgroups
guest book
jobs
jokes
open faq
what's new
 
Other
about
links
newsletters
privacy
tools
 

-----
Visual C++ by E-mail:

Get the weekly e-mail highlights on
Visual C++!
-----



EarthWeb Sites:
IT Management
Networking & Telecommunications
IT Jobs
Software Development
Hardware & Systems
Commerce
Community

EarthWeb Worldwide

   

Latitude/Longitude Class


This article was contributed by George Chastain.

In my line of work, my colleagues and I often need to add controls to a user interface to allow the user to enter geographic latitudes and longitudes.

The need to provide an interface that allows for the consistently correct entry of coordinates is usually great.

I finally decided to sit down and create classes to provide good usuable controls for entering latitudes and longitudes. These class are CGCLatitudeCtrl and CGCLongitudeCtrl.

The demo program supplied with this article illustrates the capabilities of these classes.

Sample Image

The classes are derived from a class, CGCColorEdit, I created for edit boxes that provides different color and font capabilities. The CGCColorEdit class is similar to other classes found elsewhere on this site so I will not dwell on its design.

The CGCLatitudeCtrl and CGCLongitudeCtrl classes are very simple to use. Each control divides its display into four different fields; 1) a hemisphere field, 2) a degrees field, 3) a minutes field and 4) a seconds field. The user can navigate between fields within the control using the left and right arrow keys. Navigation to the right may also be achieved using the space bar. When the use navigates to a particular field within the control, that field is selected and highlighted. Actions taken by the user will affect that field.

The up and down arrow keys may be used to increment or decrement, respectively, the currently selected field. In addition, the user may enter values for that field directly using the number keys on the keyboard.

The user may also select a specific field within the control by clicking on it with the left mouse button. The user can zero out the currently-selected field by pressing the backspace key.

A context menu is even provided. When the user clicks over the control that has focus using the right mouse button, a context menu is displayed. It allows the user to zero the entire control setting or to zero out only the currently-selected field.

There are even "hot keys" defined for the control.

When the control has focus, the user may jump to the hemisphere field by pressing the "h" key. Similarly, the user may jump to the degrees, minutes or seconds field by pressing the "d", "m" or "x" keys, respectively.

There are three methods defined for each class in addition to those inherited from CGCColorEdit. These are: The method Set() allows the application to initialize the control to any setting valid for that type of control (latitude or longitude).


BOOL Set(const HEMISPHERE_TYPE hsph,   
         const UINT Degrees,           
         const UINT Minutes,           
         const float Seconds);         
The method Get() allows the application to obtain the current setting, usually from within an EN_CHANGE handler.

Article text goes here

void Get(HEMISPHERE_TYPE& hsph, UINT& Degrees, UINT& Minutes, float& Seconds) const; The method GetDecimalDegrees() allows the application to obtain the current setting in decimal degrees.

double GetDecimalDegrees()const;
Here are the steps to place a latitude control and a longitude control on your user interface:
  • 1. Add CGCColorEdit class to your project.
  • 2. Add CGCLatitudeCtrl class to your project.
  • 3. Add CGCLongitudeCtrl class to your project.
  • 4. Place an edit box using the Resource Editor to be used for your latitude control.
  • 5. Place an edit box using the Resource Editor to be used for your longitude control.
  • 4. Using ClassWizard, create a member variable of type CGCLatitudeCtrl for one of the new edit boxes.
  • 5. Use ClassWizard to create a member variable of type CGCLongitudeCtrl for the other new edit box.
  • 6. Add an EN_CHANGE handler for each of the new edit boxes to your parent window to handle when the controls change as you would any other control class.
  • I hope that these will prove useful to someone on future projects.

    Downloads

    Download demo application - 158 Kb
    Download demo source - 94 Kb

    History

    Date Posted: December 18, 1999
    Date Updated: December 28, 1999

    Comments:

    Add Comment

       

    Give them a visit Click Here!

    Click Here!

    INSTANT EXPERTS!
    Savvy IT Pros report on SupportSource. Take a look inside the largest vault of multi-vendor computing specs ever assembled. Click here for an In-depth Report,.

    For tons of Windows technology resources, check out the Windows Programming directory.

    Searching the Web for tech topics just got better with
    TechCrawler where all results come only from popular technical sites.

    WINNER!!!
    Congratulations to James Hole, of New Mexico! The grand prize winner of EarthWeb's Flatten the Obstacles Sweepstakes and now a proud Hummer(R) owner.

    Give them a visit Click Here!

    Click Here!

    Click Here!

    Click Here!

    Home About Us Search Subscribe Advertising Info Contact Us FAQs
    Use of this site is subject to certain Terms & Conditions.
    Earthweb's statement regarding our users' right to privacy.
    Copyright ©1996-2000 EarthWeb Inc.. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited.