⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buttonssl.cpp

📁 实现Huffman编码统计压缩算法
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	CRect rectText (rectFocus);

	CString strCaption;
	GetWindowText (strCaption);
	pDC->SetBkMode (TRANSPARENT);

	if (ODS_DISABLED & lpDrawItemStruct->itemState) {
		pDC->SetBkColor (GetSysColor (COLOR_BTNFACE));
		rectFocus.OffsetRect (1,1);
		pDC->SetTextColor (GetSysColor (COLOR_WINDOW));
		pDC->DrawText (strCaption, rectFocus, DT_SINGLELINE | m_nTextAlign);

		rectFocus.OffsetRect (-1,-1);
		pDC->SetTextColor (GetSysColor (COLOR_GRAYTEXT));
		pDC->DrawText (strCaption, rectFocus, DT_SINGLELINE | m_nTextAlign);
	}
	else {
		if (SSL_STATE_UP == m_bsState) {
			pDC->SetBkColor (m_crColors[SSL_UP_BK_COLOR]);
			pDC->SetTextColor (m_crColors[SSL_UP_TEXT_COLOR]);
		}
		if (SSL_STATE_OVER == m_bsState ) {
			pDC->SetBkColor (m_crColors[SSL_OVER_BK_COLOR]);
			pDC->SetTextColor (m_crColors[SSL_OVER_TEXT_COLOR]);
		}
		if (SSL_STATE_DOWN == m_bsState) {
			pDC->SetBkColor (m_crColors[SSL_DOWN_BK_COLOR]);
			pDC->SetTextColor (m_crColors[SSL_DOWN_TEXT_COLOR]);
		}
		pDC->DrawText (strCaption, rectFocus, DT_SINGLELINE | m_nTextAlign);
	}

	if (SSL_BS_MENU_BTN & m_nStyle) {
		// Drop down split
		CRect rectSplit (btnRect);
		rectSplit.DeflateRect (2,2);
		rectSplit.right -= DROP_BUTTON_WIDTH;
		if (!(SSL_BS_FLAT & m_nStyle) || TRUE == m_bMouseOnBtn) {
			CPen brFace (PS_SOLID, 1, ::GetSysColor (COLOR_BTNSHADOW));
			pDC->SelectObject (&brFace);
			pDC->MoveTo (rectSplit.right, rectSplit.top);
			pDC->LineTo (rectSplit.right, rectSplit.bottom);

			CPen brLite (PS_SOLID, 1, ::GetSysColor (COLOR_BTNHIGHLIGHT));
			pDC->SelectObject (&brLite);
			pDC->MoveTo (rectSplit.right + 1 , rectSplit.top);
			pDC->LineTo (rectSplit.right + 1, rectSplit.bottom);
		}
		rectSplit.left = rectSplit.right;
		rectSplit.right += DROP_BUTTON_WIDTH;

		CPoint pt (rectSplit.CenterPoint ());
		pt += CPoint (m_bBtnPushed, m_bBtnPushed);

		CPen penBlack (PS_SOLID, 1, m_bDisabled ? 
			GetSysColor (COLOR_GRAYTEXT) : GetSysColor (COLOR_WINDOWTEXT));
		pDC->SelectObject (&penBlack);
		DrawArrow (pDC, pt);

		// Drop down state
		if (TRUE == m_bMenuPushed && FALSE == m_bDisabled) {    
			rectSplit.InflateRect (1, 1);
			pDC->DrawEdge (rectSplit, BDR_SUNKENOUTER, BF_RECT);
		}
	}
}

BOOL CButtonSSL::PreTranslateMessage(MSG* pMsg) 
{
	// Initialise the tooltip if necessary
	InitToolTipCtrl ();
	m_ToolTip.RelayEvent (pMsg);

	return CButton::PreTranslateMessage(pMsg);
}

/////////////////////////////////////////////////////////////////////////////
// CButtonSSL implementation

/////////////////////////////////////////////////////////////////////////////
// Initialisation

