From bc7f1c4e028e69be51079b59dae4ae5c4d43f5bb Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期六, 31 一月 2026 21:54:56 +0800
Subject: [PATCH] 1.状态指示图,目前灰色表示掉线,绿色表示在线。增加Slot的小点表示有没有料,及加工状态 。 2.增加图示
---
SourceCode/Bond/Servo/CCarrierSlotGrid.cpp | 293 +++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 237 insertions(+), 56 deletions(-)
diff --git a/SourceCode/Bond/Servo/CCarrierSlotGrid.cpp b/SourceCode/Bond/Servo/CCarrierSlotGrid.cpp
index f26ed7f..c44a1b5 100644
--- a/SourceCode/Bond/Servo/CCarrierSlotGrid.cpp
+++ b/SourceCode/Bond/Servo/CCarrierSlotGrid.cpp
@@ -1,4 +1,4 @@
-#include "stdafx.h"
+锘�#include "stdafx.h"
#include "CCarrierSlotGrid.h"
#include <gdiplus.h>
#pragma comment(lib, "gdiplus.lib")
@@ -26,7 +26,7 @@
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_HSCROLL()
- ON_WM_VSCROLL() // ★ 新增
+ ON_WM_VSCROLL() // 鈽� 鏂板
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEWHEEL()
@@ -50,8 +50,7 @@
if (GetParent() && GetParent()->GetFont()) SetFont(GetParent()->GetFont());
EnsureFonts();
EnsureGdiplus();
- // 确保样式包含滚动条
- ModifyStyle(0, WS_HSCROLL | WS_VSCROLL, 0);
+
SetWindowPos(nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
}
@@ -61,7 +60,7 @@
if (GetParent() && GetParent()->GetFont()) SetFont(GetParent()->GetFont());
EnsureFonts();
EnsureGdiplus();
- ModifyStyle(0, WS_HSCROLL | WS_VSCROLL, 0);
+
return 0;
}
@@ -142,7 +141,7 @@
Invalidate(FALSE);
}
-void CCarrierSlotGrid::SetSlotChecked(int portIndex, int slotIndex, BOOL checked)
+void CCarrierSlotGrid::SetSlotChecked(int portIndex, int slotIndex, BOOL checked, BOOL bNotify/* = FALSE*/)
{
if (!SAFE_PORT(portIndex) || !SAFE_SLOT(slotIndex)) return;
auto& pc = m_ports[portIndex];
@@ -150,7 +149,7 @@
auto& cell = pc.slots[slotIndex];
if (!cell.hasGlass) return;
cell.checked = !!checked;
- NotifySelectionChanged(portIndex, slotIndex, cell.checked);
+ if(bNotify) NotifySelectionChanged(portIndex, slotIndex, cell.checked);
Invalidate(FALSE);
}
@@ -183,7 +182,7 @@
CString CCarrierSlotGrid::GetDisplayId(int portIndex, int slotIndex) const
{
- CString s(_T("—"));
+ CString s(_T("鈥�"));
if (!SAFE_PORT(portIndex) || !SAFE_SLOT(slotIndex)) return s;
const auto& cell = m_ports[portIndex].slots[slotIndex];
if (!cell.hasGlass) return s;
@@ -218,24 +217,172 @@
return CSize(w, h);
}
-CSize CCarrierSlotGrid::CalcBestWindowSize(BOOL includeNonClient, int nSlotsOverride) const
+CSize CCarrierSlotGrid::CalcBestWindowSize(BOOL includeNonClient,
+ int nSlotsOverride,
+ int extraPadX,
+ int extraPadY) const
{
- CSize cli = CalcBestClientSize(nSlotsOverride);
- if (!includeNonClient) return cli;
+ // 1) 鍩虹瀹㈡埛鍖哄昂瀵革紙鍚垜浠湪瀹㈡埛鍖虹敾鐨� 1px 杈规锛氬乏鍙�+2/涓婁笅+2锛�
+ const CSize content = CalcBestClientSize(nSlotsOverride);
- RECT rc = { 0, 0, cli.cx, cli.cy };
+ // 2) 鍙� DPI銆佹粴鍔ㄦ潯灏哄锛堝敖閲忕敤 ForDpi锛屽洖閫�鍒版櫘閫氾級
+ UINT dpi = 96;
+#if (_WIN32_WINNT >= 0x0603)
+ if (m_hWnd) {
+ HMODULE hUser32 = ::GetModuleHandleW(L"user32.dll");
+ if (hUser32) {
+ typedef UINT(WINAPI* PFN_GETDPIFORWINDOW)(HWND);
+ auto pGetDpiForWindow = (PFN_GETDPIFORWINDOW)::GetProcAddress(hUser32, "GetDpiForWindow");
+ if (pGetDpiForWindow) dpi = pGetDpiForWindow(m_hWnd);
+ }
+ }
+#endif
+ int cxVScroll = ::GetSystemMetrics(SM_CXVSCROLL);
+ int cyHScroll = ::GetSystemMetrics(SM_CYHSCROLL);
+#if (_WIN32_WINNT >= 0x0A00) // Win10: 鍙敤 GetSystemMetricsForDpi
+ HMODULE hUser32_2 = ::GetModuleHandleW(L"user32.dll");
+ if (hUser32_2) {
+ typedef int (WINAPI* PFN_GSMFD)(int, UINT);
+ auto pGsmForDpi = (PFN_GSMFD)::GetProcAddress(hUser32_2, "GetSystemMetricsForDpi");
+ if (pGsmForDpi) {
+ cxVScroll = pGsmForDpi(SM_CXVSCROLL, dpi);
+ cyHScroll = pGsmForDpi(SM_CYHSCROLL, dpi);
+ }
+ }
+#endif
- // 目标是“刚好不出现滚动条”的窗口外框大小:
- // 用当前样式去掉 WS_HSCROLL/WS_VSCROLL 再做 AdjustWindowRectEx
- DWORD style = GetStyle();
+ // 3) DPI 鑷�傚簲瀹夊叏浣欓噺锛堥伩鍏嶅彇鏁磋宸�/涓婚宸紓锛�
+ const int autoPad = max(1, MulDiv(2, (int)dpi, 96)); // 绾︾瓑浜� 2px@96DPI
+ const int padX = (extraPadX >= 0) ? extraPadX : autoPad;
+ const int padY = (extraPadY >= 0) ? extraPadY : autoPad;
+
+ // 4) 杩唬锛氳�冭檻婊氬姩鏉$浉浜掑奖鍝嶏紝鐩村埌绋冲畾涓嶉渶瑕佹粴鍔ㄦ潯
+ int needCx = content.cx + padX;
+ int needCy = content.cy + padY;
+
+ while (true) {
+ bool needV = (GetTotalContentWidth() > needCx); // 瀹戒笉澶熲啋浼氬嚭鐜版í鍚戞粴鍔ㄦ潯锛燂紙娉ㄦ剰锛氭í鏉″崰楂樺害锛�
+ bool needH = (m_headerCY + (nSlotsOverride > 0 ? nSlotsOverride : m_nSlots) * m_rowHeight + 2 /*瀹㈡埛鍖鸿竟妗�*/ > needCy); // 楂樹笉澶熲啋浼氬嚭鐜扮旱鏉★紵锛堢旱鏉″崰瀹藉害锛�
+
+ // 娉ㄦ剰锛氬嚭鐜扳�滅旱鍚戞潯鈥濅細鍑忓皯鍙敤瀹藉害锛涘嚭鐜扳�滄í鍚戞潯鈥濅細鍑忓皯鍙敤楂樺害
+ // 鎴戜滑鐩爣鏄鈥滃嵆浣挎墸鎺夎繖浜涘崰浣嶁�濆悗涔熶粛鐒� >= 鍐呭灏哄
+ int adjCx = content.cx + padX + (needH ? cxVScroll : 0);
+ int adjCy = content.cy + padY + (needV ? cyHScroll : 0);
+
+ if (adjCx <= needCx && adjCy <= needCy) break; // 绋冲畾锛氬綋鍓� needCx/needCy 瓒冲
+ needCx = max(needCx, adjCx);
+ needCy = max(needCy, adjCy);
+ }
+
+ if (!includeNonClient) return CSize(needCx, needCy);
+
+ // 5) 鎶娾�滅悊鎯冲鎴峰尯灏哄鈥濇崲绠楁垚绐楀彛澶栨灏哄锛堝幓鎺� WS_H/VSCROLL 鍋氭崲绠楋級
+ RECT rc = { 0, 0, needCx, needCy };
+ DWORD style = GetStyle(); // 鉁� 鐢ㄧ湡瀹炴牱寮忥紝璁╃郴缁熸妸婊氬姩鏉¢潪瀹㈡埛鍖轰竴骞剁畻杩涘幓
DWORD exStyle = GetExStyle();
- style &= ~(WS_HSCROLL | WS_VSCROLL);
-
::AdjustWindowRectEx(&rc, style, FALSE, exStyle);
return CSize(rc.right - rc.left, rc.bottom - rc.top);
}
-// ---------- 几何 ----------
+void CCarrierSlotGrid::DisableSystemScrollbars()
+{
+ // 鍘绘帀鏍峰紡
+ ModifyStyle(WS_HSCROLL | WS_VSCROLL, 0, 0);
+ // 闅愯棌锛堝吋瀹规�э級
+ ShowScrollBar(SB_HORZ, FALSE);
+ ShowScrollBar(SB_VERT, FALSE);
+ // 娓呯┖婊氬姩淇℃伅
+ SCROLLINFO si{ sizeof(SCROLLINFO) }; si.fMask = SIF_ALL; si.nMin = 0; si.nMax = 0; si.nPage = 0; si.nPos = 0;
+ SetScrollInfo(SB_HORZ, &si, TRUE);
+ SetScrollInfo(SB_VERT, &si, TRUE);
+ // 璁╅潪瀹㈡埛鍖洪噸绠�
+ SetWindowPos(nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
+ Invalidate(FALSE);
+}
+
+// 娉ㄦ剰锛氳繖閲岀敤鈥滄棤婊氬姩鏉℃牱寮忊�濇潵鎹㈢畻绐楀彛澶栨灏哄锛岀‘淇濆鎴峰尯=鍐呭灏哄 + 鎴戜滑瀹㈡埛鍖鸿竟妗�
+void CCarrierSlotGrid::ResizeWindowToFitAll(BOOL includeNonClient, int nSlotsOverride)
+{
+ // 璁$畻鍐呭鎵�闇�瀹㈡埛鍖猴紙CalcBestClientSize 鍐呭凡鍖呭惈鎴戜滑瀹㈡埛鍖�1px杈规鐨� +2锛�
+ CSize need = CalcBestClientSize(nSlotsOverride);
+
+ if (!includeNonClient) {
+ SetWindowPos(nullptr, 0, 0, need.cx, need.cy,
+ SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
+ return;
+ }
+
+ RECT rc = { 0, 0, need.cx, need.cy };
+ DWORD style = GetStyle() & ~(WS_HSCROLL | WS_VSCROLL); // 鈫� 鐢ㄢ�滄棤婊氬姩鏉♀�濈殑鏍峰紡鏉ユ崲绠�
+ DWORD exStyle = GetExStyle();
+ ::AdjustWindowRectEx(&rc, style, FALSE, exStyle);
+
+ int w = rc.right - rc.left;
+ int h = rc.bottom - rc.top;
+
+ SetWindowPos(nullptr, 0, 0, w, h,
+ SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
+}
+
+void CCarrierSlotGrid::SetNoScrollbarsMode(BOOL enable)
+{
+ m_noScrollbars = !!enable;
+
+ if (m_noScrollbars) {
+ // 1) 鍋忕Щ娓呴浂
+ m_scrollX = 0;
+ m_scrollY = 0;
+
+ // 2) 鍘绘帀鏍峰紡骞堕殣钘忔潯
+ ModifyStyle(WS_HSCROLL | WS_VSCROLL, 0, 0);
+ ShowScrollBar(SB_BOTH, FALSE);
+
+ // 3) 娓呯┖婊氬姩淇℃伅锛堝嵆渚胯祫婧愰噷鍘熸湰甯︿簡鏍峰紡锛屼篃涓嶅啀褰卞搷锛�
+ SCROLLINFO si{ sizeof(SCROLLINFO) }; si.fMask = SIF_ALL;
+ SetScrollInfo(SB_HORZ, &si, TRUE);
+ SetScrollInfo(SB_VERT, &si, TRUE);
+
+ // 4) 閫氱煡绯荤粺闈炲鎴峰尯鍒锋柊锛岀‘淇濇潯琚交搴曠Щ闄�
+ SetWindowPos(nullptr, 0, 0, 0, 0,
+ SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
+
+ Invalidate(FALSE);
+ }
+ else {
+ // 閫�鍑烘棤婊氬姩鏉℃ā寮忥細浠呮仮澶嶆牱寮忥紝瀹為檯鑼冨洿浼氬湪 UpdateScrollRange 涓噸鏂拌缃�
+ ModifyStyle(0, WS_HSCROLL | WS_VSCROLL, 0);
+ SetWindowPos(nullptr, 0, 0, 0, 0,
+ SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
+ UpdateScrollRange();
+ Invalidate(FALSE);
+ }
+}
+
+void CCarrierSlotGrid::FitWindowToContentNoScroll(BOOL includeNonClient, int nSlotsOverride)
+{
+ // 纭繚宸插浜庘�滄棤婊氬姩鏉℃ā寮忊�濓紝闃叉绯荤粺鍦� AdjustWindowRectEx 鏃堕鐣欐粴鍔ㄦ潯闈炲鎴峰尯
+ SetNoScrollbarsMode(TRUE);
+
+ // 浣犺嚜宸辩殑 CalcBestClientSize 宸插寘鍚鎴峰尯 1px 杈规(+2)鐨勪慨姝�
+ CSize needCli = CalcBestClientSize(nSlotsOverride);
+
+ if (!includeNonClient) {
+ SetWindowPos(nullptr, 0, 0, needCli.cx, needCli.cy,
+ SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
+ return;
+ }
+
+ RECT rc{ 0, 0, needCli.cx, needCli.cy };
+ // 娉ㄦ剰锛氭鏃剁獥鍙f牱寮忓凡缁忔病鏈� WS_H/VSCROLL 浜嗏�斺�旂敤鐪熷疄鏍峰紡鎹㈢畻鍗冲彲
+ ::AdjustWindowRectEx(&rc, GetStyle(), FALSE, GetExStyle());
+ const int w = rc.right - rc.left;
+ const int h = rc.bottom - rc.top;
+
+ SetWindowPos(nullptr, 0, 0, w, h,
+ SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
+}
+
+// ---------- 鍑犱綍 ----------
CRect CCarrierSlotGrid::GetClientRectNoSB() const
{
CRect rc; GetClientRect(&rc); return rc;
@@ -313,9 +460,16 @@
void CCarrierSlotGrid::UpdateScrollRange()
{
+ if (m_noScrollbars) {
+ // 纭繚鍋忕Щ涓�鐩翠负 0锛屼笉璁句换浣曟粴鍔ㄤ俊鎭�
+ m_scrollX = 0;
+ m_scrollY = 0;
+ return;
+ }
+
CRect rc; GetClientRect(&rc);
- // 垂直
+ // 鍨傜洿
const int contentH = m_headerCY + m_nSlots * m_rowHeight;
const int pageY = max(1, rc.Height());
const int maxPosY = max(0, contentH - pageY);
@@ -325,7 +479,7 @@
siY.nMin = 0; siY.nMax = contentH - 1; siY.nPage = pageY; siY.nPos = m_scrollY;
SetScrollInfo(SB_VERT, &siY, TRUE);
- // 水平
+ // 姘村钩
const int contentW = GetTotalContentWidth();
const int pageX = max(1, rc.Width());
const int maxPosX = max(0, contentW - pageX);
@@ -336,10 +490,10 @@
SetScrollInfo(SB_HORZ, &siX, TRUE);
}
-// ---------- 表头分隔线命中 ----------
+// ---------- 琛ㄥご鍒嗛殧绾垮懡涓� ----------
int CCarrierSlotGrid::HitHeaderEdge(CPoint pt) const
{
- if (!m_bAllowResize) return -1; // ← 新增
+ if (!m_bAllowResize) return -1; // 鈫� 鏂板
if (!GetHeaderRect().PtInRect(pt)) return -1;
const int tol = 4;
int x = GetHeaderRect().left - m_scrollX + m_slotColCX;
@@ -353,7 +507,7 @@
return -1;
}
-// ---------- 绘制 ----------
+// ---------- 缁樺埗 ----------
BOOL CCarrierSlotGrid::OnEraseBkgnd(CDC* /*pDC*/) { return TRUE; }
void CCarrierSlotGrid::DrawFlatCheckbox(CDC* pDC, const CRect& r, bool checked, bool disabled)
@@ -395,8 +549,8 @@
{
CRect rItem = GetHeaderItemRect(i);
- // 修改为:
- if (i < GetPortCount()) { // ★ 最后一列不画分隔线
+ // 淇敼涓猴細
+ if (i < GetPortCount()) { // 鈽� 鏈�鍚庝竴鍒椾笉鐢诲垎闅旂嚎
CPen pen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW));
pOldPen = pDC->SelectObject(&pen);
pDC->MoveTo(rItem.right - 1, rItem.top);
@@ -425,11 +579,11 @@
? pc.portName
: (pc.portName + _T(" (") + pc.carrierName + _T(")"));
- // 勾选框靠右
+ // 鍕鹃�夋闈犲彸
CRect rcCb = GetHeaderCheckboxRect(i);
DrawFlatCheckbox(pDC, rcCb, all, pc.allocated);
- // 计数贴近勾选框左侧
+ // 璁℃暟璐磋繎鍕鹃�夋宸︿晶
CString cnt; cnt.Format(_T("%d/%d"), selected, m_nSlots);
SIZE szCnt{ 0,0 };
{ CFont* o = pDC->SelectObject(&m_fntBold);
@@ -438,14 +592,14 @@
const int gap = 6;
CRect rcCnt(rcCb.left - gap - szCnt.cx, rItem.top, rcCb.left - gap, rItem.bottom);
- // 左侧标题
+ // 宸︿晶鏍囬
CRect rt = rItem; rt.DeflateRect(6, 0, (rItem.right - rcCnt.left) + 6, 0);
pDC->SetBkMode(TRANSPARENT);
pDC->SelectObject(&m_fntBold);
pDC->SetTextColor(::GetSysColor(COLOR_BTNTEXT));
pDC->DrawText(leftTitle, rt, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
- // 计数
+ // 璁℃暟
pDC->SelectObject(&m_fntBold);
pDC->SetTextColor(::GetSysColor(COLOR_BTNTEXT));
pDC->DrawText(cnt, rcCnt, DT_RIGHT | DT_VCENTER | DT_SINGLELINE);
@@ -527,7 +681,7 @@
pDC->DrawText(tx, rT, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
- // 状态点(GDI+ 抗锯齿)
+ // 鐘舵�佺偣锛圙DI+ 鎶楅敮榻匡級
{
Graphics g(pDC->GetSafeHdc());
g.SetSmoothingMode(SmoothingModeAntiAlias);
@@ -543,7 +697,7 @@
-// ===== 在每个已分配(allocated)的列中央绘制半透明 LOCK 水印(用 HDC+LOGFONT 构造字体)=====
+// ===== 鍦ㄦ瘡涓凡鍒嗛厤(allocated)鐨勫垪涓ぎ缁樺埗鍗婇�忔槑 LOCK 姘村嵃锛堢敤 HDC+LOGFONT 鏋勯�犲瓧浣擄級=====
{
Gdiplus::Graphics g(pDC->GetSafeHdc());
g.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
@@ -551,7 +705,7 @@
CRect cli = GetClientRectNoSB();
CRect rh = GetHeaderRect();
- // 取当前 UI 字体(优先粗体)
+ // 鍙栧綋鍓� UI 瀛椾綋锛堜紭鍏堢矖浣擄級
LOGFONT lf{};
if ((HFONT)m_fntBold) m_fntBold.GetLogFont(&lf);
else if ((HFONT)m_fntText) m_fntText.GetLogFont(&lf);
@@ -560,21 +714,21 @@
{
if (!m_ports[i].allocated) continue;
- // 列矩形(除去表头,考虑水平滚动)
+ // 鍒楃煩褰紙闄ゅ幓琛ㄥご锛岃�冭檻姘村钩婊氬姩锛�
CRect rCol = GetHeaderItemRect(i + 1);
rCol.top = rh.bottom;
rCol.bottom = cli.bottom;
if (rCol.right <= cli.left || rCol.left >= cli.right || rCol.Height() <= 0) continue;
- // 自适应一个合适的像素高度
+ // 鑷�傚簲涓�涓悎閫傜殑鍍忕礌楂樺害
int availW = rCol.Width() - 12;
int availH = rCol.Height() - 12;
int emPx = max(16, min(min(availW / 3, availH / 5), 72));
if (emPx < 16) emPx = 16;
- // 字号减半(并给个更低的兜底,避免太小)
+ // 瀛楀彿鍑忓崐锛堝苟缁欎釜鏇翠綆鐨勫厹搴曪紝閬垮厤澶皬锛�
emPx = max(12, emPx / 2);
- // 用 LOGFONTW + HDC 构造 GDI+ 字体
+ // 鐢� LOGFONTW + HDC 鏋勯�� GDI+ 瀛椾綋
LOGFONTW lfw{};
#ifdef UNICODE
lfw = *reinterpret_cast<LOGFONTW*>(&lf);
@@ -594,14 +748,14 @@
lfw.lfPitchAndFamily = lf.lfPitchAndFamily;
MultiByteToWideChar(CP_ACP, 0, lf.lfFaceName, -1, lfw.lfFaceName, LF_FACESIZE);
#endif
- lfw.lfHeight = -emPx; // 负值=按像素高度
+ lfw.lfHeight = -emPx; // 璐熷��=鎸夊儚绱犻珮搴�
lfw.lfWeight = FW_BOLD;
- Gdiplus::Font gdifont(pDC->GetSafeHdc(), &lfw); // ★ 加上 Gdiplus::
+ Gdiplus::Font gdifont(pDC->GetSafeHdc(), &lfw); // 鈽� 鍔犱笂 Gdiplus::
Gdiplus::StringFormat fmt;
fmt.SetAlignment(Gdiplus::StringAlignmentCenter);
fmt.SetLineAlignment(Gdiplus::StringAlignmentCenter);
- Gdiplus::Color col(140, 120, 100, 60); // 半透明
+ Gdiplus::Color col(140, 120, 100, 60); // 鍗婇�忔槑
Gdiplus::SolidBrush brush(col);
Gdiplus::RectF box((Gdiplus::REAL)rCol.left, (Gdiplus::REAL)rCol.top,
(Gdiplus::REAL)rCol.Width(), (Gdiplus::REAL)rCol.Height());
@@ -616,14 +770,14 @@
}
}
- // === 客户区内 1px 灰色边框(不包滚动条,但不会缺角/抢绘制)===
+ // === 瀹㈡埛鍖哄唴 1px 鐏拌壊杈规锛堜笉鍖呮粴鍔ㄦ潯锛屼絾涓嶄細缂鸿/鎶㈢粯鍒讹級===
{
CRect cli; GetClientRect(&cli);
- // 用 FrameRect 更稳(避免右下角丢线)
+ // 鐢� FrameRect 鏇寸ǔ锛堥伩鍏嶅彸涓嬭涓㈢嚎锛�
CBrush br; br.CreateSolidBrush(::GetSysColor(COLOR_3DSHADOW));
CRect r = cli;
- // 注意:客户区坐标是 [0..width, 0..height];FrameRect 会在内侧画 1px
+ // 娉ㄦ剰锛氬鎴峰尯鍧愭爣鏄� [0..width, 0..height]锛汧rameRect 浼氬湪鍐呬晶鐢� 1px
pDC->FrameRect(&r, &br);
br.DeleteObject();
}
@@ -654,6 +808,8 @@
void CCarrierSlotGrid::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pBar)
{
+ if (m_noScrollbars) return; // 鈫� 鏂板
+
UNREFERENCED_PARAMETER(pBar);
SCROLLINFO si = { sizeof(SCROLLINFO) };
@@ -671,7 +827,7 @@
case SB_PAGERIGHT: pos += (int)si.nPage; break;
case SB_THUMBTRACK:
case SB_THUMBPOSITION:
- pos = (int)si.nTrackPos; // ★ 32 位拖动位置
+ pos = (int)si.nTrackPos; // 鈽� 32 浣嶆嫋鍔ㄤ綅缃�
break;
default:
return;
@@ -687,6 +843,8 @@
void CCarrierSlotGrid::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pBar)
{
+ if (m_noScrollbars) return; // 鈫� 鏂板
+
UNREFERENCED_PARAMETER(pBar);
SCROLLINFO si = { sizeof(SCROLLINFO) };
@@ -704,7 +862,7 @@
case SB_PAGEDOWN: pos += (int)si.nPage; break;
case SB_THUMBTRACK:
case SB_THUMBPOSITION:
- pos = (int)si.nTrackPos; // ★ 32 位拖动位置
+ pos = (int)si.nTrackPos; // 鈽� 32 浣嶆嫋鍔ㄤ綅缃�
break;
default:
return;
@@ -720,6 +878,8 @@
BOOL CCarrierSlotGrid::OnMouseWheel(UINT, short zDelta, CPoint)
{
+ if (m_noScrollbars) return FALSE; // 鈫� 鏂板锛氬交搴曚笉婊�
+
int delta = (zDelta > 0 ? -1 : +1) * (m_rowHeight * 3);
m_scrollY = max(0, m_scrollY + delta);
UpdateScrollRange();
@@ -741,8 +901,8 @@
void CCarrierSlotGrid::OnLButtonDown(UINT nFlags, CPoint pt)
{
- // 是否拖动列宽
- int edge = m_bAllowResize ? HitHeaderEdge(pt) : -1; // ← 修改
+ // 鏄惁鎷栧姩鍒楀
+ int edge = m_bAllowResize ? HitHeaderEdge(pt) : -1; // 鈫� 淇敼
if (edge >= 0)
{
m_bResizing = true;
@@ -754,7 +914,7 @@
return;
}
- // Header 点击(仅复选框区域)
+ // Header 鐐瑰嚮锛堜粎澶嶉�夋鍖哄煙锛�
if (GetHeaderRect().PtInRect(pt))
{
for (int i = 1; i <= GetPortCount(); ++i)
@@ -780,7 +940,7 @@
return;
}
- // Cell 点击
+ // Cell 鐐瑰嚮
CRect cli = GetClientRectNoSB();
if (pt.y < cli.top + m_headerCY) return;
int yIn = pt.y - (cli.top + m_headerCY) + m_scrollY;
@@ -856,7 +1016,7 @@
}
else
{
- int idx = m_resizeEdge - 1; // 调整 Port idx 的宽度
+ int idx = m_resizeEdge - 1; // 璋冩暣 Port idx 鐨勫搴�
int nw = max(m_portColMin, m_portColCXsStart[idx] + dx);
if (nw != m_portColCXs[idx]) { m_portColCXs[idx] = nw; UpdateScrollRange(); Invalidate(FALSE); }
}
@@ -883,20 +1043,41 @@
return CWnd::OnSetCursor(pWnd, nHitTest, message);
}
-// ---------- 通知 ----------
-void CCarrierSlotGrid::NotifySelectionChanged(int /*port*/, int /*slot*/, BOOL /*checked*/)
+void CCarrierSlotGrid::NotifySelectionChanged(int port, int slot, BOOL checked)
{
- if (GetParent())
- {
+ // 鍏煎鏃х殑 WM_COMMAND锛堝彲鐣欙紝涔熷彲娉ㄩ噴鎺夛級
+ if (GetParent()) {
const int code = 0x2001;
GetParent()->SendMessage(WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(), code), (LPARAM)m_hWnd);
}
+ // 鏂扮殑 WM_NOTIFY锛屽甫涓婄储寮曚笌鐘舵��
+ if (GetParent()) {
+ CSG_SEL_CHANGE nm{};
+ nm.hdr.hwndFrom = m_hWnd;
+ nm.hdr.idFrom = (UINT)GetDlgCtrlID();
+ nm.hdr.code = CSGN_SEL_CHANGED;
+ nm.port = port;
+ nm.slot = slot;
+ nm.checked = checked;
+ GetParent()->SendMessage(WM_NOTIFY, nm.hdr.idFrom, (LPARAM)&nm);
+ }
}
-void CCarrierSlotGrid::NotifyMaterialChanged(int /*port*/, int /*slot*/, int /*material*/)
+
+void CCarrierSlotGrid::NotifyMaterialChanged(int port, int slot, int material)
{
- if (GetParent())
- {
+ if (GetParent()) {
const int code = 0x2002;
GetParent()->SendMessage(WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(), code), (LPARAM)m_hWnd);
}
+ if (GetParent()) {
+ CSG_MAT_CHANGE nm{};
+ nm.hdr.hwndFrom = m_hWnd;
+ nm.hdr.idFrom = (UINT)GetDlgCtrlID();
+ nm.hdr.code = CSGN_MAT_CHANGED;
+ nm.port = port;
+ nm.slot = slot;
+ nm.material = material;
+ GetParent()->SendMessage(WM_NOTIFY, nm.hdr.idFrom, (LPARAM)&nm);
+ }
}
+
--
Gitblit v1.9.3