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

📄 buttonex.h

📁 通过手机数据线连接手机
💻 H
字号:
#if !defined(AFX_BTNTEXTSAMPLE_H__A622CD42_22FB_11D2_BC00_FD41D317EE64__INCLUDED_)
#define AFX_BTNTEXTSAMPLE_H__A622CD42_22FB_11D2_BC00_FD41D317EE64__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// buttonEx.h : header file
//

#include "jwfcx.h"

#include "fontEx.h"

/////////////////////////////////////////////////////////////////////////////
// CBtnTextSample window
//本类用于在按钮上显示一个文本字串,此文本可指定字体

class JWX_EXT_CLASS CBtnTextSample : public CButton
{
// Construction
public:
	CBtnTextSample();

// Attributes
public:
	void SetPushLike( BOOL pushLike )
	{
		m_pushLike = pushLike;
	};
	void SetBGColor( COLORREF color )
	{
		m_bgColor = color;
		Invalidate();
	};
	COLORREF GetBGColor()
	{
		return m_bgColor;
	};
	void SetFGColor( COLORREF color )
	{
		m_fgColor = color;
		Invalidate();
	};
	COLORREF GetFGColor()
	{
		return m_fgColor;
	};

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CBtnTextSample)
	public:
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
	//}}AFX_VIRTUAL

// Implementation
public:
UINT m_format;
CFontEx m_font;
CString m_sampleText;

	virtual ~CBtnTextSample();

	// Generated message map functions
protected:
	//{{AFX_MSG(CBtnTextSample)
		// NOTE - the ClassWizard will add and remove member functions here.
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()

COLORREF m_bgColor;
COLORREF m_fgColor;
BOOL m_pushLike;
};

/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// CBtnColor window
//本类可用于在按钮上显示颜色
//使用SetColor()来给m_color赋值可指定颜色
//SetPushLike( TRUE )可将此按钮设为可按下的铵钮,否则为平面

#define BTNPUSH_NONE	0
#define BTNPUSH_STD		1
#define BTNPUSH_CHECK	2

class JWX_EXT_CLASS CBtnColor : public CButton
{
// Construction
public:
	CBtnColor();

// Attributes
public:
	void SetPushStyle( int style )
	{
		m_pushStyle = style;
	};
	void Check( BOOL push );
	int GetCheckStatus();

	void SetColor( COLORREF color )
	{
		m_color = color;
		Invalidate();
	};
	COLORREF GetColor()
	{
		return m_color;
	};

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CBtnColor)
	public:
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
	virtual BOOL Create( const RECT& rect, CWnd* pParentWnd, UINT nID );
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CBtnColor();

	// Generated message map functions
protected:
	//{{AFX_MSG(CBtnColor)
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()

COLORREF m_color;
BOOL m_pushStyle;
BOOL m_pushed;
};


/////////////////////////////////////////////////////////////////////////////
// CBtnImage Public CButton
// 位图按钮

class JWX_EXT_CLASS CBtnImage : public CButton
{
// Construction
public:
	CBtnImage();
	virtual ~CBtnImage();

public:
	//设置资源ID
	// if imgID == 0,则关闭此状态位图
	BOOL SetImgIDNormal( UINT imgID );
	BOOL SetImgIDDown( UINT imgID );
	BOOL SetImgIDFocus( UINT imgID );
	BOOL SetImgIDDisable( UINT imgID );
	BOOL SetImgIDCheck( UINT imgID );
	BOOL SetImgIDHaveMouse( UINT imgID );

	//设置BMP文件名
	// if imgName == NULL,则关闭此状态位图
	BOOL SetImgNameNormal( UINT imgName );
	BOOL SetImgNameDown( UINT imgName );
	BOOL SetImgNameFocus( UINT imgName );
	BOOL SetImgNameDisable( UINT imgName );
	BOOL SetImgNameCheck( UINT imgName );
	BOOL SetImgNameHaveMouse( UINT imgName );

	void EnableStretch( BOOL enable = TRUE )
	{
		m_enableStretch = enable;
	};
	//允许/禁止在鼠标移动设置聚焦特性
	void EnableFocusOnMouseMove( BOOL enable = TRUE )
	{
		m_focusOnMouseMove = enable;
	};


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CBtnImage)
	public:
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
	//}}AFX_VIRTUAL

	// Generated message map functions
protected:
	//{{AFX_MSG(CBtnImage)
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()

