From 52a552985f1ef1cdaef18dbdb29722581e507f48 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期五, 06 十二月 2024 17:58:31 +0800
Subject: [PATCH] 1.实现按钮闪烁功能;
---
SourceCode/Bond/BondEq/BlButton.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/SourceCode/Bond/BondEq/BlButton.cpp b/SourceCode/Bond/BondEq/BlButton.cpp
index 289e020..4e31082 100644
--- a/SourceCode/Bond/BondEq/BlButton.cpp
+++ b/SourceCode/Bond/BondEq/BlButton.cpp
@@ -35,6 +35,7 @@
m_hIcon[0] = nullptr;
m_hIcon[1] = nullptr;
m_nIconWidth = 0;
+ m_nFlashState = 0;
}
@@ -47,6 +48,15 @@
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)
@@ -131,6 +141,18 @@
m_nIconWidth = width;
}
+void CBlButton::Flash(int ms)
+{
+ m_nFlashState = 1;
+ SetTimer(1, ms, nullptr);
+}
+
+void CBlButton::StopFlash()
+{
+ m_nFlashState = 0;
+ KillTimer(1);
+}
+
void CBlButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
HDC hDC = lpDrawItemStruct->hDC;
@@ -140,6 +162,11 @@
// 边框+背景
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);
@@ -164,7 +191,8 @@
// 图标
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;
@@ -173,13 +201,18 @@
}
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);
@@ -279,6 +312,7 @@
ON_WM_LBUTTONDOWN()
ON_CONTROL_REFLECT_EX(BN_CLICKED, &CBlButton::OnBnClicked)
ON_WM_LBUTTONUP()
+ ON_WM_TIMER()
END_MESSAGE_MAP()
@@ -445,4 +479,15 @@
blbNmhdr.dwData2 = dwData2;
pParent->SendMessage(WM_NOTIFY, (WPARAM)blbNmhdr.nmhdr.idFrom, (LPARAM)&blbNmhdr);
}
-}
\ No newline at end of file
+}
+
+void CBlButton::OnTimer(UINT_PTR nIDEvent)
+{
+ if (1 == nIDEvent) {
+ m_nFlashState++;
+ if (m_nFlashState > 2) m_nFlashState = 1;
+ Invalidate();
+ }
+
+ CButton::OnTimer(nIDEvent);
+}
--
Gitblit v1.9.3