Click here to Skip to main content
15,885,818 members
Articles / Desktop Programming / MFC
Article

The Ultimate Toolbox Physical Unit Edit Controls

Rate me:
Please Sign up or sign in to vote.
4.50/5 (3 votes)
25 Aug 2007CPOL2 min read 31.1K   473   15  
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:

C++
#include "OXPhysicalEditEx.h"


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)


Written By
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.
This is a Organisation

476 members

Comments and Discussions

 
-- There are no messages in this forum --