⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spinedit.h

📁 一个自定义的SPIN控件
💻 H
字号:
#if !defined(AFX_SpinEdit_H__47B852C0_B62E_11D4_90EA_FC4F9026BF42__INCLUDED_)
#define AFX_SpinEdit_H__47B852C0_B62E_11D4_90EA_FC4F9026BF42__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// SpinEdit.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// SpinEdit.h : header file
//
// SpinEdit Control header file
//
// This code is free for personal and commercial use.
// 
// Written by Huang Chaoyi (ahaa007@263.net)
// Please use and enjoy. Please let me know if you find bugs. 
//
// There are some code blocks copied from Chris Maunder's CGridCtrl class. 
// Thank you, Chris Maunder.
/////////////////////////////////////////////////////////////////////////////

#define SPINEDITCTRL_CLASSNAME _T("SPINEDITCTRL")
#define IsCTRLpressed()  ( (GetKeyState(VK_CONTROL) & (1 << (sizeof(SHORT)*8-1))) != 0 )

// default arrow button width
#define ARROWBTN_WIDTH		20

typedef enum enValueType{ SE_INT=0, 
						  SE_FLOAT,
						  SE_DOUBLE,
						  SE_BUTT}VALUE_TYPE;

// structure for notify message from seedit, ie inplaced edit
typedef struct tagSENotifyMsg { 
    NMHDR   hdr; 
    CString szText;
	LPARAM	lParam;
	CWnd*	pNewFocusWnd;
} SE_NOTIFYMSG;

#define SEN_ENDLABELEDIT		WM_USER+2000
#define SEN_LOWERBTNDOWN		SEN_ENDLABELEDIT+1
#define SEN_LOWERBTNUP			SEN_ENDLABELEDIT+2
#define SEN_UPPERBTNDOWN		SEN_ENDLABELEDIT+3
#define SEN_UPPERBTNUP			SEN_ENDLABELEDIT+4

class CSEEdit;
class CSpinEdit;
void AFXAPI DDX_SpinEditControl(CDataExchange* pDX, int nIDC, CSpinEdit& rControl);

/////////////////////////////////////////////////////////////////////////////
// CSpinEdit window

class CSpinEdit : public CWnd
{
	DECLARE_DYNCREATE(CSpinEdit)

// Construction
public:
	CSpinEdit();
	BOOL Create( CWnd* pParentWnd, CRect rect, UINT nID, DWORD dwStyle );
	BOOL SubclassWindow(HWND hWnd);

//method
public:
	virtual void  OnDraw(CDC* pDC);

protected:
	BOOL RegisterWindowClass();
	
	CString GetShowText( BOOL bNeedExtraText=TRUE );
	BOOL DrawText( CDC* pDC);
	BOOL DrawUpperBtn( CDC* pDC);
	BOOL DrawLowerBtn( CDC* pDC);
	BOOL DrawFrame( CDC* pDC );
	BOOL ShowEdit( int nChar );

	BOOL RedrawFrame();
	BOOL RedrawText();
	BOOL RedrawUpperBtn();
	BOOL RedrawLowerBtn();

	BOOL GetTextRect( CRect& rect );
	BOOL GetUpperBtnRect( CRect& rect );
	BOOL GetLowerBtnRect( CRect& rect );

	BOOL AddValue( DWORD dwStepNum = 1 );
	BOOL SubValue( DWORD dwStepNum = 1 );

	double DoubleModValue( const double value, const double step, const BYTE bPointPos );

// Attributes
public:
	BOOL SetParams( BYTE       bType,
		            BYTE	   bPointPos,
					double	   dbCurValue,
					double     dbBase,
					double     dbLower,
					double     dbUpper,
					double     dbStep,
					BOOL       bNeedExtraText,
					LPCTSTR    lpExtraText );


	BOOL SetValueType( const BYTE bType = SE_INT, const BYTE bPointPos = 0 );
	BYTE GetValueType( void );
	BYTE GetValuePos( void );

	BOOL SetCurValue( double dbValue );
	double GetCurValue( void );

	BOOL SetBase( double dbBase = 0 );
	double GetBase( void );

	BOOL SetRange( double dbLower = 0, double dbUpper = 100 );
	void GetRange( double &dbLower, double &dbUpper );

	BOOL SetStep( double dbStep = 1 );
	double GetStep( void );

	BOOL SetExtraText( LPCTSTR lpStr );
	CString GetExtraText( void );

	void SetNeedExtraText( BOOL bNeed=TRUE );
	BOOL GetNeedExtraText( void );

	CSEEdit* GetEditCtrl( void );

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CSpinEdit)
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CSpinEdit();

	// Generated message map functions
protected:
	//{{AFX_MSG(CSpinEdit)
	afx_msg void OnKillFocus(CWnd* pNewWnd);
	afx_msg void OnPaint();
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
    afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);    
	afx_msg void OnCaptureChanged(CWnd *pWnd);
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg UINT OnGetDlgCode();
	afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);	
	afx_msg void OnSetFocus(CWnd* pOldWnd);	
	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
	afx_msg void OnEndInplaceEdit(NMHDR* pNMHDR, LRESULT* pResult);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

protected:
	double	m_dbValue;
	double	m_dbBase;
	double	m_dbLower;
	double	m_dbUpper;
	double	m_dbStep;
	double	m_dbOldValue;

	int		m_nStepsPerWheelNotch;
	int		m_nTimerID;
	int		m_nTimerInterval;

	BYTE	m_bValueType;
	CString	m_szExtraText;
	BYTE	m_bPointPos;
	
	BOOL	m_bEditShow;
	BOOL	m_bLowerBtnPushed;
	BOOL	m_bUpperBtnPushed;
	BOOL	m_bNeedExtraText;	
	
	CSEEdit*			m_pEdit;	
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_SpinEdit_H__47B852C0_B62E_11D4_90EA_FC4F9026BF42__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -