GDI+的PNG透明4状态按钮,放到DIALOG或者FRAMEWND上就不刷新自己了
诚向各位高手求教!!!
这个类可以在网络上找到,单独使用没问题,可加上背景以后,透明的地方就漏出来了。
对GID+不太熟,见谅!
背景已处理 OnCtlColor, OnEraseBkGrnd之类的函数。
class CGdipButton : public CButton
{
public:
CGdipButton();
virtual ~CGdipButton();
// image types
enum {
STD_TYPE = 0,
ALT_TYPE,
DIS_TYPE
};
// sets the image type
void SetImage(int type);
BOOL LoadAltImage(UINT id, LPCTSTR pType);
BOOL LoadStdImage(UINT id, LPCTSTR pType);
// 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 SetHorizontal(bool ImagesAreLaidOutHorizontally = FALSE);
void DeleteToolTip();
protected:
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_nCurType;
CGdiPlusBitmapResource* m_pAltImage;
CGdiPlusBitmapResource* 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(CGdipButton)
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()
private:
CDC m_dcBk; // button background
CDC m_dcStd; // standard button
CDC m_dcStdP; // standard button pressed
CDC m_dcStdH; // standard button hot
CDC m_dcAlt; // alternate button
CDC m_dcAltP; // alternate button pressed
CDC m_dcAltH; // alternate button hot
CDC m_dcGS; // grayscale button (does not have a hot or pressed state)
CDC* m_pCurBtn; // current pointer to one of the above
};