?? buttonex.h
字號(hào):
#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
//本類用于在按鈕上顯示一個(gè)文本字串,此文本可指定字體
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()來(lái)給m_color賦值可指定顏色
//SetPushLike( TRUE )可將此按鈕設(shè)為可按下的銨鈕,否則為平面
#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:
//設(shè)置資源ID
// if imgID == 0,則關(guān)閉此狀態(tài)位圖
BOOL SetImgIDNormal( UINT imgID );
BOOL SetImgIDDown( UINT imgID );
BOOL SetImgIDFocus( UINT imgID );
BOOL SetImgIDDisable( UINT imgID );
BOOL SetImgIDCheck( UINT imgID );
BOOL SetImgIDHaveMouse( UINT imgID );
//設(shè)置BMP文件名
// if imgName == NULL,則關(guān)閉此狀態(tài)位圖
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;
};
//允許/禁止在鼠標(biāo)移動(dòng)設(shè)置聚焦特性
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; //標(biāo)識(shí)是否響應(yīng)鼠標(biāo)在其上通過的動(dòng)作
BOOL m_haveMouse; //標(biāo)識(shí)鼠標(biāo)是否在按鈕上
BOOL m_isChecked;
BOOL m_isPushed;
};
/////////////////////////////////////////////////////////////////////////////
// CBtnEx的用法:
// 生成一個(gè)CBtnEx對(duì)象,對(duì)要做成園按鈕的控件做SubclassWindow即可
class JWX_EXT_CLASS CBtnEx : public CButton
{
public:
typedef enum
{
patternRect,
patternRound,
patternOther
} EBtnPat;
CBtnEx();
//設(shè)置按鈕形狀,并以此形狀設(shè)置窗口區(qū)域,若用patternOther,則此前m_rgn應(yīng)建立
void SetPattern( EBtnPat pattern );
//設(shè)置畫按鈕用的圖像,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;
//標(biāo)識(shí)按鈕是否透明,應(yīng)在subclass之前設(shè)置,如果對(duì)話框模板中已設(shè)透明,此值可將在preSubclass中自動(dòng)設(shè)置
BOOL m_bgTransparent;
//文本式樣,TRUE時(shí)為立體,否則平面
BOOL m_3DText;
//邊框厚度,缺省為2,可以是1
int m_nBorder; // width of the border in pixels for 3D highlight
//畫立體框用的顏色,在構(gòu)造函數(shù)中調(diào)用系統(tǒng)色來(lái)生成,此后可由用戶指定
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
//使用位圖來(lái)畫按鈕,其中的圖像按順序?yàn)椋簄ormal, selected, disabled, hover
//可以只有normal一個(gè)圖像
CImageList m_faceIMG;
//判斷及更新的按鈕用的區(qū)域,坐標(biāo)為本按鈕的客戶區(qū)坐標(biāo)
//若此值被外部代碼改動(dòng),應(yīng)調(diào)用SetPattern()來(lái)更新窗口區(qū)域
CRgn m_rgn;
//允許鼠標(biāo)經(jīng)過時(shí)點(diǎn)亮按鈕
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中調(diào)用此函數(shù)通知父窗口重畫
//如果返回FALSE,接下來(lái)畫自己
//如果返回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 );
//這是用于畫特殊邊框的函數(shù),由于類重載實(shí)現(xiàn)
virtual void DrawBorderOther(CDC * pDC, UINT state, CRect & rect, int & nRadius );
//用于鎖定父窗口更新一個(gè)變量,見NotifyParentRepaint()中的說(shuō)明
BOOL m_disParentRepaint;
//按鈕的式樣,如矩形、園形等,由patternXXXX定義
EBtnPat m_pattern;
CRgn m_wndRgn;//設(shè)置區(qū)域后,系統(tǒng)要求保持此區(qū)域,這是屏幕坐標(biāo)
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);
//這是用于畫特殊邊框的函數(shù),由子類重載實(shí)現(xiàn)
virtual void DrawBorderOther(CDC * pDC, UINT state, CRect & rect, int & nRadius );
//復(fù)制BMP,該死的MS,連復(fù)制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來(lái)求透明區(qū)域
//transparent為TRUE表示只將BMP作為一個(gè)區(qū)域來(lái)使用,不使用其圖像來(lái)畫按鈕
BOOL SetBMP( CBitmap * pN, CBitmap * pS = NULL,
CBitmap * pH = NULL, CBitmap * pD = NULL,
COLORREF clrMask = RGB( 255, 0, 255 ),
BOOL transparent = FALSE );
//設(shè)置畫按鈕用的圖像,bmp將按CX等分,按鈕的區(qū)域由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_)
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -