From 49c116b0a9d6ad26dae0d5ec915ea6f7fe5684f4 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期六, 13 九月 2025 11:34:40 +0800
Subject: [PATCH] Merge branch 'liuyang'
---
SourceCode/Bond/Servo/CProcessDataListDlg.cpp | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 201 insertions(+), 0 deletions(-)
diff --git a/SourceCode/Bond/Servo/CProcessDataListDlg.cpp b/SourceCode/Bond/Servo/CProcessDataListDlg.cpp
new file mode 100644
index 0000000..65e58dd
--- /dev/null
+++ b/SourceCode/Bond/Servo/CProcessDataListDlg.cpp
@@ -0,0 +1,201 @@
+锘�// CProcessDataListDlg.cpp: 瀹炵幇鏂囦欢
+//
+
+#include "stdafx.h"
+#include "Servo.h"
+#include "CProcessDataListDlg.h"
+#include "afxdialogex.h"
+
+
+// CProcessDataListDlg 瀵硅瘽妗�
+
+IMPLEMENT_DYNAMIC(CProcessDataListDlg, CDialogEx)
+
+CProcessDataListDlg::CProcessDataListDlg(CWnd* pParent /*=nullptr*/)
+ : CDialogEx(IDD_DIALOG_PROCESS_DATA_LIST, pParent)
+{
+
+}
+
+CProcessDataListDlg::~CProcessDataListDlg()
+{
+}
+
+void CProcessDataListDlg::DoDataExchange(CDataExchange* pDX)
+{
+ CDialogEx::DoDataExchange(pDX);
+ DDX_Control(pDX, IDC_LIST_RECIPE_PARAM, m_listCtrl);
+}
+
+
+BEGIN_MESSAGE_MAP(CProcessDataListDlg, CDialogEx)
+ ON_BN_CLICKED(IDC_BUTTON1, &CProcessDataListDlg::OnBnClickedButton1)
+END_MESSAGE_MAP()
+
+
+// CProcessDataListDlg 娑堟伅澶勭悊绋嬪簭
+
+
+BOOL CProcessDataListDlg::OnInitDialog()
+{
+ CDialogEx::OnInitDialog();
+
+
+ DWORD dwStyle = m_listCtrl.GetExtendedStyle();
+ dwStyle |= LVS_EX_FULLROWSELECT;
+ dwStyle |= LVS_EX_GRIDLINES;
+ dwStyle |= LVS_EX_DOUBLEBUFFER;
+ m_listCtrl.SetExtendedStyle(dwStyle);
+
+ HIMAGELIST imageList = ImageList_Create(24, 24, ILC_COLOR24, 1, 1);
+ ListView_SetImageList(m_listCtrl.GetSafeHwnd(), imageList, LVSIL_SMALL);
+ m_listCtrl.InsertColumn(0, _T("鍚嶇О"), LVCFMT_RIGHT, 188);
+ m_listCtrl.InsertColumn(1, _T("鍊�"), LVCFMT_LEFT, 128);
+
+
+ InsertParamsToListCtrl(m_listCtrl, m_strRawText);
+
+ return TRUE; // return TRUE unless you set the focus to a control
+ // 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
+}
+
+void CProcessDataListDlg::setRawText(CString& strRawText)
+{
+ m_strRawText = strRawText;
+}
+
+void CProcessDataListDlg::InsertParamsToListCtrl(CListCtrl& listCtrl, const CString& data)
+{
+ // 娓呯┖鐜版湁鍐呭
+ listCtrl.DeleteAllItems();
+
+ int row = 0;
+ int start = 0;
+ CString item;
+
+ // 鎸夐�楀彿鍒嗗壊
+ while (AfxExtractSubString(item, data, row, ',')) // row 浠� 0 寮�濮嬶紝閫愪釜鍙栧瓙涓�
+ {
+ int pos = item.Find(_T(':'));
+ if (pos == -1) {
+ row++;
+ continue;
+ }
+
+ CString name = item.Left(pos);
+ CString value = item.Mid(pos + 1);
+
+ name.Trim(); // 鍘绘帀鍓嶅悗绌烘牸
+ value.Trim();
+
+ int nItem = listCtrl.InsertItem(row, name); // 绗竴鍒楋細鍙傛暟鍚�
+ listCtrl.SetItemText(nItem, 1, value); // 绗簩鍒楋細鍙傛暟鍊�
+
+ row++;
+ }
+}
+
+bool CProcessDataListDlg::CopyListCtrlToClipboard(CListCtrl& listCtrl, bool includeHeader/* = false*/)
+{
+ CString strCSV;
+ int nCount = listCtrl.GetItemCount();
+ int nColCount = listCtrl.GetHeaderCtrl()->GetItemCount();
+
+ if (nCount == 0 || nColCount == 0)
+ return false;
+
+ // 濡傛灉闇�瑕佸鍑鸿〃澶�
+ if (includeHeader)
+ {
+ CString headerLine;
+ for (int j = 0; j < nColCount; j++)
+ {
+ CString text;
+ LVCOLUMN col;
+ TCHAR buf[256] = { 0 };
+ col.mask = LVCF_TEXT;
+ col.pszText = buf;
+ col.cchTextMax = 255;
+ if (listCtrl.GetColumn(j, &col))
+ text = col.pszText;
+
+ if (text.Find(_T(',')) != -1 || text.Find(_T('"')) != -1)
+ {
+ text.Replace(_T("\""), _T("\"\""));
+ text = _T("\"") + text + _T("\"");
+ }
+
+ headerLine += text;
+ if (j < nColCount - 1)
+ headerLine += _T(",");
+ }
+ strCSV += headerLine + _T("\n");
+ }
+
+ // 閬嶅巻琛�
+ for (int i = 0; i < nCount; i++)
+ {
+ CString line;
+ for (int j = 0; j < nColCount; j++)
+ {
+ CString text = listCtrl.GetItemText(i, j);
+
+ // 濡傛灉鍖呭惈閫楀彿鎴栧弻寮曞彿锛屽姞涓婂紩鍙峰苟杞箟
+ if (text.Find(_T(',')) != -1 || text.Find(_T('"')) != -1)
+ {
+ text.Replace(_T("\""), _T("\"\""));
+ text = _T("\"") + text + _T("\"");
+ }
+
+ line += text;
+ if (j < nColCount - 1)
+ line += _T(",");
+ }
+ strCSV += line + _T("\n");
+ }
+
+ if (!OpenClipboard())
+ return false;
+
+ EmptyClipboard();
+
+ // 杞负鍏ㄥ眬鍐呭瓨
+ HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, (strCSV.GetLength() + 1) * sizeof(TCHAR));
+ if (!hMem)
+ {
+ CloseClipboard();
+ return false;
+ }
+
+ LPTSTR pMem = (LPTSTR)GlobalLock(hMem);
+ if (!pMem)
+ {
+ GlobalFree(hMem);
+ CloseClipboard();
+ return false;
+ }
+
+ _tcscpy_s(pMem, strCSV.GetLength() + 1, strCSV);
+ GlobalUnlock(hMem);
+
+#ifdef UNICODE
+ SetClipboardData(CF_UNICODETEXT, hMem);
+#else
+ SetClipboardData(CF_TEXT, hMem);
+#endif
+
+ CloseClipboard();
+ return true;
+}
+
+void CProcessDataListDlg::OnBnClickedButton1()
+{
+ if (CopyListCtrlToClipboard(m_listCtrl, true))
+ {
+ AfxMessageBox(_T("澶嶅埗鎴愬姛锛�"));
+ }
+ else
+ {
+ AfxMessageBox(_T("澶嶅埗澶辫触锛�"));
+ }
+}
--
Gitblit v1.9.3