SECCalculator Class

class SECCalculator: public CWnd

The SECCalculator class implements a calculator edit control capable of decimal arithmetic and other standard operations.

Defined in: SecCalc.h

Comments

See the sample CALC in the \SAMPLES\TOOLKIT\STANDARD\CONTROLS\CALC directory for a demonstration of this class.

Class Members

Creation/initialization

SECCalculator()

Constructs an SECCalculator object.

BOOL  Create(DWORD dwStyle, int x, int y, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL)

Creates a window for the calculator and attaches it to the

BOOL  CreateEx(DWORD dwExStyle, DWORD dwStyle, int x, int y, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL)

Creates a window with extended style attributes for the

Attributes

enum  SECCalcOp

List of calculator functions/buttons

Public Operations

int  HitTest(CPoint point) const

Returns the index of the button under the given point.

void  InvalidateBtn(int nIndex, BOOL bErase = FALSE)

Invalidates the button at the given index.

void  InvalidatePanel(BOOL bErase = FALSE)

Invalidates the LCD panel.

void  ResetCalc()

Resets the calculator back to a "zero" state.

void  SetValue(double val)

Set the current calculator value.

double  GetValue() const

Get the current calculator value.

void  SetDecimalPlaces(int nDP)

Set the maximum number of decimal places to be displayed.

int  GetDecimalPlaces() const

Get the maximum number of decimal places to be displayed.

Overridable

virtual BOOL  CreateBtns(CWnd* pParentWnd)

Creates the calculator’s buttons.

virtual BOOL  CreatePanel(CWnd* pParentWnd)

Creates the calculator’s LCD panel.

virtual BOOL  HandleEvent(SECCalcOp op)

Handles events related to the calculator’s operations (add,

virtual CString  LoadDecSeparator()

Override to change the decimal separator displayed.

Protected Operations

CSize  CalcLayout(DWORD dwStyle)

Lays out the calculator buttons.

void  SetDisplayString()

Formats the value into a displayable string.

void  PressBtn(int nIndex)

Presses the given button.

void  SizePanel()

Sizes the panel to the width of the calculator.

void  FormatNo(LPTSTR ptr, int nDP)

Formats the current number to the supplied number

virtual UINT  GetClassStyle() const

Returns the class style that this window "will" be registered with.

virtual void  Draw(CDC& dc)

Draws the calculator.

void  DrawPanel(CDC& dc)

Draws the panel.

BOOL  HandleDigit(SECCalcOp op)

Handles a digit input.

BOOL  HandleDecimalPoint(SECCalcOp op)

Handles a decimal point input.

BOOL  HandleBackspace(SECCalcOp op)

Handles a backspace input.

BOOL  HandleOperator(SECCalcOp op)

Handles an operation (add, subtract, etc.).

BOOL  HandleClear(SECCalcOp op)

Handles the 'Clear' operation.

BOOL  HandleClearError(SECCalcOp op)

Handles the 'Clear Error' operation.

TCHAR  GetFormatDecimal()

Returns the decimal character used by scanf, printf.

Protected data members

enum  StateFlags

State flags

TCHAR  m_cLeadByte

First input byte of multi-byte pair.

int  m_nState

The current state.

double  m_val

The currently displayed value.

SECCalcOp  m_lastOp

The last operation entered.

BOOL  m_bReplace

Next digit will replace current display.

int  m_nDP

Max number of decimal places.

int  m_nTotalDigits

Total number of displayable digits.

CRect  m_panelRect

The outer rectange of the panel.

CString  m_strDisplay

The current display string for the panel.

CString  m_strDecSep

The decimal separator.

CFont  m_btnFont

Font used for drawing buttons.

CFont  m_panelFont

Font used for drawing the panel.

HBITMAP  m_hEqualsBmp

Handle of bitmap used on equals button.

int  m_nBtnWidth

Width of a button (a column).

int  m_nBtnHeight

Height of a button.

int  m_nVIndent

Vertical Indent of button matrix.

int  m_nHIndent

Horizontal Indent of button matrix.

int  m_nVSpace

Space between button rows.

int  m_nHSpace

Space between button columns

int  m_nCapture

Index of button with capture