CBitmap m_bitmapNormal;
CBitmap m_bitmapDown;
CBitmap m_bitmapFocus;
CBitmap m_bitmapDisable;
CBitmap m_bitmapCheck;
CBitmap m_bitmapHaveMouse;

BOOL m_enableStretch;	//允许缩放位图,如果不允许,那么控件将被改变大小
BOOL m_focusOnMouseMove;	//标识是否响应鼠标在其上通过的动作
BOOL m_haveMouse;	//标识鼠标是否在按钮上

BOOL m_isChecked;
BOOL m_isPushed;
};


/////////////////////////////////////////////////////////////////////////////
// CBtnEx的用法:
// 生成一个CBtnEx对象,对要做成园按钮的控件做SubclassWindow即可

class JWX_EXT_CLASS CBtnEx : public CButton
{
public:

typedef enum
{
	patternRect,
	patternRound,
	patternOther
} EBtnPat;
	
	CBtnEx();

	//设置按钮形状,并以此形状设置窗口区域,若用patternOther,则此前m_rgn应建立
	void SetPattern( EBtnPat pattern );

	//设置画按钮用的图像,bmp将按CX等分
	virtual BOOL SetFaceIMG( UINT bmpID, int cx, COLORREF mask );
	virtual BOOL SetFaceIMG( CBitmap * pBMP, int cx, COLORREF mask );

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CBtnEx)
	public:
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
	protected:
	virtual void PreSubclassWindow();
	virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
	//}}AFX_VIRTUAL

// Implementation
public:
	//在按钮的左下角弹出指定的菜单,subMenuID指定要弹出的子菜单
	void PopupMenu( UINT menuID, int subMenuID=0 );
	HCURSOR m_hCursor;
	virtual ~CBtnEx();

	BOOL   m_bDrawDashedFocusCircle;

	//标识按钮是否透明,应在subclass之前设置,如果对话框模板中已设透明,此值可将在preSubclass中自动设置
	BOOL m_bgTransparent;
	//文本式样,TRUE时为立体,否则平面
	BOOL m_3DText;

	//边框厚度,缺省为2,可以是1
	int m_nBorder;														// width of the border in pixels for 3D highlight
	
	//画立体框用的颜色,在构造函数中调用系统色来生成,此后可由用户指定
	COLORREF m_clr3dLight;
	COLORREF m_clr3dShadow;
	COLORREF m_clr3dHighLight;
	COLORREF m_clr3dDKShadow;

//按钮表面色彩
COLORREF m_clrFaceN, m_clrFaceS, m_clrFaceH, m_clrFaceD;					// background colors for button states: normal, selected, hover, disabled

//使用位图来画按钮,其中的图像按顺序为:normal, selected, disabled, hover
//可以只有normal一个图像
CImageList m_faceIMG;

//判断及更新的按钮用的区域,坐标为本按钮的客户区坐标
//若此值被外部代码改动,应调用SetPattern()来更新窗口区域
CRgn m_rgn;

//允许鼠标经过时点亮按钮
BOOL m_enableHover;
//允许平面按钮
BOOL m_enableFlat;

	// Generated message map functions
protected:
// prototypes
// Calculate colour for a point at the given angle by performing a linear
// interpolation between the colours crBright and crDark based on the cosine
// of the angle between the light source and the point.
//
// Angles are measured from the +ve x-axis (i.e. (1,0) = 0 degrees, (0,1) = 90 degrees )
// But remember: +y points down!
COLORREF GetColour(double dAngle, COLORREF crBright, COLORREF crDark);
void DrawCircle(CDC* pDC, CPoint p, LONG lRadius, COLORREF crColour, BOOL bDashed = FALSE);
void DrawCircleLeft(CDC* pDC, CPoint p, LONG lRadius, COLORREF crBright, COLORREF crDark);
void DrawCircleRight(CDC* pDC, CPoint p, LONG lRadius, COLORREF crBright, COLORREF crDark);

	//在DrawItem中调用此函数通知父窗口重画
	//如果返回FALSE,接下来画自己
	//如果返回TRUE,则什么也不做
	BOOL NotifyParentRepaint( LPRECT rect );

	void CheckHover(CPoint point);
	// determines if point is inside the button region
	BOOL HitTest(CPoint point);

	//{{AFX_MSG(CBtnEx)
	afx_msg void OnSize( UINT nType, int cx, int cy );
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()

	virtual void DrawItemFace( CDC * pDC, UINT state, CRect & rect, int & nRadius );
	virtual void DrawItemBorder( CDC * pDC, UINT state, CRect & rect, int & nRadius );
	virtual void DrawItemBG(CDC * pDC, UINT state, CRect & rect, int & nRadius );

	virtual void DrawFaceIMG(CDC * pDC, UINT state, CRect & rect, int & nRadius );
	virtual void DrawFaceText(CDC * pDC, UINT state, CRect & rect, int & nRadius );

	virtual void DrawBorderRound(CDC * pDC, UINT state, CRect & rect, int & nRadius );
	virtual void DrawBorderRect(CDC * pDC, UINT state, CRect & rect, int & nRadius );

	//这是用于画特殊边框的函数,由于类重载实现
	virtual void DrawBorderOther(CDC * pDC, UINT state, CRect & rect, int & nRadius );