void CButtonSSL::SetSSLButtonStyle (UINT nStyle) {
	m_nStyle = nStyle;

	// Resize the button if necessary
	if (SSL_BS_AUTOSIZE == (SSL_BS_AUTOSIZE & m_nStyle)) {
		SetSize ();
	}

	if (TRUE == IsDefault ()) {
		PostMessage (BM_SETSTYLE, BS_PUSHBUTTON, TRUE);
	}
	else {
		PostMessage (BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
	}
}

UINT CButtonSSL::GetSSLButtonStyle () {
	return m_nStyle;
}

/////////////////////////////////////////////////////////////////////////////
// Image Functions

BOOL CButtonSSL::SetSSLButtonBitmap(UINT nResourceID, COLORREF crMask) {
	BOOL bReturn = m_bmpImage.LoadBitmap (nResourceID);
	if (TRUE == bReturn) {
		m_bmpImage.GetObject (sizeof m_bmp, &m_bmp);
		m_nImageWidth = m_bmp.bmWidth;
		m_nImageHeight = m_bmp.bmHeight;
		if (NULL != m_imageList.m_hImageList) {
			m_imageList.Detach ();
		}
		bReturn = m_imageList.Create (m_bmp.bmWidth, m_bmp.bmHeight, ILC_MASK | ILC_COLOR32, 1, 1);
		if (TRUE == bReturn) {
			if (m_imageList.Add (&m_bmpImage, crMask) > -1) {
				m_bImageLoaded = TRUE;
			}
			else {
				m_bImageLoaded = FALSE;
			}
		}
		else {
			m_bImageLoaded = FALSE;
		}
	}

	// Resize the button if necessary
	if (SSL_BS_AUTOSIZE == (SSL_BS_AUTOSIZE & m_nStyle)) {
		SetSize ();
	}

	return bReturn;
}

BOOL CButtonSSL::SetSSLButtonBitmaps (UINT nUpID, COLORREF crUpMask, 
					   UINT nOverID/* = 0*/, COLORREF crOverMask/* = SSL_MASK*/,
					   UINT nDownID/* = 0*/, COLORREF crDownMask/* = SSL_MASK*/, 
					   UINT nDisabledID/* = 0*/, COLORREF crDisabledMask/* = SSL_MASK*/) {
	ASSERT (0 != nUpID);
	BOOL bReturn = m_bmpImage.LoadBitmap (nUpID);
	if (TRUE == bReturn) {
		m_bmpImage.GetObject (sizeof m_bmp, &m_bmp);
		m_nImageWidth = m_bmp.bmWidth;
		m_nImageHeight = m_bmp.bmHeight;
		if (NULL != m_imageList.m_hImageList) {
			m_imageList.Detach ();
		}
		bReturn = m_imageList.Create (m_nImageWidth, m_nImageHeight, ILC_MASK | ILC_COLOR32, 4, 0);
		if (TRUE == bReturn) {
			if (m_imageList.Add (&m_bmpImage, crUpMask) > -1) {
				m_bImageLoaded = TRUE;
				BOOL bOver = FALSE;
				// Add the Over image
				if (nOverID > 0) {
					AddBitmap (nOverID, crOverMask);
					bOver = TRUE;
				}
				else {
					// Use Up image if Over not supplied
					AddBitmap (nUpID, crUpMask);
				}
				// Add the Down image
				if (nDownID > 0) {
					AddBitmap (nDownID, crDownMask);
				}
				else {
					// If there's no Down image supplied
					if (TRUE == bOver) {
						// Use the Over image is supplied
						AddBitmap (nOverID, crOverMask);
					}
					else {
						// Otherwise use the Up image
						AddBitmap (nUpID, crUpMask);
					}
				}
				// Add the Disabled image
				// If one isn't one DrawState will use the Up image and draw it disabled.
				if (nDisabledID > 0) {
					AddBitmap (nDisabledID, crDisabledMask);
				}
			}
			else {
				m_bImageLoaded = FALSE;
			}
		}
	}


	// Resize the button if necessary
	if (SSL_BS_AUTOSIZE == (SSL_BS_AUTOSIZE & m_nStyle)) {
		SetSize ();
	}

	return bReturn;
}

BOOL CButtonSSL::SetSSLButtonIcon(UINT nResourceID) {
	BOOL bReturn = FALSE;
	HINSTANCE hInstance = AfxFindResourceHandle (MAKEINTRESOURCE (nResourceID), RT_GROUP_ICON);

	m_hIcon = (HICON)::LoadImage (hInstance, MAKEINTRESOURCE (nResourceID), IMAGE_ICON, 0, 0, 0);
	if (NULL != m_hIcon) {
		ICONINFO iconInfo;
		ZeroMemory (&iconInfo, sizeof (ICONINFO));
		bReturn = ::GetIconInfo (m_hIcon, &iconInfo);
		if (TRUE == bReturn) {
			m_nImageWidth = iconInfo.xHotspot * 2;
			m_nImageHeight = iconInfo.yHotspot * 2;
			::DeleteObject(iconInfo.hbmMask);
			::DeleteObject(iconInfo.hbmColor);
			if (NULL != m_imageList.m_hImageList) {
				m_imageList.Detach ();
			}
			bReturn = m_imageList.Create (m_nImageWidth, m_nImageHeight, ILC_MASK | ILC_COLOR32, 1, 1);
			if (TRUE == bReturn) {
				if (m_imageList.Add (m_hIcon) > -1) {
					m_bImageLoaded = TRUE;
				}
				else {
					m_bImageLoaded = FALSE;
				}
			}
		}
	}


	// Resize the button if necessary
	if (SSL_BS_AUTOSIZE == (SSL_BS_AUTOSIZE & m_nStyle)) {
		SetSize ();
	}

	return bReturn;
}

BOOL CButtonSSL::SetSSLButtonIcons (UINT nUpID, UINT nOverID/* = 0*/,
					   UINT nDownID/* = 0*/, UINT nDisabledID/* = 0*/) {
	ASSERT (0 != nUpID);
	BOOL bReturn = FALSE;
	HINSTANCE hInstance = AfxFindResourceHandle (MAKEINTRESOURCE (nUpID), RT_GROUP_ICON);

	m_hIcon = (HICON)::LoadImage (hInstance, MAKEINTRESOURCE (nUpID), IMAGE_ICON, 0, 0, 0);
	if (NULL != m_hIcon) {
		ICONINFO iconInfo;
		ZeroMemory (&iconInfo, sizeof (ICONINFO));
		bReturn = ::GetIconInfo (m_hIcon, &iconInfo);
		if (TRUE == bReturn) {
			m_nImageWidth = iconInfo.xHotspot * 2;
			m_nImageHeight = iconInfo.yHotspot * 2;
			::DeleteObject (iconInfo.hbmMask);
			::DeleteObject (iconInfo.hbmColor);
			if (NULL != m_imageList.m_hImageList) {
				m_imageList.Detach ();
			}
			bReturn = m_imageList.Create (m_nImageWidth, m_nImageHeight, ILC_MASK | ILC_COLOR32, 4, 0);
			if (TRUE == bReturn) {
				if (m_imageList.Add (m_hIcon) > -1) {
					m_bImageLoaded = TRUE;
					BOOL bOver = FALSE;
					// Add the Over image
					if (nOverID > 0) {
						AddIcon (nOverID);
						bOver = TRUE;
					}
					else {
						// Use Up image if Over not supplied
						AddIcon (nUpID);
					}
					// Add the Down image
					if (nDownID > 0) {
						AddIcon (nDownID);
					}
					else {
						// If there's no Down image supplied
						if (TRUE == bOver) {
							// Use the Over image is supplied
							AddIcon (nOverID);
						}
						else {
							// Otherwise use the Up image
							AddIcon (nUpID);
						}
					}
					// Add the Disabled image
					// If one isn't one DrawState will use the Up image and draw it disabled.
					if (nDisabledID > 0) {
						AddIcon (nDisabledID);
					}
				}
				else {
					m_bImageLoaded = FALSE;
				}
			}
		}
	}

	// Resize the button if necessary
	if (SSL_BS_AUTOSIZE == (SSL_BS_AUTOSIZE & m_nStyle)) {
		SetSize ();
	}

	return bReturn;
}

void CButtonSSL::SetSSLImageAlign (UINT nImageAlign) {
	m_nImageAlign = nImageAlign;
	Invalidate ();
}

UINT CButtonSSL::GetSSLImageAlign () {
	return m_nImageAlign;
}

/////////////////////////////////////////////////////////////////////////////
// Text Functions

void CButtonSSL::SetSSLTextAlign (UINT nTextAlign) {
	m_nTextAlign = nTextAlign;
	Invalidate ();
}

UINT CButtonSSL::GetSSLTextAlign () {
	return m_nTextAlign;
}

BOOL CButtonSSL::SetSSLButtonFont (LPCTSTR lpszFaceName, int nSizePoints/* = 8*/,
									BOOL bUnderline/* = FALSE*/, BOOL bBold/* = FALSE*/,
									BOOL bStrikeOut/* = FALSE*/, BOOL bItalic/* = FALSE*/) {
	if (NULL != (HFONT)m_font) {
		m_font.DeleteObject ();
	}

	CDC* pDC = GetDC ();
	LOGFONT lf;
	memset (&lf, 0, sizeof(LOGFONT));

	strcpy (lf.lfFaceName, lpszFaceName);
	lf.lfHeight = -MulDiv (nSizePoints, GetDeviceCaps (pDC->m_hDC, LOGPIXELSY), 72);
	lf.lfUnderline = bUnderline;
	if (TRUE == bBold) {
		lf.lfWeight = FW_BOLD;
	}
	lf.lfStrikeOut = bStrikeOut;
	lf.lfItalic = bItalic;

	BOOL bReturn = m_font.CreateFontIndirect (&lf);

	Invalidate ();
	ReleaseDC (pDC);

	return bReturn;
}

BOOL CButtonSSL::SetSSLButtonFont (CFont& font) {
	if (NULL != (HFONT)m_font) {
		m_font.DeleteObject ();
	}

	LOGFONT lf;
	font.GetLogFont (&lf);

	BOOL bReturn = m_font.CreateFontIndirect (&lf);

	Invalidate ();
	
	return bReturn;
}

/////////////////////////////////////////////////////////////////////////////
// Colour Functions

void CButtonSSL::SetSSLDefaultColors (BOOL bRedraw/* = TRUE*/) {
	m_crColors[SSL_UP_BK_COLOR]	= ::GetSysColor(COLOR_BTNFACE);
	m_crColors[SSL_UP_TEXT_COLOR]	= ::GetSysColor(COLOR_BTNTEXT);
	m_crColors[SSL_OVER_BK_COLOR]	= ::GetSysColor(COLOR_BTNFACE);
	m_crColors[SSL_OVER_TEXT_COLOR]	= ::GetSysColor(COLOR_BTNTEXT);
	m_crColors[SSL_DOWN_BK_COLOR]	= ::GetSysColor(COLOR_BTNFACE);
	m_crColors[SSL_DOWN_TEXT_COLOR]	= ::GetSysColor(COLOR_BTNTEXT);

	if (TRUE == bRedraw) {
		Invalidate();
	}
}

BOOL CButtonSSL::SetSSLColor (BYTE byColorIndex, COLORREF crColor, BOOL bRedraw/* = TRUE*/) {
	if (byColorIndex > SSL_MAX_COLORS) {
		return FALSE;
	}

	m_crColors[byColorIndex] = crColor;

	if (TRUE == bRedraw) {
		Invalidate ();
	}
	
	return TRUE;
}

BOOL CButtonSSL::GetSSLColor (BYTE byColorIndex, COLORREF* pcrColor) {
	if (byColorIndex > SSL_MAX_COLORS) {
		return FALSE;
	}

	*pcrColor = m_crColors[byColorIndex];

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// Check Box Functions

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -