LAPTOP-SNT8I5JK\Boounion
2025-07-28 bfe14e41fa5b07771d78af4511ba18d706bc23cc
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,24 @@
   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;
@@ -140,6 +168,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 +197,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 +207,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 +318,7 @@
   ON_WM_LBUTTONDOWN()
   ON_CONTROL_REFLECT_EX(BN_CLICKED, &CBlButton::OnBnClicked)
   ON_WM_LBUTTONUP()
   ON_WM_TIMER()
END_MESSAGE_MAP()
@@ -445,4 +485,15 @@
      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);
}