win32方式实现自绘按钮

/**
 * \file OwnerDrawButton.h
 *
 * \brief 自绘按钮的实现类
 *
 * \author
 */ 

#pragma once

class COwnerDrawButton
{
public:
    COwnerDrawButton(void);
    ~COwnerDrawButton(void);
private:
    COwnerDrawButton(const COwnerDrawButton &OtherOwnerDrawButton);
    COwnerDrawButton &operator=(const COwnerDrawButton &OtherOwnerDrawButton);
public:
    /**
	 * \brief 刷新控件
	 */
    bool InvalidataCtrl();
public:
    /**
	 * \brief 创建按钮
	 * \param lpszCaption 参数,为按钮的显示文本
     * \param lpszImage 参数,为按钮的位图路径
     * \param rect 参数,为按钮的坐标
     * \param hParentWnd 参数,为按钮的父窗口句柄
     * \param nID 参数,为按钮的控件ID
     * \param lpszImage 参数,为按钮控件一般状态位图路径
	 */
    BOOL Create(LPCSTR lpszCaption, const RECT& rect, HWND hParentWnd,\
        UINT nID, LPCSTR lpszImage);
    /**
	 * \brief 绘制按钮
     * \param hDC 参数,为按钮的绘制用DC句柄
	 */
    void Draw(HDC hDC);
    void DrawFocusRect(HDC hDC,RECT &rcWnd);
    /**
	 * \brief 设置按钮
     * \param fEnable 参数,为设置按钮是否可用
	 */
    void EnableButton(bool fEnable);

    void OnLbuttonDown(WPARAM wParam, LPARAM lParam);
    void OnLbuttonUp(WPARAM wParam, LPARAM lParam);
    void OnLbuttonDBClick(WPARAM wParam, LPARAM lParam);
    void OnMouseMove(WPARAM wParam, LPARAM lParam);
    void OnMouseLeave(WPARAM wParam, LPARAM lParam);
private:
    /**
	 * \brief 按钮消息回调函数
	 */
    static LRESULT CALLBACK ButtonProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
public:
    enum STATE
    {
        STATE_UP, 
        STATE_DOWN, 
        STATE_FOCUS, 
        STATE_DISABLE
    };
    WNDPROC     m_OldProc;//!按钮的默认消息回调函数
    HWND        m_hWnd;      //!此按钮的句柄
private:
    HBITMAP     m_hFourStateBitmap; //!按钮的普通四状态位图
    BOOL        m_fRoundButton;  //!当前控件类型,TRUE为按钮类型,FALSE为一般的显示位图控件
    BOOL        m_fTrackMouse;
    int         m_nButtonState;//!按钮的当前状态
    HFONT       m_hFont;//!控件字体
};



                
  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 11
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值