www.pudn.com > NumericEdit_Demo.rar > NumericEdit.h
/*
CNumericEdit - A clone of the spinedit control used in Jasc's Paint Shop Pro
Contact : jg@jgsoftware.com
Use the code for anything, just submit suggestions and bug fixes to above address.
4/13/2004 - 1.0 Initial release
4/20/2004 - 1.02 Bug fixes and some enhancements
Fixed bug where the edit would only accept hex digits. Also now allow negative sign "-" to be entered
Added NES_METER style to make the small bar under the edit field optional
Control will now reconfigure itself when changing style bits
Fixed max value bug. The full range is now accesible with the popup
Added NES_LIVEUPDATE style. This style allows the control to notify it's parent during value tracking. Without this style, the parent is updated only at the end of tracking
Demo has been updated to show the new features
Added DDX_NumericEdit() function for DDX support
Now using the active window caption color for the bar colors
Changed hardcoded custom messages to use windows registered messages so as not to cause any conflict with other custom messages
*/
#pragma once
// DDX_NumericEdit to use for dialog data exchange
void AFXAPI DDX_NumericEdit(CDataExchange* pDX, int nIDC, int& value);
// CMyEdit
class CMyEdit : public CEdit
{
DECLARE_DYNAMIC(CMyEdit)
private:
BOOL m_fOverFlow;
CBrush m_brError;
public:
CMyEdit()
{
m_fOverFlow = FALSE;
m_brError.CreateSolidBrush(RGB(255,128,128));
}
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnEnChange();
afx_msg HBRUSH CtlColor(CDC* /*pDC*/, UINT /*nCtlColor*/);
};
// CMyButton
class CMyButton : public CButton
{
DECLARE_DYNAMIC(CMyButton)
public:
CMyButton() {}
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg LRESULT OnBnSetStyle(WPARAM wParam,LPARAM lParam);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
};
// CMyTrackPopup
class CMyTrackPopup : public CWnd
{
DECLARE_DYNAMIC(CMyTrackPopup)
private:
int m_nMin;
int m_nMax;
int m_nValue;
CWnd* m_pNotify;
double m_dPixelValue;
public:
CMyTrackPopup() {}
BOOL Create(int x,int y,int nMin,int nMax,int nValue,CWnd* pParent);
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnPaint();
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnSize(UINT nType, int cx, int cy);
};
// CNumericEdit
// Messages
static const UINT NEM_GETPOS = ::RegisterWindowMessage(_T("NEM_GETPOS-{C513E47E-D128-4513-8460-B6C944A49131}"));
static const UINT NEM_SETPOS = ::RegisterWindowMessage(_T("NEM_SETPOS-{D3BF042E-8E1E-403f-8644-CCCB8FDBD80C}"));
static const UINT NEM_GETRANGE = ::RegisterWindowMessage(_T("NEM_GETRANGE-{5474EEB4-6BDC-4a5d-9CCE-7FC29F2BA06E}"));
static const UINT NEM_SETRANGE = ::RegisterWindowMessage(_T("NEM_SETRANGE-{D837739D-9588-4747-AB2C-12BBFEF57138}"));
static const UINT NEM_GETREADONLY = ::RegisterWindowMessage(_T("NEM_GETREADONLY-{7399E120-E305-48e0-9CF3-755483B79F87}"));
static const UINT NEM_SETREADONLY = ::RegisterWindowMessage(_T("NEM_SETREADONLY-{12B8313F-44D6-4680-A208-19B61186BEC9}"));
// Notifications
static const UINT NEN_CHANGED = ::RegisterWindowMessage(_T("NEN_CHANGED-{CD9B6FDC-F420-4956-91B0-AB882EC15A89}"));
// Styles
#define NES_SPIN 0x0001
#define NES_POPUP 0x0002
#define NES_METER 0x0004
#define NES_LIVEUPDATE 0x0008
class CNumericEdit : public CWnd
{
DECLARE_DYNAMIC(CNumericEdit)
public:
CNumericEdit();
private:
int m_nMin;
int m_nMax;
int m_nValue;
BOOL m_fCaptured;
CRect m_rcBar;
double m_dPixelValue;
BOOL m_fTracking;
void ResizeChildren(int cx,int cy);
protected:
DECLARE_MESSAGE_MAP()
CMyButton m_wndButton;
CSpinButtonCtrl m_wndSpinButton;
CMyEdit m_wndEdit;
public:
int GetValue();
void SetValue(int nValue);
void GetRange(int& nMin,int& nMax);
void SetRange(int nMin,int nMax);
BOOL GetReadOnly();
void SetReadOnly(BOOL fReadOnly);
afx_msg void OnPaint();
BOOL Create(DWORD dwStyle,const CRect& rcRect,CWnd* pParent,UINT nID);
public:
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnSetFocus(CWnd* pOldWnd);
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnStyleChanged(int nWhich, LPSTYLESTRUCT lpStyleStruct);
afx_msg LRESULT OnGetPos(WPARAM,LPARAM);
afx_msg LRESULT OnSetPos(WPARAM wParam,LPARAM lParam);
afx_msg LRESULT OnGetRange(WPARAM wParam,LPARAM lParam);
afx_msg LRESULT OnSetRange(WPARAM wParam,LPARAM lParam);
afx_msg LRESULT OnGetReadOnly(WPARAM,LPARAM);
afx_msg LRESULT OnSetReadOnly(WPARAM wParam,LPARAM lParam);
afx_msg LRESULT OnShowPopup(WPARAM wParam,LPARAM lParam);
afx_msg LRESULT OnPopupStateChange(WPARAM wParam,LPARAM lParam);
};