From e8a27bb203fe2aff70390a5eca002d7438da9b0f Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期三, 22 十月 2025 14:24:34 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang
---
SourceCode/Bond/Servo/GroupLabel.cpp | 275 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 275 insertions(+), 0 deletions(-)
diff --git a/SourceCode/Bond/Servo/GroupLabel.cpp b/SourceCode/Bond/Servo/GroupLabel.cpp
new file mode 100644
index 0000000..57f31d0
--- /dev/null
+++ b/SourceCode/Bond/Servo/GroupLabel.cpp
@@ -0,0 +1,275 @@
+#include "stdafx.h"
+#include "GroupLabel.h"
+
+
+CGroupLabel::CGroupLabel()
+{
+ m_crBkgnd = RGB(255, 255, 255);
+ m_crLine = RGB(188, 188, 188);
+ m_crText = RGB(88, 88, 88);
+ m_nPadding[PADDING_LEFT] = 5;
+ m_nPadding[PADDING_TOP] = 5;
+ m_nPadding[PADDING_RIGHT] = 5;
+ m_nPadding[PADDING_BOTTOM] = 5;
+ m_nTextAlign = TEXT_ALIGN_CENTER;
+ m_bEnableResize = FALSE;
+}
+
+
+CGroupLabel::~CGroupLabel()
+{
+}
+BEGIN_MESSAGE_MAP(CGroupLabel, CStatic)
+ ON_WM_PAINT()
+ ON_WM_LBUTTONDOWN()
+ ON_WM_SETCURSOR()
+END_MESSAGE_MAP()
+
+
+void CGroupLabel::EnableResize()
+{
+ m_bEnableResize = TRUE;
+
+ DWORD dwStyle = GetStyle();
+ dwStyle |= SS_NOTIFY;
+ SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle);
+}
+
+void CGroupLabel::DisableResize()
+{
+ m_bEnableResize = FALSE;
+}
+
+void CGroupLabel::OnPaint()
+{
+ CPaintDC dc(this); // device context for painting
+ // TODO: 在此处添加消息处理程序代码
+ // 不为绘图消息调用 CStatic::OnPaint()
+
+
+ HDC hMemDC;
+ HBITMAP hBitmap;
+ RECT rcClient;
+ CString strText;
+ HFONT hFont;
+ HBRUSH hBrushBK;
+
+
+ ::GetClientRect(m_hWnd, &rcClient);
+ hMemDC = ::CreateCompatibleDC(dc.m_hDC);
+ hBitmap = ::CreateCompatibleBitmap(dc.m_hDC, rcClient.right - rcClient.left,
+ rcClient.bottom - rcClient.top);
+ ::SelectObject(hMemDC, hBitmap);
+ ::SetBkMode(hMemDC, TRANSPARENT);
+
+
+ // 背景颜色
+ hBrushBK = CreateSolidBrush(m_crBkgnd);
+ ::FillRect(hMemDC, &rcClient, hBrushBK);
+ DeleteObject(hBrushBK);
+
+
+ // 窗口标题
+ int x1, x2, x3, x4;
+ x1 = rcClient.left + m_nPadding[PADDING_LEFT];
+ x4 = rcClient.right - m_nPadding[PADDING_RIGHT];
+ hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
+ ::SelectObject(hMemDC, hFont);
+ ::SetTextColor(hMemDC, m_crText);
+ char szTitle[256];
+ int nTextLen = ::GetWindowText(m_hWnd, szTitle, 256);
+ if (nTextLen > 0) {
+ RECT rcTitle;
+ SIZE sizeText;
+
+ rcTitle.left = x1;
+ rcTitle.top = rcClient.top + 2;
+ rcTitle.bottom = rcClient.bottom - 2;
+ rcTitle.right = x4;
+
+#define TEXT_SPAGE 12
+ GetTextExtentPoint32(hMemDC, szTitle, nTextLen, &sizeText);
+ if (TEXT_ALIGN_LEFT == m_nTextAlign) {
+ ::DrawText(hMemDC, szTitle, nTextLen, &rcTitle, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
+ x1 += sizeText.cx + TEXT_SPAGE;
+ }
+ else if (TEXT_ALIGN_CENTER == m_nTextAlign) {
+ ::DrawText(hMemDC, szTitle, nTextLen, &rcTitle, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
+ x2 = x1 + (x4 - x1 - sizeText.cx - TEXT_SPAGE * 2) / 2;
+ x3 = x2 + sizeText.cx + TEXT_SPAGE * 2;
+ }
+ else {
+ ::DrawText(hMemDC, szTitle, nTextLen, &rcTitle, DT_RIGHT | DT_VCENTER | DT_SINGLELINE);
+ x4 -= (sizeText.cx + TEXT_SPAGE);
+ }
+
+
+ }
+
+
+ // 分隔线
+ HPEN hPen = CreatePen(PS_SOLID, 1, m_crLine);
+ HPEN hOldPen = (HPEN)SelectObject(hMemDC, hPen);
+ int y = (rcClient.bottom - rcClient.top) / 2;
+
+ if (TEXT_ALIGN_LEFT == m_nTextAlign) {
+ ::MoveToEx(hMemDC, x1, y, NULL);
+ ::LineTo(hMemDC, x4, y);
+ }
+ else if (TEXT_ALIGN_CENTER == m_nTextAlign) {
+ ::MoveToEx(hMemDC, x1, y, NULL);
+ ::LineTo(hMemDC, x2, y);
+ ::MoveToEx(hMemDC, x3, y, NULL);
+ ::LineTo(hMemDC, x4, y);
+ }
+ else {
+ ::MoveToEx(hMemDC, x1, y, NULL);
+ ::LineTo(hMemDC, x4, y);
+ }
+
+ SelectObject(hMemDC, hOldPen);
+ ::DeleteObject(hPen);
+
+
+ // EndPaint
+ ::BitBlt(dc.m_hDC, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top,
+ hMemDC, 0, 0, SRCCOPY);
+ ::DeleteObject(hBitmap);
+ ::DeleteDC(hMemDC);
+}
+
+void CGroupLabel::SetTextAlignMode(int nAlign)
+{
+ if (nAlign == TEXT_ALIGN_LEFT || nAlign == TEXT_ALIGN_CENTER || nAlign == TEXT_ALIGN_RIGHT) {
+ m_nTextAlign = nAlign;
+
+ RECT rcClient;
+ ::GetClientRect(m_hWnd, &rcClient);
+ ::InvalidateRect(m_hWnd, &rcClient, TRUE);
+ }
+}
+
+void CGroupLabel::Setpadding(int type, unsigned int nPadding)
+{
+ if (type >= PADDING_LEFT && PADDING_LEFT <= PADDING_BOTTOM) {
+ m_nPadding[type] = nPadding;
+ }
+}
+
+/*
+ * 设置背景色
+ * color -- 背景色
+ */
+void CGroupLabel::SetBkgndColor(COLORREF color)
+{
+ m_crBkgnd = color;
+}
+
+/*
+ * 设置文本色
+ * color -- 背景色
+ */
+void CGroupLabel::SetTextColor(COLORREF color)
+{
+ m_crText = color;
+
+ RECT rcClient;
+ ::GetClientRect(m_hWnd, &rcClient);
+ ::InvalidateRect(m_hWnd, &rcClient, TRUE);
+}
+
+/*
+ * 设置线色
+ * color -- 背景色
+ */
+void CGroupLabel::SetLineColor(COLORREF color)
+{
+ m_crLine = color;
+
+ RECT rcClient;
+ ::GetClientRect(m_hWnd, &rcClient);
+ ::InvalidateRect(m_hWnd, &rcClient, TRUE);
+}
+
+ void CGroupLabel::OnLButtonDown(UINT nFlags, CPoint point)
+ {
+ if (!m_bEnableResize) {
+ CStatic::OnLButtonDown(nFlags, point);
+ return;
+ }
+
+ CPoint pt, ptNew;
+ pt = point;
+ int nMoveY = 0;
+
+ // 捕捉鼠标消息,检测是否拖动
+ CRect rcParent, rcWindows;
+ GetClientRect(&rcWindows);
+ ::ClientToScreen(m_hWnd, (LPPOINT)&rcWindows);
+ ::ClientToScreen(m_hWnd, (LPPOINT)&rcWindows.right);
+ GetParent()->GetClientRect(&rcParent);
+ ::ClientToScreen(GetParent()->m_hWnd, (LPPOINT)&rcParent);
+ HDC hDC = ::GetDC(::GetDesktopWindow());
+ ::DrawFocusRect(hDC, &rcWindows);
+
+ if (::GetCapture() == NULL) {
+ SetCapture();
+ ASSERT(this == GetCapture());
+ AfxLockTempMaps();
+ for (;;) {
+ MSG msg;
+ VERIFY(::GetMessage(&msg, NULL, 0, 0));
+
+ if (GetCapture() != this) break;
+
+ switch (msg.message)
+ {
+ case WM_MOUSEMOVE:
+ ptNew = msg.pt;
+ if (ptNew.y < rcParent.top) ptNew.y = rcParent.top;
+ ::DrawFocusRect(hDC, &rcWindows);
+ rcWindows.top = ptNew.y - 3;
+ rcWindows.bottom = ptNew.y + 3;
+ ::DrawFocusRect(hDC, &rcWindows);
+ ::ScreenToClient(m_hWnd, &ptNew);
+ break;
+
+ case WM_LBUTTONUP:
+ ptNew = msg.pt;
+ ::ScreenToClient(m_hWnd, &ptNew);
+ nMoveY = ptNew.y - pt.y;
+ goto ExitLoop;
+
+ case WM_KEYDOWN:
+ if (msg.wParam == VK_ESCAPE) {
+ goto ExitLoop;
+ }
+ break;
+
+ default:
+ DispatchMessage(&msg);
+ break;
+ }
+ }
+
+ ExitLoop:
+ ::DrawFocusRect(hDC, &rcWindows);
+ ::ReleaseDC(::GetDesktopWindow(), hDC);
+ ReleaseCapture();
+ ::InvalidateRect(m_hWnd, NULL, TRUE);
+ GetParent()->SendMessage(ID_MSG_RESIZEY, nMoveY, 0);
+ AfxUnlockTempMaps(FALSE);
+ }
+
+ CStatic::OnLButtonDown(nFlags, point);
+ }
+
+ BOOL CGroupLabel::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
+ {
+ if (m_bEnableResize) {
+ ::SetCursor(::LoadCursor(NULL, IDC_SIZENS));
+ return TRUE;
+ }
+
+ return CStatic::OnSetCursor(pWnd, nHitTest, message);
+ }
--
Gitblit v1.9.3