From 829fe6c6bc33d53fda9c31fd45a37e1df87befff Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期五, 30 一月 2026 11:16:24 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang
---
SourceCode/Bond/Servo/HmLabel.cpp | 177 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 177 insertions(+), 0 deletions(-)
diff --git a/SourceCode/Bond/Servo/HmLabel.cpp b/SourceCode/Bond/Servo/HmLabel.cpp
new file mode 100644
index 0000000..c60cacb
--- /dev/null
+++ b/SourceCode/Bond/Servo/HmLabel.cpp
@@ -0,0 +1,177 @@
+#include "stdafx.h"
+#include "HmLabel.h"
+
+
+CHmLabel::CHmLabel()
+{
+ m_crFrame = RGB(128, 128, 128);
+ m_crBackground = RGB(255, 0, 0);
+ m_crForeground = RGB(255, 255, 255);
+ m_hFont = NULL;
+ m_hFontNote = NULL;
+}
+
+
+CHmLabel::~CHmLabel()
+{
+ if (m_hFont != NULL) {
+ ::DeleteObject(m_hFont);
+ m_hFont = NULL;
+ }
+
+ if (m_hFontNote != NULL) {
+ ::DeleteObject(m_hFontNote);
+ m_hFontNote = NULL;
+ }
+}
+
+BEGIN_MESSAGE_MAP(CHmLabel, CStatic)
+ ON_WM_PAINT()
+ ON_WM_NCPAINT()
+END_MESSAGE_MAP()
+
+void CHmLabel::setText(CString strText)
+{
+ SetWindowText(strText);
+ Invalidate();
+}
+
+void CHmLabel::setNote1(CString strNote1)
+{
+ m_strNote1 = strNote1;
+}
+
+void CHmLabel::setFontSize(int size)
+{
+ if (m_hFont != NULL) {
+ ::DeleteObject(m_hFont);
+ m_hFont = NULL;
+ }
+
+ m_hFont = CreateFont(size, 0, 0, 0, FW_MEDIUM,
+ FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS,
+ CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, _T("宋体"));
+}
+
+void CHmLabel::setNoteFontSize(int size)
+{
+ if (m_hFontNote != NULL) {
+ ::DeleteObject(m_hFontNote);
+ m_hFontNote = NULL;
+ }
+
+ m_hFontNote = CreateFont(size, 0, 0, 0, FW_MEDIUM,
+ FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS,
+ CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, _T("宋体"));
+}
+
+void CHmLabel::setNoteTextColor(COLORREF color, BOOL bInvalidate/* = FALSE*/)
+{
+ m_crNote = color;
+ if (bInvalidate) Invalidate(TRUE);
+}
+
+void CHmLabel::setBackground(COLORREF color, BOOL bInvalidate/* = FALSE*/)
+{
+ m_crBackground = color;
+ if (bInvalidate) Invalidate(TRUE);
+}
+
+void CHmLabel::setForeground(COLORREF color, BOOL bInvalidate/* = FALSE*/)
+{
+ m_crForeground = color;
+ if (bInvalidate) Invalidate(TRUE);
+}
+
+void CHmLabel::OnPaint()
+{
+ CPaintDC dc(this); // device context for painting
+ // TODO: 在此处添加消息处理程序代码
+ // 不为绘图消息调用 CStatic::OnPaint()
+
+
+ HDC hMemDC;
+ HBITMAP hBitmap;
+ RECT rcClient;
+ CString strText;
+ HBRUSH hBrushBK;
+
+
+ GetClientRect(&rcClient);
+ hMemDC = ::CreateCompatibleDC(dc.m_hDC);
+ hBitmap = ::CreateCompatibleBitmap(dc.m_hDC, rcClient.right - rcClient.left,
+ rcClient.bottom - rcClient.top);
+ ::SelectObject(hMemDC, hBitmap);
+
+
+ // 背景颜色
+ hBrushBK = CreateSolidBrush(m_crBackground);
+ ::FillRect(hMemDC, &rcClient, hBrushBK);
+ DeleteObject(hBrushBK);
+
+
+ // 文字
+ char szText[256];
+ GetWindowText(szText, 256);
+ RECT rcText = rcClient;
+ SetBkMode(hMemDC, TRANSPARENT);
+ SetTextColor(hMemDC, m_crForeground);
+ ::SelectObject(hMemDC, m_hFont == NULL ? (HFONT)GetStockObject(DEFAULT_GUI_FONT) : m_hFont);
+ ::DrawTextA(hMemDC, szText, (int)strlen(szText), &rcText, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
+
+
+ // Note1
+ SetTextColor(hMemDC, m_crNote);
+ ::SelectObject(hMemDC, m_hFontNote == NULL ? (HFONT)GetStockObject(DEFAULT_GUI_FONT) : m_hFontNote);
+ ::DrawText(hMemDC, m_strNote1, m_strNote1.GetLength(), &rcClient, DT_CENTER | DT_BOTTOM | DT_SINGLELINE | DT_END_ELLIPSIS);
+
+
+ // EndPaint
+ ::BitBlt(dc.m_hDC, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top,
+ hMemDC, 0, 0, SRCCOPY);
+ ::DeleteObject(hBitmap);
+ ::DeleteDC(hMemDC);
+}
+
+
+void CHmLabel::OnNcPaint()
+{
+ // TODO: 在此处添加消息处理程序代码
+ // 不为绘图消息调用 CStatic::OnNcPaint()
+ long styleEx = GetWindowLong(m_hWnd, GWL_EXSTYLE);
+ if ((styleEx & WS_EX_CLIENTEDGE) == WS_EX_CLIENTEDGE) {
+
+ RECT rect, rcClient;
+ GetClientRect(&rcClient);
+ ::ClientToScreen(m_hWnd, (LPPOINT)&rcClient.left);
+ ::ClientToScreen(m_hWnd, (LPPOINT)&rcClient.right);
+ GetWindowRect(&rect);
+ ::OffsetRect(&rcClient, -rect.left, -rect.top);
+
+ rect.right -= rect.left;
+ rect.bottom -= rect.top;
+ rect.left = 0;
+ rect.top = 0;
+
+ HRGN hRgnWnd = CreateRectRgnIndirect(&rect);
+ HRGN hRgnClient = CreateRectRgnIndirect(&rcClient);
+
+ HBRUSH hBrushBK, hBrushFrame;
+ HDC hDC = ::GetWindowDC(m_hWnd);
+ ::SelectClipRgn(hDC, hRgnWnd);
+ ::ExtSelectClipRgn(hDC, hRgnClient, RGN_DIFF);
+
+ hBrushBK = CreateSolidBrush(m_crBackground);
+ ::FillRect(hDC, &rect, hBrushBK);
+ DeleteObject(hBrushBK);
+
+ hBrushFrame = CreateSolidBrush(m_crFrame);
+ ::FrameRect(hDC, &rect, hBrushFrame);
+
+ ::DeleteObject(hRgnWnd);
+ ::DeleteObject(hRgnClient);
+ DeleteObject(hBrushFrame);
+ ::ReleaseDC(m_hWnd, hDC);
+ }
+}
+
--
Gitblit v1.9.3