skinbtn.h

来自「一个界面类似QQ界面的小程序」· C头文件 代码 · 共 86 行

H
86
字号
/************************************************************************ 
* 文件名:    SkinBtn.h 
* 文件描述:  图片按钮 
* 创建人:    黄锐坤(Nuk), 2006年08月22日
* 版本号:    1.0 
************************************************************************/ 

#pragma once
#include <atlimage.h>       


// CSkinBtn

class CSkinBtn : public CButton
{
	DECLARE_DYNAMIC(CSkinBtn)

public:
	CSkinBtn();
	virtual ~CSkinBtn();

	typedef enum state
	{
		NORMAL,
		HOVER,
		DOWN,
		DISABLE
	}state;

protected:
	DECLARE_MESSAGE_MAP()

	CImage  m_imgNormal;
	CImage  m_imgHover;
	CImage  m_imgDown;
	CImage  m_imgDisable;

private:
	state m_state;
	COLORREF m_fg, m_bg;
	bool m_bMouseOver;
	bool m_bEnabled;
	CFont *m_pFont;
	
	bool m_bDCStored;//是否已经保存背景图
	
	CImage m_hMouseInIcon;
	CImage m_hMouseOutIcon;
	CPoint m_textPos;
	CRect m_iconRect;

	CDC m_memDC;

public:
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
protected:
	virtual void PreSubclassWindow();
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDIS);
protected:	
	//在按钮中填充颜色
	void DrawFilledRect(CDC *DC, CRect R, COLORREF color);
	//设置按钮上的字体颜色
	void DrawButtonText(CDC *DC, CRect R, CString str, COLORREF TextColor);
	void DrawButton();
public:
	void SetOwnerDraw(bool IsDraw);
	void SetImage(UINT nNormalID, UINT nHoverID, UINT nDownID, UINT nDisableID);
	void SetImage(CString strNormal, CString strHover, CString strDown, CString strDisable);
	void SetIcon(CString  strMouseOut,CString strMouseIn);
	void SetColor(COLORREF fgcolor,COLORREF bgcolor);
	void SetTextPos(CPoint point);
	CImage* GetPaintImage(){return &m_imgNormal;}
	CImage* GetPaintIcon(){return &m_hMouseOutIcon;}
	CPoint GetTextPos(){return m_textPos;}
	COLORREF GetFGColor() { return m_fg; }	
	COLORREF GetBGColor() { return m_bg; }
	CRect GetRectInParent();
	CRect GetIconRect(){return m_iconRect;}
public:
	afx_msg void OnEnable(BOOL bEnable);
};

⌨️ 快捷键说明

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