//用于锁定父窗口更新一个变量,见NotifyParentRepaint()中的说明
BOOL m_disParentRepaint;

//按钮的式样,如矩形、园形等,由patternXXXX定义
EBtnPat m_pattern;

CRgn   m_wndRgn;//设置区域后,系统要求保持此区域,这是屏幕坐标
CPoint m_ptCentre;
CPoint m_ptLeft;
CPoint m_ptRight;
int    m_nRadius;
BOOL   m_bStretch;

	BOOL m_bMouseDown;		// indicated that mouse is pressed down
	BOOL m_bHover;			// indicates if mouse is over the button
	BOOL m_bCapture;		// indicates that mouse is captured in the buton
};

class JWX_EXT_CLASS CBtnRgn : public CBtnEx
{
public:
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CBtnRgn)
	//}}AFX_VIRTUAL

public:

//如果使用自定义BMP,且此值为真,则加画3D边框
BOOL m_bmp3DBorder;

protected:
	//{{AFX_MSG(CBtnRgn)
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()

	// region pixel work - unused
	void RgnPixelWork(CDC * pDC, CRgn * pRgn);
#define MBORDER_FLAT 0
#define MBORDER_SUNKEN 1
#define MBORDER_RISING 2
	// frames region to show 3D shadows
	void FrameRgn3D(HDC hDC, const HRGN hRgn, int mBorder);

	//这是用于画特殊边框的函数,由子类重载实现
	virtual void DrawBorderOther(CDC * pDC, UINT state, CRect & rect, int & nRadius );

	//复制BMP,该死的MS,连复制BMP的功能都没有!
	void CopyBitmap( CBitmap * bmpD, CBitmap * bmpS, long xOff = 0, long yOff = 0 );

public:
	CBtnRgn();
	virtual ~CBtnRgn();
	// complex parameters constructor
	// lpszCaption - window caption
	// dwStyle - window styles
	// point - position of the button on the parent window (in parent coordinates)
	// hRgn - handle to region which represents the button (in button client coordinates)
	// pParentWnd - handle to parent window
	// nID - control Id
	// nBorder - specifies width of the border in pixels for 3D highlight (allowed values are 1, 2)
	// nColor - normal color 
	// sColor - selected color
	// hColor - hover color
	// dColor - disabled color
	BOOL Create(LPCTSTR lpszCaption, DWORD dwStyle,
		const CPoint point, CRgn & rgn,
		CWnd* pParentWnd, UINT nID);
							// constructor with hover & selected color specified
	BOOL Create(LPCTSTR lpszCaption, DWORD dwStyle,
		const CPoint point, CRgn & rgn,
		CWnd* pParentWnd, UINT nID,
		UINT nBorder,
		COLORREF nColor, COLORREF sColor,
		COLORREF hColor, COLORREF dColor);
	//自定义按钮的BMP,如果pN为NULL,则表示不使用自定义的BMP,使用pN来求透明区域
	//transparent为TRUE表示只将BMP作为一个区域来使用,不使用其图像来画按钮
	BOOL SetBMP( CBitmap * pN, CBitmap * pS = NULL,
		CBitmap * pH = NULL, CBitmap * pD = NULL,
		COLORREF clrMask = RGB( 255, 0, 255 ),
		BOOL transparent = FALSE );

	//设置画按钮用的图像,bmp将按CX等分,按钮的区域由mask决定
	virtual BOOL SetFaceIMG( CBitmap * pBMP, int cx, COLORREF mask );
};

/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_BTNTEXTSAMPLE_H__A622CD42_22FB_11D2_BC00_FD41D317EE64__INCLUDED_)

⌨️ 快捷键说明

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