📄 buttons.cpp
字号:
// ColorButton.cpp : implementation file//#include "stdafx.h"#include "Fusion.h"#include "Buttons.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// RxButtonRxButton::RxButton(){ m_nButtonStyle = BS_PUSHBUTTON; m_nCheck = 0; // Initialize Unchecked.}RxButton::~RxButton(){}BEGIN_MESSAGE_MAP(RxButton, CButton) //{{AFX_MSG_MAP(RxButton) ON_WM_RBUTTONUP() ON_WM_LBUTTONDBLCLK() //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// RxButton message handlers// 滚瓢 胶鸥老阑 历厘茄饶 OwnerDraw 屈怕肺 函券茄促.// 檬扁 积己矫 叼弃飘 胶鸥老肺 瘤沥窍搁 DrawItem窃荐啊 龋免登瘤 臼绰促.// " BS_OWNERDRAW肺 瘤沥窍搁 促弗 胶鸥老篮 公矫等促.void RxButton::PreSubclassWindow(){ UINT nStyle = this->GetButtonStyle(); if(nStyle & BS_PUSHBUTTON) m_nButtonStyle = BS_PUSHBUTTON; else if(nStyle & BS_CHECKBOX) m_nButtonStyle = BS_CHECKBOX; else if(nStyle & BS_USERBUTTON) m_nButtonStyle = BS_RADIOBUTTON; CButton::PreSubclassWindow(); ModifyStyle(0, BS_OWNERDRAW);}void RxButton::OnRButtonUp(UINT nFlags, CPoint point) { NMHDR hdr; hdr.hwndFrom = m_hWnd; hdr.idFrom = GetDlgCtrlID(); hdr.code = BTN_RIGHT_CLICKED; CWnd* pOwner = GetOwner(); if (pOwner) pOwner->SendMessage(WM_NOTIFY, hdr.idFrom, (LPARAM)&hdr); CButton::OnRButtonUp(nFlags, point);}// 歹喉努腐且 版快 弊成 滚瓢 努腐栏肺 秦霖促.(扁促覆阑 绝矩促. down->up->down->up)void RxButton::OnLButtonDblClk(UINT nFlags, CPoint point) { SendMessage(WM_LBUTTONDOWN, 0, MAKELPARAM(point.x, point.y));}/////////////////////////////////////////////////////////////////////////////// User Defined Functions// Auto Exchange check statusvoid RxButton::SetToggle(){ m_nCheck ? SetCheck(0) : SetCheck(1);}void RxButton::SetCheck(int nCheck, BOOL bRedraw){ m_nCheck = nCheck;// TRACE1("\nSetCheck : %d", nCheck); if(bRedraw) RedrawWindow();}int RxButton::GetCheck(){ return m_nCheck;}/////////////////////////////////////////////////////////////////////////////// RxPushButton Class/////////////////////////////////////////////////////////////////////////////RxPushButton::RxPushButton(){ m_crInfo.crTextNormal = RGB( 0, 0, 0); m_crInfo.crTextSelect = RGB( 0, 0, 0); m_crInfo.crTextDisable = RGB(238,238,238); m_crInfo.crFaceNormal = RGB(192,192,192); m_crInfo.crFaceSelect = RGB(232,252,232); m_crInfo.crFaceDisable = RGB(192,192,192); m_crInfo.crLeftNormal = RGB(255,255,255); m_crInfo.crRightNormal = RGB(128,128,128); m_crInfo.crLeftSelect = RGB( 49, 49, 49); m_crInfo.crRightSelect = RGB(238,238,238); m_crInfo.crLeftDisable = RGB(142,142,142); m_crInfo.crRightDisable = RGB(142,142,142);}RxPushButton::~RxPushButton(){}BEGIN_MESSAGE_MAP(RxPushButton, RxButton) //{{AFX_MSG_MAP(RxPushButton) ON_WM_ERASEBKGND() //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// RxPushButton message handlersBOOL RxPushButton::OnEraseBkgnd(CDC* pDC) { return TRUE;}void RxPushButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { // 滚瓢狼 阿辆 惑怕沥焊甫 掘绢柯促. CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); CRect rect = lpDrawItemStruct->rcItem; UINT state = lpDrawItemStruct->itemState; // Create a mem DC for drawing CDC dcMem; CBitmap bmpMem; dcMem.CreateCompatibleDC(pDC); bmpMem.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height()); CBitmap *pOldBmp = dcMem.SelectObject(&bmpMem); int nSaveDC = dcMem.SaveDC(); BUTTONCOLOR crInfoTemp; // Select color Information switch(m_nButtonStyle) { // 阿 滚瓢狼 屈怕肺 累悼窍绰 巴贸烦 祸惑阑 炼例茄促. case BS_PUSHBUTTON : GetColorPushStyle(state, &crInfoTemp); break; case BS_RADIOBUTTON : GetColorRadioStyle(state, &crInfoTemp); break; case BS_CHECKBOX : GetColorCheckStyle(state, &crInfoTemp); break; } // Draw Background CBrush brush, *pOldBrush; brush.CreateSolidBrush(crInfoTemp.crFace); pOldBrush = dcMem.SelectObject(&brush); dcMem.PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY); dcMem.SelectObject(pOldBrush); brush.DeleteObject(); // Draw Button Edge CRect rcTemp = rect; dcMem.Draw3dRect(rcTemp, RGB( 0, 0, 0), RGB( 0, 0, 0)); rcTemp.DeflateRect(1, 1, 1, 1); dcMem.Draw3dRect(rcTemp, crInfoTemp.crLeft, crInfoTemp.crRight); // Draw Text CRect rcTemp2 = rect; if (state & ODS_SELECTED || GetCheck()) rcTemp2.OffsetRect(1,1); DrawButtonText(&dcMem, rcTemp2, &crInfoTemp); // Draw Focus Rect if (state & ODS_FOCUS) { rcTemp.DeflateRect(2, 2, 2, 2); dcMem.DrawFocusRect(rcTemp); } pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), &dcMem, rect.left, rect.top, SRCCOPY); // Clean up. dcMem.SelectObject(pOldBmp); dcMem.RestoreDC(nSaveDC); dcMem.DeleteDC(); bmpMem.DeleteObject();}// Normal-(Btn Down)->Focus-(Btn Down)->Select-(Btn Up)->Focus-(Kill Focus)->Normalvoid RxPushButton::GetColorPushStyle(UINT nState, BUTTONCOLOR *crInfo){ // Select color Information if (nState & ODS_SELECTED) // 滚瓢捞 喘妨廉 乐阑 版快 { crInfo->crText = m_crInfo.crTextSelect; crInfo->crFace = RGB(162,162,162);//m_crInfo.crFaceSelect; crInfo->crLeft = m_crInfo.crLeftSelect; crInfo->crRight = m_crInfo.crRightSelect; }/* else if (nState & ODS_FOCUS) // 器目胶甫 啊瘤绊 乐阑 版快 { crInfo->crText = m_crInfo.crTextFocus; crInfo->crFace = m_crInfo.crFaceFocus; crInfo->crLeft = m_crInfo.crLeftNormal; crInfo->crRight = m_crInfo.crRightNormal; }*/ else if (nState & ODS_DISABLED) // 荤侩 阂瓷 惑怕老 版快 { crInfo->crText = m_crInfo.crTextDisable; crInfo->crFace = m_crInfo.crFaceDisable; crInfo->crLeft = m_crInfo.crLeftDisable; crInfo->crRight = m_crInfo.crRightDisable; } else // 焊烹 惑怕 { crInfo->crText = m_crInfo.crTextNormal; crInfo->crFace = m_crInfo.crFaceNormal; crInfo->crLeft = m_crInfo.crLeftNormal; crInfo->crRight = m_crInfo.crRightNormal; }}void RxPushButton::GetColorRadioStyle(UINT nState, BUTTONCOLOR *crInfo){ if (nState & ODS_DISABLED) // 荤侩 阂瓷 惑怕老 版快 { crInfo->crText = m_crInfo.crTextDisable; crInfo->crFace = m_crInfo.crFaceDisable; crInfo->crLeft = m_crInfo.crLeftDisable; crInfo->crRight = m_crInfo.crRightDisable; return; } if (nState & ODS_FOCUS) // 器目胶甫 啊瘤绊 乐阑 版快 { if (GetCheck()) // 眉农 登绢 乐阑 版快 { crInfo->crText = m_crInfo.crTextSelect; crInfo->crFace = m_crInfo.crFaceSelect; crInfo->crLeft = m_crInfo.crLeftSelect; crInfo->crRight = m_crInfo.crRightSelect; } else { crInfo->crText = m_crInfo.crTextNormal; crInfo->crFace = m_crInfo.crFaceNormal; crInfo->crLeft = m_crInfo.crLeftNormal; crInfo->crRight = m_crInfo.crRightNormal; } } else // 器目胶啊 绝阑 版快 { if(GetCheck()) // 眉农 登绢 乐阑 版快 { crInfo->crText = m_crInfo.crTextSelect; crInfo->crFace = m_crInfo.crFaceSelect; crInfo->crLeft = m_crInfo.crLeftSelect; crInfo->crRight = m_crInfo.crRightSelect; } else { crInfo->crText = m_crInfo.crTextNormal; crInfo->crFace = m_crInfo.crFaceNormal; crInfo->crLeft = m_crInfo.crLeftNormal; crInfo->crRight = m_crInfo.crRightNormal; } }}// * Default Routing *//// Uncheck-(Btn Down)->Focus-(Btn Down)->Select-(Btn Up)->Focus-(SetCheck(1))->Check// ~~~~~==> Don't remove this state : for the SetFocus()//// Event situation State Check value //--------------------------------------------------------------------------------------// Uncheck 0// Btn Down Focus Uncheck 0 ODS_FOCUS // Btn Down Focus Check 0 ODS_SELECTED// Btn Up Focus Uncheck 0 ODS_FOCUS <== this state cause flicker!! : // SetCheck(1) Focus Check 1 prevent using the m_bFirstFocus Flag.////// ** New Routing **//// Event situation State Check value m_bFirstFocus nState//--------------------------------------------------------------------------------------// Uncheck 0 FALSE// Btn Down Focus Uncheck 0 FALSE ODS_FOCUS// Btn Down Focus Check 0 FALSE ODS_SELECT// Btn Up Focus Check 0 TRUE ODS_FOCUS// SetCheck(1) Focus Check 1 FALSE//void RxPushButton::GetColorCheckStyle(UINT nState, BUTTONCOLOR *crInfo){ if (nState & ODS_DISABLED) // 荤侩 阂瓷 惑怕老 版快 { //TRACE1("\nDrawItem Disable : %d", GetCheck()); crInfo->crText = m_crInfo.crTextDisable; crInfo->crFace = m_crInfo.crFaceDisable; crInfo->crLeft = m_crInfo.crLeftDisable; crInfo->crRight = m_crInfo.crRightDisable; return; } if (nState & ODS_FOCUS) // 器目胶甫 啊瘤绊 乐阑 版快 { if (GetCheck() || nState & ODS_SELECTED) // 眉农 登绢 乐阑 版快 { //TRACE1("\nFocus Check : %d", GetCheck()); crInfo->crText = m_crInfo.crTextSelect; crInfo->crFace = m_crInfo.crFaceSelect; crInfo->crLeft = m_crInfo.crLeftSelect; crInfo->crRight = m_crInfo.crRightSelect; } else { //TRACE1("\nFocus Uncheck : %d", GetCheck()); crInfo->crText = m_crInfo.crTextNormal; crInfo->crFace = m_crInfo.crFaceNormal; crInfo->crLeft = m_crInfo.crLeftNormal; crInfo->crRight = m_crInfo.crRightNormal; } } else // 器目胶啊 绝阑 版快 { if (GetCheck() || nState & ODS_SELECTED) // 眉农 登绢 乐阑 版快 { //TRACE1("\nCheck : %d", GetCheck()); crInfo->crText = m_crInfo.crTextSelect; crInfo->crFace = m_crInfo.crFaceSelect; crInfo->crLeft = m_crInfo.crLeftSelect; crInfo->crRight = m_crInfo.crRightSelect; } else { //TRACE1("\nUncheck : %d", GetCheck()); crInfo->crText = m_crInfo.crTextNormal; crInfo->crFace = m_crInfo.crFaceNormal; crInfo->crLeft = m_crInfo.crLeftNormal; crInfo->crRight = m_crInfo.crRightNormal; } }}void RxPushButton::DrawButtonText(CDC *pDC, CRect rect, BUTTONCOLOR *crInfo){ // Apply CWnd font CFont *pFont = GetFont(); CFont *pOldFont = (CFont *)pDC->SelectObject(pFont); // Draw Window Text CString strWindow; GetWindowText(strWindow); pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(crInfo->crText); UINT nStyle = GetStyle(); if(nStyle & BS_MULTILINE) { rect.top += 3; rect.bottom +=3; pDC->DrawText(strWindow, rect, DT_CENTER|DT_VCENTER); } else pDC->DrawText(strWindow, rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE); // Restore the original font. pDC->SelectObject(pOldFont);}// 拿矾 沥焊 汲沥.void RxPushButton::SetColors(BUTTONCOLORS *crInfo){ if(crInfo->nMask & BC_TEXTN) m_crInfo.crTextNormal = crInfo->crTextNormal; if(crInfo->nMask & BC_TEXTS) m_crInfo.crTextSelect = crInfo->crTextSelect; if(crInfo->nMask & BC_TEXTD) m_crInfo.crTextDisable = crInfo->crTextDisable; if(crInfo->nMask & BC_FACEN) m_crInfo.crFaceNormal = crInfo->crFaceNormal; if(crInfo->nMask & BC_FACES) m_crInfo.crFaceSelect = crInfo->crFaceSelect; if(crInfo->nMask & BC_FACED) m_crInfo.crFaceDisable = crInfo->crFaceDisable; if(crInfo->nMask & BC_LEFTN) m_crInfo.crLeftNormal = crInfo->crLeftNormal; if(crInfo->nMask & BC_LEFTS) m_crInfo.crLeftSelect = crInfo->crLeftSelect; if(crInfo->nMask & BC_LEFTD) m_crInfo.crLeftDisable = crInfo->crLeftDisable; if(crInfo->nMask & BC_RIGHTN) m_crInfo.crRightNormal = crInfo->crRightNormal; if(crInfo->nMask & BC_RIGHTS) m_crInfo.crRightSelect = crInfo->crRightSelect; if(crInfo->nMask & BC_RIGHTD) m_crInfo.crRightDisable = crInfo->crRightDisable;}BUTTONCOLORS* RxPushButton::GetColors(){ return &m_crInfo;}/////////////////////////////////////////////////////////////////////////////// RxRadioButton Class/////////////////////////////////////////////////////////////////////////////RxRadioButton::RxRadioButton(){ m_crBkgnd = RGB(204,220,223); m_crText = RGB( 0, 0, 0); m_crRadioFace = RGB(222,233,235); m_crRadioPoint = RGB( 0, 0, 0); m_crRadioEdge = RGB( 0, 0, 0); m_crRadio1 = RGB( 32, 43, 45); m_crRadio2 = RGB( 92,103,105); m_crRadio3 = RGB(142,153,155); m_crRadio4 = RGB(202,213,215); m_crRadio5 = RGB(252,253,255);}RxRadioButton::~RxRadioButton(){}BEGIN_MESSAGE_MAP(RxRadioButton, RxButton) //{{AFX_MSG_MAP(RxRadioButton) ON_WM_ERASEBKGND() //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// RxRadioButton message handlersBOOL RxRadioButton::OnEraseBkgnd(CDC* pDC) { return TRUE;}/////////////////////////////////////////////////////////////////////////////// User Defined Functions.void RxRadioButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { // 滚瓢狼 阿辆 惑怕沥焊甫 掘绢柯促. CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); CRect rect = lpDrawItemStruct->rcItem; UINT state = lpDrawItemStruct->itemState; int nSaveDC = pDC->SaveDC();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -