Click here to Skip to main content
Click here to Skip to main content

The Ultimate Toolbox Physical Unit Edit Controls

, 25 Aug 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
The Ultimate Toolbox contains several predefined CEdit derived controls for physical unit input and conversion

Visit the Ultimate Toolbox main page for an overview and configuration guide to the Ultimate Toolbox library.

Source code and project files for this sample can be found in the samples\gui\PhysicalTest directory of the sample projects download.

Overview

Screenshot - PhysicalEdit.jpg

The COXTimeEdit, COXAngleEdit, COXLengthEdit, and COXTempEdit classes are all derived from COXPhysicalEdit which is derived from CEdit.

Have a look at the Page Setup dialog boxes in Windows 95 and compare them to the margins setup property page in the Microsoft Office applications (or others). The fundamental difference is that in the Office applications, you can enter the values for margins as a physical value (numerical value and a physical unit) whereas in the standard dialog, you cannot supply a unit.

The COXTimeEdit, COXAngelEdit, COXLengthEdit, and COXTempEdit classes allow you to implement the same type of controls in your own applications: for time (duration), angle, length, and temperature. No need to define a fixed unit at desigdn time for your dialog boxes or property pages any more.

Features

  • Adds physical units to numerical input in edit controls.
  • Built-in functions for conversions between physical units.
  • Functions for setting and retrieving physical values in desired units.
  • No need for SetWindowText() and GetWindowText() any more.
  • Extended COXPhysicalEdit base class which can be easily derived to implement other physical properties (area, speed etc.).

Usage

You can attach a COXPhsicalEdit derived control to an existing edit control by subclassing the latter.

As per usual, place a standard edit control on the dialog using the dialog editor. Invoke the Class Wizard and select the Member Variables page. Add a member variable for the ID of the edit control, selecting a CEdit control as the type.

Next, open the header file for the dialog. Include the OXPhysicalEditEx.h header. In the AFX_DATA section for the dialog you will see the declaration for the edit control as a CEdit. Change this to the control you wish to use ( OXPhysicalEditEx.h contains the class declarations COXTimeEdit, COXAngelEdit, COXLengthEdit, and COXTempEdit.)

Don't forget to include the OXPhysicalEditEx.cpp file in your project!

The sample demonstrates the use of four COXPhysicalEdit derived classes, subclassing them in the dialog:

#include <span class="code-string">"OXPhysicalEditEx.h"
</span>


class CPhysicalTestDlg : public CDialog
{
// Construction

public:
    CPhysicalTestDlg(CWnd* pParent = NULL);    // standard constructor


// Dialog Data

    //{{AFX_DATA(CPhysicalTestDlg)

    enum { IDD = IDD_PHYSICALTEST_DIALOG };
    ...
    COXTempEdit    m_wndTemp;
    COXTimeEdit    m_wndTime;
    COXLengthEdit    m_wndLength;
    COXAngleEdit    m_wndAngle;
    ...

The compiled HTML help documentation contains complete class references for COXPhysicalEdit,COXTimeEdit,COXAngleEdit,COXLengthEdit,and COXTempEdit, as well as the extended CEdit derived classes COXEdit, COXNumericEdit, COXCurrencyEdit, COXMaskedEdit, and the templated COXDropEdit.

History

Initial CodeProject release August 2007.

License

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

Share

About the Author

The Ultimate Toolbox
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created TheUltimateToolbox.com, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.
 
Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
Group type: Organisation

394 members


Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141216.1 | Last Updated 25 Aug 2007
Article Copyright 2007 by The Ultimate Toolbox
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid