自繪實現(xiàn)半透明水晶按鈕
運行效果
實現(xiàn)方法
1.給按鈕加上BS_OWNERDRAW樣式
2.重載DrawItem函數(shù),在這里繪制按鈕
3.關(guān)鍵之處就是把父窗口的背景復(fù)制到按鈕上,實現(xiàn)視覺上的透明
4.最后通過AlphaBlend實現(xiàn)半透明.
源碼下載:
http://blog.csdn.net/cometnet/article/details/8464693實現(xiàn)源碼
C/C++ code
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
// MyButton.h
#pragma once
// CMyButton
class CMyButton : public CButton
{
DECLARE_DYNAMIC(CMyButton)
public:
CMyButton();
virtual ~CMyButton();
public:
void SetBkColor(COLORREF color);
void SetTextColor(COLORREF color);
private:
bool m_bOver;
bool m_bDown;
bool m_bDisable;
bool m_bTracking;
COLORREF m_bkColor;
COLORREF m_textColor;
protected:
DECLARE_MESSAGE_MAP()
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual void PreSubclassWindow();
public:
virtual void DrawItem(LPDRAWITEMSTRUCT /*lpDrawItemStruct*/);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg LRESULT OnMouseLeave(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnMouseHover(WPARAM wParam, LPARAM lParam);
afx_msg void OnEnable(BOOL bEnable);
private:
void ButtonInit();
void DrawButton();
void DrawButton(HDC hDestDC);
};
(###)
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點擊舉報。