darker
2025-02-18 f4e3d35dd0f912c303b13b48a4a3fc09ccb0a845
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once
#include "afxwin.h"
 
#define BS_NORMAL        0
#define BS_HOVER        1
#define BS_PRESS        2
#define BS_FOCUS        3
#define BS_DISABLE        4
 
#define BLBUTTON_MENU_ITEM_CLICKED        0x1345
 
typedef struct tagBLBUTTON_NMHDR
{
    NMHDR        nmhdr;
    DWORD_PTR    dwData;
    DWORD_PTR    dwData1;
    DWORD_PTR    dwData2;
} BLBUTTON_NMHDR;
 
class CBlButton :
    public CButton
{
private:
    typedef struct tagBADGE
    {
        COLORREF badgeBackground;
        COLORREF badgeForeground;
        int type;                       /* 0: ÎÞ,²»ÏÔʾ*/
        int number;
    } BADGE;
 
public:
    CBlButton();
    ~CBlButton();
 
 
public:
    void SetRoundWidth(int width);
    int GetDrawState();
    void SetFrameColor(int index, COLORREF color);
    void SetFrameColor(COLORREF color);
    void SetBkgndColor(int index, COLORREF color);
    void SetTextColor(int index, COLORREF color);
    void SetBkgndBmp(const char* pszBmpFile);
    void SetFaceColor(COLORREF color);
    void SetTextColor(COLORREF color);
    void SetBadgeNumber(int number);
    void ShowDotBadge(BOOL bShow, COLORREF color);
    void SetMenu(HMENU hMenu);
    void SetCurrentMenuItem(UINT nPosition);
    HMENU GetMenu();
    void SetIcon(HICON hIcon, HICON hIconGray, int width);
    void Flash(int ms);
    void StopFlash();
    BOOL IsFlash();
 
private:
    BOOL CustomBitBlt(HDC hDC, LPRECT lprc, CString& strBkgndBmp, int nFrame, int nAllFrame,
        int nB0, int nB1, int nB2, int nB3, COLORREF crTransparent);
    void CBlButton::Notify(int nCode, DWORD_PTR dwData, DWORD_PTR dwData1 = 0, DWORD_PTR dwData2 = 0);
 
private:
    bool m_bHover;            // ÐüÍ£ 
    bool m_bSelected;        // °´Ï 
    BOOL m_bTracking;        // ¸ú×Ù 
    int m_nState;
    int m_nRoundWidth;
 
private:
    COLORREF m_crFrame[5];    // ±ß¿òÑÕÉ«
    COLORREF m_crBkgnd[5];    // ±³¾°ÑÕÉ«
    COLORREF m_crText[5];    // Îı¾ÑÕÉ«
    CString m_strBkgndBmp;
 
private:
    BADGE m_badge;
    HMENU m_hMenu;
    HICON m_hIcon[2];
    int m_nIconWidth;
    int m_nFlashState;        // ÉÁ˸״̬£¬0£º²»ÉÁ£»1ºÍ2ΪÉÁ˸Çл»ÖÐ
 
public:
    virtual void DrawItem(LPDRAWITEMSTRUCT /*lpDrawItemStruct*/);
    virtual void PreSubclassWindow();
    DECLARE_MESSAGE_MAP()
    afx_msg void OnMouseMove(UINT nFlags, CPoint point);
    afx_msg void OnMouseHover(UINT nFlags, CPoint point);
    afx_msg void OnMouseLeave();
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    afx_msg BOOL OnBnClicked();
    afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
    afx_msg void OnTimer(UINT_PTR nIDEvent);
};