www.pudn.com > StyleToolkit_demo_src.zip > StyleButton.h


// 
// StyleButton.h : Version 1.0 - see article at CodeProject.com 
// 
// Author:  Darren Sessions 
//           
// 
// Description: 
//     StyleButton is a CButton derived control that uses GDI+ to support  
//     alternate image formats.  StyleButton is an updated version of my 
//	   GdipButton that supports the use of Styles. 
// 
// History 
//     Version 1.0 - 2008 July 1 
//     - Initial public release 
// 
// License: 
//     This software is released under the Code Project Open License (CPOL), 
//     which may be found here:  http://www.codeproject.com/info/eula.aspx 
//     You are free to use this software in any way you like, except that you  
//     may not sell this source code. 
// 
//     This software is provided "as is" with no expressed or implied warranty. 
//     I accept no liability for any damage or loss of business that this  
//     software may cause. 
// 
/////////////////////////////////////////////////////////////////////////////// 
 
#pragma once 
 
#include "style.h" 
 
///////////////////////////////////////////////////////////////////////////// 
// StyleButton window 
 
class StyleButton : public CButton 
{ 
public: 
 
	StyleButton(); 
	virtual ~StyleButton(); 
 
	// image states 
	enum	 
	{ 
		STD_STATE	= 0, 
		ALT_STATE, 
		DIS_STATE 
	}; 
 
	// sets the image type 
	void SetImage(int type); 
 
	// load image functions 
	BOOL LoadAltImage(UINT id, LPCTSTR pType); 
	BOOL LoadStdImage(UINT id, LPCTSTR pType); 
 
	// load style functions 
	void LoadStdStyle(Style style); 
	void LoadHotStyle(Style style); 
	void LoadPressedStyle(Style style); 
	void LoadAltStyle(Style style); 
	void LoadAltHotStyle(Style style); 
	void LoadAltPressedStyle(Style style); 
	void LoadDisabledStyle(Style style); 
 
	void CreateNow(); 
 
	// if false, disables the press state and uses grayscale image if it exists 
	void EnableButton(BOOL bEnable = TRUE) { m_bIsDisabled = !bEnable; } 
 
	// in toggle mode each press toggles between std and alt images 
	void EnableToggle(BOOL bEnable = TRUE); 
 
	// return the enable/disable state 
	BOOL IsDisabled(void) {return (m_bIsDisabled == TRUE); } 
 
	void SetBkGnd(CDC* pDC); 
 
	void SetToolTipText(CString spText, BOOL bActivate = TRUE); 
	void SetToolTipText(UINT nId, BOOL bActivate = TRUE); 
	void DeleteToolTip(); 
 
 
protected: 
 
	enum 
	{ 
		BUTTON_TYPE_INVALID, 
		BUTTON_TYPE_IMAGE, 
		BUTTON_TYPE_STYLE 
	}; 
 
	void PaintBk(CDC* pDC); 
	void PaintBtn(CDC* pDC); 
 
	BOOL	m_bHaveAltImage; 
	BOOL	m_bHaveBitmaps; 
 
	BOOL	m_bIsDisabled; 
	BOOL	m_bIsToggle; 
	BOOL	m_bIsHovering; 
	BOOL	m_bIsTracking; 
 
	int		m_nCurState; 
	int		m_nButtonType; 
 
	GResource* m_pAltImage; 
	GResource* m_pStdImage; 
 
	CString			m_tooltext; 
	CToolTipCtrl*	m_pToolTip; 
	 
	void	InitToolTip(); 
 
	virtual void PreSubclassWindow(); 
	virtual void DrawItem(LPDRAWITEMSTRUCT /*lpDrawItemStruct*/); 
	virtual BOOL PreTranslateMessage(MSG* pMsg); 
 
	//{{AFX_MSG(StyleButton) 
	afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor); 
	afx_msg BOOL OnEraseBkgnd(CDC* pDC); 
	afx_msg void OnMouseMove(UINT nFlags, CPoint point); 
	afx_msg LRESULT OnMouseLeave(WPARAM wparam, LPARAM lparam); 
	afx_msg LRESULT OnMouseHover(WPARAM wparam, LPARAM lparam) ; 
	//}}AFX_MSG 
 
	DECLARE_MESSAGE_MAP() 
 
	BOOL	m_bHavePStyle, m_bHaveHStyle, m_bHaveGStyle; 
	BOOL	m_bHaveAltStyle, m_bHaveAltPStyle, m_bHaveAltHStyle; 
 
	void	DrawHotBitmap(Graphics* pGraphics, Bitmap* bmp); 
	void	DrawGrayBitmap(Graphics* pGraphics, Bitmap* bmp); 
 
private: 
 
	CDC		m_dcBk;			// button background 
	 
	MemDC	m_dcStd;		// standard button 
	MemDC	m_dcStdP;		// standard button pressed 
	MemDC	m_dcStdH;		// standard button hot 
	MemDC	m_dcStdG;		// grayscale button  
 
	MemDC	m_dcAlt;		// alternate button 
	MemDC	m_dcAltP;		// alternate button pressed 
	MemDC	m_dcAltH;		// alternate button hot 
 
	CDC*	m_pCurBtn;		// current pointer to one of the above 
 
	// Style versions of above 
	Style	m_StdStyle; 
	Style	m_StdPStyle; 
	Style	m_StdHStyle; 
	Style	m_StdGStyle; 
	Style	m_AltStyle; 
	Style	m_AltPStyle; 
	Style	m_AltHStyle; 
};