Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

The Ultimate Toolbox Physical Unit Edit Controls

0.00/5 (No votes)
25 Aug 2007 1  
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 "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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here