资源简介
MFC开发的漂亮界面程序,具备换肤、半透明功能。
代码片段和文件信息
#include “StdAfx.h“
#include “Button.h“
namespace itallto {
namespace directui {
Button::Button() : m_pBackground(NULL)
m_nState(ButtonStateNormal)
m_strText(_T(““))
m_clrBackMask(0){
for (int i = 0; i < 4; ++i) {
m_nBackPos[i] = -1;
}
for (int i = 0; i < 4; ++i) {
m_clrTextColor[i] = 0;
}
}
Button::~Button() {
}
void Button::SetText(LPCTSTR pszText) {
m_strText = pszText;
}
CString Button::GetText() const {
return m_strText;
}
void Button::SetBackground(CBitmap* pBackground INT nNormalPos
INT nHoverPos INT nSelectedPos INT nDisabledPos
COLORREF clrMask) {
if (NULL == pBackground) {
return;
}
m_pBackground = pBackground;
m_nBackPos[ButtonStateNormal] = nNormalPos;
m_nBackPos[ButtonStateHover] = nHoverPos;
m_nBackPos[ButtonStateSelected] = nSelectedPos;
m_nBackPos[ButtonStateDisabled] = nDisabledPos;
m_clrBackMask = clrMask;
}
void Button::OnPaint(CDC *pDC) {
if (!IsVisible()) return;
if (m_pBackground) {
if (m_nBackPos[m_nState] != -1) {
INT nBmpX = m_nWidth * m_nBackPos[m_nState];
BITMAP bm;
m_pBackground->GetBitmap(&bm);
INT nBmpWidth = bm.bmWidth / m_nWidth;
INT nBmpHeight = bm.bmHeight / m_nHeight;
CDC bmpDC;
bmpDC.CreateCompatibleDC(pDC);
CBitmap* pOldBmp = bmpDC.Selectobject(m_pBackground);
INT nBmpY = 0;
pDC->TransparentBlt(m_nX m_nY m_nWidth m_nHeight
&bmpDC
nBmpX
nBmpY
m_nWidth
m_nHeight
m_clrBackMask);
bmpDC.Selectobject(pOldBmp);
}
}
if (!m_strText.IsEmpty()) {
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(m_clrTextColor[m_nState]);
CRect rect;
GetBoundRect(rect);
pDC->DrawText(m_strText &rect DT_SINGLELINE | DT_VCENTER | DT_CENTER);
}
}
void Button::onmousemove(UINT nFlags CPoint point BOOL& bNeedUpdate) {
bNeedUpdate = FALSE;
if (ButtonStateSelected == m_nState) {
return;
}
if (ButtonStateHover == m_nState) {
return;
}
m_nState = ButtonStateHover;
bNeedUpdate = TRUE;
}
void Button::onmouseleave(UINT nFlags CPoint point BOOL& bNeedUpdate) {
bNeedUpdate = FALSE;
if (ButtonStateNormal != m_nState) {
m_nState = ButtonStateNormal;
bNeedUpdate = TRUE;
}
}
void Button::OnLButtonDown(UINT nFlags CPoint point BOOL& bNeedUpdate) {
bNeedUpdate = FALSE;
if (ButtonStateSelected != m_nState) {
m_nState = ButtonStateSelected;
bNeedUpdate = TRUE;
}
}
void Button::OnLButtonUp(UINT nFlags CPoint point BOOL& bNeedUpdate) {
bNeedUpdate = FALSE;
if (ButtonStateNormal != m_nState) {
m_nState = ButtonStateNormal;
bNeedUpdate = TRUE;
}
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2873 2015-09-17 10:05 DirectUIForMFC\Button.cpp
文件 1208 2015-09-17 10:05 DirectUIForMFC\Button.h
文件 7968 2015-10-13 16:37 DirectUIForMFC\Debug\BuildLog.htm
文件 383100 2015-09-17 15:32 DirectUIForMFC\DirectUIForMFC.aps
文件 2103 2015-09-14 15:38 DirectUIForMFC\DirectUIForMFC.cpp
文件 559 2015-09-14 15:39 DirectUIForMFC\DirectUIForMFC.h
文件 5458 2015-09-17 15:32 DirectUIForMFC\DirectUIForMFC.rc
文件 6374 2015-10-13 16:16 DirectUIForMFC\DirectUIForMFC.vcproj
文件 1415 2015-10-13 16:37 DirectUIForMFC\DirectUIForMFC.vcproj.PAICDOM.EX-GONGMINGUANG001.user
文件 15389 2015-10-13 16:37 DirectUIForMFC\DirectUIForMFCDlg.cpp
文件 1967 2015-09-17 16:13 DirectUIForMFC\DirectUIForMFCDlg.h
文件 2805 2015-09-17 09:15 DirectUIForMFC\Element.cpp
文件 1999 2015-09-17 10:04 DirectUIForMFC\Element.h
文件 1100 2015-10-13 16:23 DirectUIForMFC\HomeButton.cpp
文件 313 2015-10-13 16:02 DirectUIForMFC\HomeButton.h
文件 2995 2015-09-14 09:43 DirectUIForMFC\ReadMe.txt
文件 36056 2015-09-14 15:47 DirectUIForMFC\res\bmp129.bmp
文件 85592 2015-09-14 17:35 DirectUIForMFC\res\bmp130.bmp
文件 129656 2015-09-15 17:45 DirectUIForMFC\res\bmp131.bmp
文件 25976 2015-09-17 14:35 DirectUIForMFC\res\bmp135.bmp
....... 67777 2007-11-28 16:21 DirectUIForMFC\res\DirectUIForMFC.ico
文件 370 2015-09-14 09:43 DirectUIForMFC\res\DirectUIForMFC.rc2
文件 820 2015-09-17 15:32 DirectUIForMFC\resource.h
文件 147 2015-09-14 09:43 DirectUIForMFC\stdafx.cpp
文件 1854 2015-09-14 09:43 DirectUIForMFC\stdafx.h
文件 8047 2015-09-17 16:14 DirectUIForMFC\TabView.cpp
文件 2006 2015-09-17 15:05 DirectUIForMFC\TabView.h
文件 1030 2015-09-14 09:43 DirectUIForMFC\targetver.h
文件 1240 2015-09-17 09:06 DirectUIForMFC\ToolButton.cpp
文件 309 2015-09-16 17:13 DirectUIForMFC\ToolButton.h
............此处省略6个文件信息
评论
共有 条评论