| | |
| | | m_hIcon[0] = nullptr; |
| | | m_hIcon[1] = nullptr; |
| | | m_nIconWidth = 0; |
| | | m_nFlashState = 0; |
| | | } |
| | | |
| | | |
| | |
| | | if (BS_NORMAL <= index && index <= BS_DISABLE) { |
| | | m_crFrame[index] = color; |
| | | } |
| | | } |
| | | |
| | | void CBlButton::SetFrameColor(COLORREF color) |
| | | { |
| | | m_crFrame[BS_NORMAL] = color; |
| | | m_crFrame[BS_HOVER] = color; |
| | | m_crFrame[BS_PRESS] = color; |
| | | m_crFrame[BS_FOCUS] = color; |
| | | Invalidate(); |
| | | } |
| | | |
| | | void CBlButton::SetRoundWidth(int width) |
| | |
| | | m_nIconWidth = width; |
| | | } |
| | | |
| | | void CBlButton::Flash(int ms) |
| | | { |
| | | m_nFlashState = 1; |
| | | SetTimer(1, ms, nullptr); |
| | | } |
| | | |
| | | void CBlButton::StopFlash() |
| | | { |
| | | m_nFlashState = 0; |
| | | KillTimer(1); |
| | | Invalidate(); |
| | | } |
| | | |
| | | BOOL CBlButton::IsFlash() |
| | | { |
| | | return m_nFlashState != 0; |
| | | } |
| | | |
| | | void CBlButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) |
| | | { |
| | | HDC hDC = lpDrawItemStruct->hDC; |
| | |
| | | |
| | | // 边框+背景 |
| | | int state = GetDrawState(); |
| | | if (m_nFlashState != 0) { |
| | | if (state != BS_DISABLE) { |
| | | state = m_nFlashState == 1 ? BS_NORMAL : BS_PRESS; |
| | | } |
| | | } |
| | | HBRUSH hBrush = CreateSolidBrush(m_crBkgnd[state]); |
| | | HPEN hPen = CreatePen(PS_SOLID, state == BS_FOCUS ? 2 : 1, m_crFrame[state]); |
| | | HPEN hOldPen = (HPEN)::SelectObject(hDC, hPen); |
| | |
| | | |
| | | // 图标 |
| | | RECT rcText = rcClient; |
| | | if (m_hIcon != nullptr) { |
| | | HICON hIcon = this->IsWindowEnabled() ? m_hIcon[0] : m_hIcon[01]; |
| | | if (hIcon != nullptr) { |
| | | int xIcon = (rcClient.right - rcClient.top - m_nIconWidth) / 2; |
| | | if (m_hMenu != nullptr) xIcon -= 10; |
| | | int yIcon = (rcClient.bottom - rcClient.top - m_nIconWidth) / 2; |
| | |
| | | } |
| | | |
| | | DrawIconEx(hDC, xIcon, yIcon, |
| | | this->IsWindowEnabled() ? m_hIcon[0] : m_hIcon[01], m_nIconWidth, m_nIconWidth, 0, 0, DI_NORMAL); |
| | | hIcon, m_nIconWidth, m_nIconWidth, 0, 0, DI_NORMAL); |
| | | rcText.top = yIcon + m_nIconWidth + 2; |
| | | } |
| | | |
| | | |
| | | // 文本 |
| | | HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); |
| | | CFont* pFont = GetFont(); |
| | | if (pFont != nullptr) { |
| | | hFont = (HFONT)pFont->GetSafeHandle(); |
| | | } |
| | | |
| | | |
| | | ::SelectObject(hDC, hFont); |
| | | ::SetBkMode(hDC, TRANSPARENT); |
| | |
| | | ON_WM_LBUTTONDOWN() |
| | | ON_CONTROL_REFLECT_EX(BN_CLICKED, &CBlButton::OnBnClicked) |
| | | ON_WM_LBUTTONUP() |
| | | ON_WM_TIMER() |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | |
| | | blbNmhdr.dwData2 = dwData2; |
| | | pParent->SendMessage(WM_NOTIFY, (WPARAM)blbNmhdr.nmhdr.idFrom, (LPARAM)&blbNmhdr); |
| | | } |
| | | } |
| | | } |
| | | |
| | | void CBlButton::OnTimer(UINT_PTR nIDEvent) |
| | | { |
| | | if (1 == nIDEvent) { |
| | | m_nFlashState++; |
| | | if (m_nFlashState > 2) m_nFlashState = 1; |
| | | Invalidate(); |
| | | } |
| | | |
| | | CButton::OnTimer(nIDEvent); |
| | | } |