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.h | 5 +
SourceCode/Bond/BondEq/View/AxisSettingsDlg.h | 16 +++
SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp | 80 +++++++++++---------
Document/Bond软件开发进度表.xlsx | 0
SourceCode/Bond/BondEq/BlButton.cpp | 51 ++++++++++++
SourceCode/Bond/BondEq/Common.h | 42 ++++++++++
6 files changed, 154 insertions(+), 40 deletions(-)
diff --git "a/Document/Bond\350\275\257\344\273\266\345\274\200\345\217\221\350\277\233\345\272\246\350\241\250.xlsx" "b/Document/Bond\350\275\257\344\273\266\345\274\200\345\217\221\350\277\233\345\272\246\350\241\250.xlsx"
index 7a4d235..e92b5b0 100644
--- "a/Document/Bond\350\275\257\344\273\266\345\274\200\345\217\221\350\277\233\345\272\246\350\241\250.xlsx"
+++ "b/Document/Bond\350\275\257\344\273\266\345\274\200\345\217\221\350\277\233\345\272\246\350\241\250.xlsx"
Binary files differ
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);
+}
diff --git a/SourceCode/Bond/BondEq/BlButton.h b/SourceCode/Bond/BondEq/BlButton.h
index 4415a8b..5b9d5ca 100644
--- a/SourceCode/Bond/BondEq/BlButton.h
+++ b/SourceCode/Bond/BondEq/BlButton.h
@@ -38,6 +38,7 @@
void SetRoundWidth(int width);
int GetDrawState();
void SetFrameColor(int index, COLORREF color);
+ void SetFrameColor(COLORREF color);
void SetBkgndColor(int index, COLORREF color);
void SetTextColor(int index, COLORREF color);
void SetBkgndBmp(const char* pszBmpFile);
@@ -49,6 +50,8 @@
void SetCurrentMenuItem(UINT nPosition);
HMENU GetMenu();
void SetIcon(HICON hIcon, HICON hIconGray, int width);
+ void Flash(int ms);
+ void StopFlash();
private:
BOOL CustomBitBlt(HDC hDC, LPRECT lprc, CString& strBkgndBmp, int nFrame, int nAllFrame,
@@ -73,6 +76,7 @@
HMENU m_hMenu;
HICON m_hIcon[2];
int m_nIconWidth;
+ int m_nFlashState; // 闪烁状态,0:不闪;1和2为闪烁切换中
public:
virtual void DrawItem(LPDRAWITEMSTRUCT /*lpDrawItemStruct*/);
@@ -84,5 +88,6 @@
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg BOOL OnBnClicked();
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
+ afx_msg void OnTimer(UINT_PTR nIDEvent);
};
diff --git a/SourceCode/Bond/BondEq/Common.h b/SourceCode/Bond/BondEq/Common.h
index 000ad4b..5560bbf 100644
--- a/SourceCode/Bond/BondEq/Common.h
+++ b/SourceCode/Bond/BondEq/Common.h
@@ -89,6 +89,48 @@
#define BTN1_TEXT_FOCUS RGB(51, 51, 51)
#define BTN1_TEXT_DISABLE RGB(191, 191, 191)
+
+/* 轴设定页面颜色定义 */
+
+/* 5个按钮页, 按钮背景色,正常状态*/
+#define BTN_PAGE_FACE_NORMAL_COLOR RGB(240, 240, 240)
+#define BTN_PAGE_FACE_SELECT_COLOR RGB(0, 122, 204)
+#define BTN_PAGE_TEXT_NORMAL_COLOR RGB(22, 22, 22)
+#define BTN_PAGE_TEXT_SELECT_COLOR RGB(222, 222, 222)
+
+/* JOG+, JOG-*/
+#define BTN_JOG_FRAME_NORMAL RGB(88, 88, 88)
+#define BTN_JOG_FRAME_HOVER RGB(88, 88, 88)
+#define BTN_JOG_FRAME_PRESS RGB(88, 88, 88)
+#define BTN_JOG_BKGND_NORMAL RGB(0, 232, 0)
+#define BTN_JOG_BKGND_HOVER RGB(0, 222, 0)
+#define BTN_JOG_BKGND_PRESS RGB(0, 168, 0)
+
+/* Sev按钮 */
+#define BTN_SEV_FRAME_NORMAL RGB(88, 88, 88)
+#define BTN_SEV_FRAME_HOVER RGB(88, 88, 88)
+#define BTN_SEV_FRAME_PRESS RGB(88, 88, 88)
+#define BTN_SEV_BKGND_NORMAL RGB(0, 232, 0)
+#define BTN_SEV_BKGND_HOVER RGB(0, 222, 0)
+#define BTN_SEV_BKGND_PRESS RGB(222, 0, 0)
+
+/* Stop按钮 */
+#define BTN_STOP_FRAME_NORMAL RGB(88, 88, 88)
+#define BTN_STOP_FRAME_HOVER RGB(88, 88, 88)
+#define BTN_STOP_FRAME_PRESS RGB(88, 88, 88)
+#define BTN_STOP_BKGND_NORMAL RGB(0, 168, 0)
+#define BTN_STOP_BKGND_HOVER RGB(0, 138, 0)
+#define BTN_STOP_BKGND_PRESS RGB(222, 0, 0)
+
+/* OPR 按钮 */
+#define BTN_OPR_FRAME_NORMAL RGB(88, 88, 88)
+#define BTN_OPR_FRAME_HOVER RGB(88, 88, 88)
+#define BTN_OPR_FRAME_PRESS RGB(88, 88, 88)
+#define BTN_OPR_BKGND_NORMAL RGB(222, 222, 222)
+#define BTN_OPR_BKGND_HOVER RGB(208, 208, 222)
+#define BTN_OPR_BKGND_PRESS RGB(0, 232, 0)
+
+
/* 按钮id */
#define VIEW_TOOL_BTN_CLOSE 0x1016
diff --git a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
index 8e82048..adc83f2 100644
--- a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
+++ b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
@@ -40,7 +40,7 @@
m_bReady = FALSE;
m_bBusy = FALSE;
m_bErr = FALSE;
- for (int i = 0; i < 9; i++) {
+ for (int i = 0; i < BTN_MAX; i++) {
m_pBlBtns[i] = new CBlButton();
}
}
@@ -55,7 +55,7 @@
}
m_mapFonts.clear();
- for (int i = 0; i < 9; i++) {
+ for (int i = 0; i < BTN_MAX; i++) {
delete m_pBlBtns[i];
}
}
@@ -733,40 +733,46 @@
}
// 鎸夐挳鍒濆鍖�
- m_pBlBtns[0]->SubclassDlgItem(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP1, this);
- m_pBlBtns[1]->SubclassDlgItem(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP2, this);
- m_pBlBtns[2]->SubclassDlgItem(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP3, this);
- m_pBlBtns[3]->SubclassDlgItem(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP4, this);
- m_pBlBtns[4]->SubclassDlgItem(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP5, this);
- m_pBlBtns[5]->SubclassDlgItem(IDC_BUTTON_AXIS_TEST_JOG_ADD, this);
- m_pBlBtns[5]->SetFrameColor(BS_NORMAL, BTN_JOG_FRAME_NORMAL);
- m_pBlBtns[5]->SetFrameColor(BS_HOVER, BTN_JOG_FRAME_HOVER);
- m_pBlBtns[5]->SetFrameColor(BS_PRESS, BTN_JOG_FRAME_PRESS);
- m_pBlBtns[5]->SetBkgndColor(BS_NORMAL, BTN_JOG_BKGND_NORMAL);
- m_pBlBtns[5]->SetBkgndColor(BS_HOVER, BTN_JOG_BKGND_HOVER);
- m_pBlBtns[5]->SetBkgndColor(BS_PRESS, BTN_JOG_BKGND_PRESS);
- m_pBlBtns[6]->SubclassDlgItem(IDC_BUTTON_AXIS_TEST_JOG_SUB, this);
- m_pBlBtns[6]->SetFrameColor(BS_NORMAL, BTN_JOG_FRAME_NORMAL);
- m_pBlBtns[6]->SetFrameColor(BS_HOVER, BTN_JOG_FRAME_HOVER);
- m_pBlBtns[6]->SetFrameColor(BS_PRESS, BTN_JOG_FRAME_PRESS);
- m_pBlBtns[6]->SetBkgndColor(BS_NORMAL, BTN_JOG_BKGND_NORMAL);
- m_pBlBtns[6]->SetBkgndColor(BS_HOVER, BTN_JOG_BKGND_HOVER);
- m_pBlBtns[6]->SetBkgndColor(BS_PRESS, BTN_JOG_BKGND_PRESS);
- m_pBlBtns[7]->SubclassDlgItem(IDC_BUTTON_AXIS_SEV, this);
- m_pBlBtns[7]->SetFrameColor(BS_NORMAL, BTN_SEV_FRAME_NORMAL);
- m_pBlBtns[7]->SetFrameColor(BS_HOVER, BTN_SEV_FRAME_HOVER);
- m_pBlBtns[7]->SetFrameColor(BS_PRESS, BTN_SEV_FRAME_PRESS);
- m_pBlBtns[7]->SetBkgndColor(BS_NORMAL, BTN_SEV_BKGND_NORMAL);
- m_pBlBtns[7]->SetBkgndColor(BS_HOVER, BTN_SEV_BKGND_HOVER);
- m_pBlBtns[7]->SetBkgndColor(BS_PRESS, BTN_SEV_BKGND_PRESS);
- m_pBlBtns[8]->SubclassDlgItem(IDC_BUTTON_AXIS_TEST_STOP, this);
- m_pBlBtns[8]->SetFrameColor(BS_NORMAL, BTN_STOP_FRAME_NORMAL);
- m_pBlBtns[8]->SetFrameColor(BS_HOVER, BTN_STOP_FRAME_HOVER);
- m_pBlBtns[8]->SetFrameColor(BS_PRESS, BTN_STOP_FRAME_PRESS);
- m_pBlBtns[8]->SetBkgndColor(BS_NORMAL, BTN_STOP_BKGND_NORMAL);
- m_pBlBtns[8]->SetBkgndColor(BS_HOVER, BTN_STOP_BKGND_HOVER);
- m_pBlBtns[8]->SetBkgndColor(BS_PRESS, BTN_STOP_BKGND_PRESS);
-
+ m_pBlBtns[BTN_PAGE1]->SubclassDlgItem(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP1, this);
+ m_pBlBtns[BTN_PAGE2]->SubclassDlgItem(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP2, this);
+ m_pBlBtns[BTN_PAGE3]->SubclassDlgItem(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP3, this);
+ m_pBlBtns[BTN_PAGE4]->SubclassDlgItem(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP4, this);
+ m_pBlBtns[BTN_PAGE5]->SubclassDlgItem(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP5, this);
+ m_pBlBtns[BTN_JOG_ADD]->SubclassDlgItem(IDC_BUTTON_AXIS_TEST_JOG_ADD, this);
+ m_pBlBtns[BTN_JOG_ADD]->SetFrameColor(BS_NORMAL, BTN_JOG_FRAME_NORMAL);
+ m_pBlBtns[BTN_JOG_ADD]->SetFrameColor(BS_HOVER, BTN_JOG_FRAME_HOVER);
+ m_pBlBtns[BTN_JOG_ADD]->SetFrameColor(BS_PRESS, BTN_JOG_FRAME_PRESS);
+ m_pBlBtns[BTN_JOG_ADD]->SetBkgndColor(BS_NORMAL, BTN_JOG_BKGND_NORMAL);
+ m_pBlBtns[BTN_JOG_ADD]->SetBkgndColor(BS_HOVER, BTN_JOG_BKGND_HOVER);
+ m_pBlBtns[BTN_JOG_ADD]->SetBkgndColor(BS_PRESS, BTN_JOG_BKGND_PRESS);
+ m_pBlBtns[BTN_JOG_SUB]->SubclassDlgItem(IDC_BUTTON_AXIS_TEST_JOG_SUB, this);
+ m_pBlBtns[BTN_JOG_SUB]->SetFrameColor(BS_NORMAL, BTN_JOG_FRAME_NORMAL);
+ m_pBlBtns[BTN_JOG_SUB]->SetFrameColor(BS_HOVER, BTN_JOG_FRAME_HOVER);
+ m_pBlBtns[BTN_JOG_SUB]->SetFrameColor(BS_PRESS, BTN_JOG_FRAME_PRESS);
+ m_pBlBtns[BTN_JOG_SUB]->SetBkgndColor(BS_NORMAL, BTN_JOG_BKGND_NORMAL);
+ m_pBlBtns[BTN_JOG_SUB]->SetBkgndColor(BS_HOVER, BTN_JOG_BKGND_HOVER);
+ m_pBlBtns[BTN_JOG_SUB]->SetBkgndColor(BS_PRESS, BTN_JOG_BKGND_PRESS);
+ m_pBlBtns[BTN_JOG_SEV]->SubclassDlgItem(IDC_BUTTON_AXIS_SEV, this);
+ m_pBlBtns[BTN_JOG_SEV]->SetFrameColor(BS_NORMAL, BTN_SEV_FRAME_NORMAL);
+ m_pBlBtns[BTN_JOG_SEV]->SetFrameColor(BS_HOVER, BTN_SEV_FRAME_HOVER);
+ m_pBlBtns[BTN_JOG_SEV]->SetFrameColor(BS_PRESS, BTN_SEV_FRAME_PRESS);
+ m_pBlBtns[BTN_JOG_SEV]->SetBkgndColor(BS_NORMAL, BTN_SEV_BKGND_NORMAL);
+ m_pBlBtns[BTN_JOG_SEV]->SetBkgndColor(BS_HOVER, BTN_SEV_BKGND_HOVER);
+ m_pBlBtns[BTN_JOG_SEV]->SetBkgndColor(BS_PRESS, BTN_SEV_BKGND_PRESS);
+ m_pBlBtns[BTN_JOG_STOP]->SubclassDlgItem(IDC_BUTTON_AXIS_TEST_STOP, this);
+ m_pBlBtns[BTN_JOG_STOP]->SetFrameColor(BS_NORMAL, BTN_STOP_FRAME_NORMAL);
+ m_pBlBtns[BTN_JOG_STOP]->SetFrameColor(BS_HOVER, BTN_STOP_FRAME_HOVER);
+ m_pBlBtns[BTN_JOG_STOP]->SetFrameColor(BS_PRESS, BTN_STOP_FRAME_PRESS);
+ m_pBlBtns[BTN_JOG_STOP]->SetBkgndColor(BS_NORMAL, BTN_STOP_BKGND_NORMAL);
+ m_pBlBtns[BTN_JOG_STOP]->SetBkgndColor(BS_HOVER, BTN_STOP_BKGND_HOVER);
+ m_pBlBtns[BTN_JOG_STOP]->SetBkgndColor(BS_PRESS, BTN_STOP_BKGND_PRESS);
+ m_pBlBtns[BTN_JOG_OPR]->SubclassDlgItem(IDC_BUTTON_AXIS_TEST_OPR, this);
+ m_pBlBtns[BTN_JOG_OPR]->SetFrameColor(BS_NORMAL, BTN_OPR_FRAME_NORMAL);
+ m_pBlBtns[BTN_JOG_OPR]->SetFrameColor(BS_HOVER, BTN_OPR_FRAME_HOVER);
+ m_pBlBtns[BTN_JOG_OPR]->SetFrameColor(BS_PRESS, BTN_OPR_FRAME_PRESS);
+ m_pBlBtns[BTN_JOG_OPR]->SetBkgndColor(BS_NORMAL, BTN_OPR_BKGND_NORMAL);
+ m_pBlBtns[BTN_JOG_OPR]->SetBkgndColor(BS_HOVER, BTN_OPR_BKGND_HOVER);
+ m_pBlBtns[BTN_JOG_OPR]->SetBkgndColor(BS_PRESS, BTN_OPR_BKGND_PRESS);
// 鍒濆鍖栧綋鍓嶉〉闈负绗竴椤�
m_currentPage = 1;
@@ -1008,6 +1014,7 @@
handleAxisOperation(AxisOperationType::OPR, true);
Sleep(200);
handleAxisOperation(AxisOperationType::OPR, false);
+ m_pBlBtns[BTN_JOG_OPR]->Flash(1000);
}
void CAxisSettingsDlg::OnBnClickedButtonAxisTestStop()
@@ -1016,6 +1023,7 @@
handleAxisOperation(AxisOperationType::STOP, true);
Sleep(200);
handleAxisOperation(AxisOperationType::STOP, false);
+ m_pBlBtns[BTN_JOG_OPR]->StopFlash();
}
void CAxisSettingsDlg::OnSelchangeComboAxisName()
diff --git a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.h b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.h
index d7aef3a..e23daaa 100644
--- a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.h
+++ b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.h
@@ -4,6 +4,20 @@
#include "BLLabel.h"
#include "CPLC.h"
+
+#define BTN_MAX 10
+#define BTN_PAGE1 0
+#define BTN_PAGE2 1
+#define BTN_PAGE3 2
+#define BTN_PAGE4 3
+#define BTN_PAGE5 4
+#define BTN_JOG_ADD 5
+#define BTN_JOG_SUB 6
+#define BTN_JOG_SEV 7
+#define BTN_JOG_STOP 8
+#define BTN_JOG_OPR 9
+
+
// CAxisSettingsDlg 瀵硅瘽妗�
enum class AxisOperationType {
@@ -74,7 +88,7 @@
CStatic m_staticAxisNO, m_staticAxisDescription, m_staticStartAddress;
CEdit m_editManualSpeed, m_editAutoSpeed, m_editAccelerationTime, m_editDecelerationTime, m_editJogDistance;
- CBlButton* m_pBlBtns[9];
+ CBlButton* m_pBlBtns[BTN_MAX];
std::map<int, CRect> m_mapCtrlLayouts;
std::map<int, CFont*> m_mapFonts;
--
Gitblit v1.9.3