// CDlgMgr.cpp: 实现文件 // #include "pch.h" #include "scanner-check.h" #include "CDlgMgr.h" #include "afxdialogex.h" #include #include #include #include // CDlgMgr 对话框 static std::wstring vid_pid_edit_org_proc = L"vid_pid_edit_org_proc"; static wchar_t* hex = L"0123456789ABCDEF"; IMPLEMENT_DYNAMIC(CDlgMgr, CDialogEx) CDlgMgr::CDlgMgr(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_MANAGER, pParent) { } CDlgMgr::~CDlgMgr() { } static bool is_checked(CWnd* ctrl) { return ((CButton*)ctrl)->GetCheck() == BST_CHECKED; } static bool is_checked(CDialogEx* dlg, UINT id) { return is_checked(dlg->GetDlgItem(id)); } static void set_checked(CWnd* ctrl, bool checked) { ((CButton*)ctrl)->SetCheck(checked ? BST_CHECKED : BST_UNCHECKED); } static void set_checked(CDialogEx* dlg, UINT id, bool checked) { return set_checked(dlg->GetDlgItem(id), checked); } static LRESULT vid_pid_edit_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { wchar_t now[40] = { 0 }; int len = 0, sel = 0, max_len = 4; bool all_digit = true; WNDPROC wndproc = (WNDPROC)GetPropW(hwnd, vid_pid_edit_org_proc.c_str()); std::wstring buf(L""); if (!wndproc) wndproc = DefWindowProcW; switch (msg) { case WM_CHAR: GetWindowTextW(hwnd, now, _countof(now)); len = lstrlenW(now); sel = SendMessage(hwnd, EM_GETSEL, 0, 0); sel = ((sel >> 16) & 0x0ff) - (sel & 0x0ffff); if (wp >= ' ' && len - sel >= max_len) return 0; if (wp >= '0' && wp <= '9') wp = hex[wp - '0']; else if (wp >= 'A' && wp <= 'F') wp = hex[wp - 'A' + 10]; else if (wp >= 'a' && wp <= 'f') wp = hex[wp - 'a' + 10]; else if(wp >= ' ') return 0; break; //case WM_COPY: // return 0; case WM_PASTE: { size_t l = 0; if (file_util::get_clipboard(NULL, &l, CF_UNICODETEXT) == ERROR_INSUFFICIENT_BUFFER) { buf.resize(l + 4); l++; if (file_util::get_clipboard(&buf[0], &l, CF_UNICODETEXT)) l = 0; } if (l == 0) return 0; lp = (LPARAM)&buf[0]; msg = WM_SETTEXT; } case WM_SETTEXT: for (int i = 0; len < max_len + 1 && i < lstrlenW((wchar_t*)lp); ++i) { wchar_t ch = ((wchar_t*)lp)[i]; if (ch >= '0' && ch <= '9') now[len++] = hex[ch - '0']; else if (ch >= 'A' && ch <= 'F') { now[len++] = hex[ch - 'A' + 10]; all_digit = false; } else if (ch >= 'a' && ch <= 'f') { now[len++] = hex[ch - 'a' + 10]; all_digit = false; } else break; } if(len == 0) return 0; if (/*len == max_len + 1 &&*/ all_digit) { sel = _wtoi(now); //if (sel <= 0x0ffff) { now[max_len] = 0; for (int l = max_len - 1; l >= 0; --l, sel >>= 4) now[l] = hex[sel % 16]; } //else // now[max_len] = 0; } lp = (LPARAM)now; break; } return wndproc(hwnd, msg, wp, lp); } static void set_vid_pid_proc(HWND hwnd) { SetPropW(hwnd, vid_pid_edit_org_proc.c_str(), (HANDLE)(FARPROC)GetWindowLong(hwnd, GWL_WNDPROC)); SetWindowLong(hwnd, GWL_WNDPROC, (LONG)(FARPROC)vid_pid_edit_proc); } static WORD vid_pid_edit_value(HWND hwnd) { wchar_t text[40] = { 0 }; int off = 10; WORD vpid = 0; GetWindowTextW(hwnd, text + off, _countof(text) - off - 1); for (int i = 0; text[off + i]; ++i) { const wchar_t* ptr = NULL; text[0] = text[off + i]; ptr = wcsstr(hex, text); if (!ptr) break; vpid <<= 4; vpid += ptr - hex; } return vpid; } void CDlgMgr::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_LIST1, list_); DDX_Control(pDX, IDC_COMBO_ITEM, combo_); DDX_Control(pDX, IDC_IPADDRESS1, ip_); } BEGIN_MESSAGE_MAP(CDlgMgr, CDialogEx) ON_BN_CLICKED(IDC_CHECK2, &CDlgMgr::OnBnClickedCheckReport) ON_MESSAGE(WM_USER + 1, &CDlgMgr::OnDisableIPCtrl) ON_BN_CLICKED(IDC_BUTTON_MAINTAIN, &CDlgMgr::OnBnClickedButtonMaintain) ON_BN_CLICKED(IDC_BUTTON_ADD, &CDlgMgr::OnBnClickedButtonAdd) ON_CBN_SELCHANGE(IDC_COMBO_ITEM, &CDlgMgr::OnCbnSelchangeComboItem) ON_NOTIFY(NM_DBLCLK, IDC_LIST1, &CDlgMgr::OnNMDblclkList1) ON_BN_CLICKED(IDC_BUTTON_ADD_ALL, &CDlgMgr::OnBnClickedButtonAddAll) ON_WM_DROPFILES() // ON_WM_GETDLGCODE() ON_COMMAND(ID_LIST_PASTE_CLIPBOARD, &CDlgMgr::OnListPasteClipboard) ON_NOTIFY(NM_RCLICK, IDC_LIST1, &CDlgMgr::OnNMRClickList1) ON_COMMAND(ID_LIST_CLEAR, &CDlgMgr::OnListClear) END_MESSAGE_MAP() static DWORD WINAPI disable_ip_ctrl(LPVOID lp) { Sleep(500); PostMessage((HWND)lp, WM_USER + 1, 0, 0); return 0; } LRESULT CDlgMgr::OnDisableIPCtrl(WPARAM, LPARAM) { OnBnClickedCheckReport(); return 0; } // CDlgMgr 消息处理程序 BOOL CDlgMgr::OnInitDialog() { CDialogEx::OnInitDialog(); int ind = list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("\u5E8F\u53F7"), 0, 40); list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("\u6D4B\u8BD5\u9879\u76EE"), 0, 171); list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("\u5FC5\u987B\u8054\u673A\u6D4B\u8BD5"), 0, 86); list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("\u4E0D\u901A\u8FC7\u5219\u505C\u6B62"), 0, 86); list_.SetExtendedStyle((list_.GetExStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES) & (~LVS_EX_CHECKBOXES)); list_.ModifyStyle(0, LVS_SINGLESEL); set_checked(this, IDC_CHECK_ONLINE, true); set_checked(this, IDC_CHECK_FATAL, true); combo_.AddString(L"船形开关"); combo_.AddString(L"外观"); combo_.AddString(L"显示屏"); combo_.AddString(L"歪斜"); combo_.AddString(L"超声波"); set_vid_pid_proc(GetDlgItem(IDC_EDIT_VID_SRC)->m_hWnd); set_vid_pid_proc(GetDlgItem(IDC_EDIT_PID_SRC)->m_hWnd); set_vid_pid_proc(GetDlgItem(IDC_EDIT_VID_TO)->m_hWnd); set_vid_pid_proc(GetDlgItem(IDC_EDIT_PID_TO)->m_hWnd); SetDlgItemInt(IDC_EDIT_VID_SRC, 0x3072); SetDlgItemInt(IDC_EDIT_PID_SRC, 0x200); SetDlgItemInt(IDC_EDIT_VID_TO, 0x3072); SetDlgItemInt(IDC_EDIT_PID_TO, 0x0239); SetDlgItemInt(IDC_EDIT_SLEEP, 5); SetDlgItemInt(IDC_EDIT_SPEED, 60); return TRUE; // 除非将焦点设置到控件,否则返回 TRUE } void CDlgMgr::OnBnClickedCheckReport() { // TODO: 在此添加控件通知处理程序代码 bool enable = is_checked(this, IDC_CHECK2); GetDlgItem(IDC_IPADDRESS1)->EnableWindow(enable); GetDlgItem(IDC_IPADDRESS1)->ShowWindow(SW_SHOW); GetDlgItem(IDC_EDIT_IP)->ShowWindow(SW_HIDE); GetDlgItem(IDC_EDIT_PORT)->EnableWindow(enable); GetDlgItem(IDC_EDIT_DB)->EnableWindow(enable); if (enable) GotoDlgCtrl(GetDlgItem(IDC_IPADDRESS1)); } void CDlgMgr::OnBnClickedButtonMaintain() { // TODO: 在此添加控件通知处理程序代码 ::PostMessage(GetParent()->m_hWnd, WM_TO_ITEM_MGR_TAB, 0, 0); } void CDlgMgr::OnBnClickedButtonAdd() { // TODO: 在此添加控件通知处理程序代码 wchar_t text[128] = { 0 }; bool online = is_checked(this, IDC_CHECK_ONLINE), fatal = is_checked(this, IDC_CHECK_FATAL); int ind = -1; if (::GetWindowTextW(GetDlgItem(IDC_COMBO_ITEM)->m_hWnd, text, _countof(text) - 1) == 0) return; for (int i = 0; i < list_.GetItemCount(); ++i) { wchar_t val[128] = { 0 }; list_.GetItemText(i, 1, val, _countof(val) - 1); if (wcscmp(text, val) == 0) { ind = i; break; } } if (ind == -1) { wchar_t sn[20] = { 0 }; swprintf_s(sn, _countof(sn) - 1, L"%u", list_.GetItemCount() + 1); ind = list_.InsertItem(list_.GetItemCount(), sn); list_.SetItemText(ind, 1, text); } list_.SetItemText(ind, 2, online ? L"true" : L"false"); list_.SetItemText(ind, 3, fatal ? L"true" : L"false"); list_.SetItemState(ind, LVNI_FOCUSED | LVIS_SELECTED, LVNI_FOCUSED | LVIS_SELECTED); list_.EnsureVisible(ind, FALSE); } void CDlgMgr::OnCbnSelchangeComboItem() { // TODO: 在此添加控件通知处理程序代码 wchar_t text[128] = { 0 }, val[128] = { 0 }; page_config::ITEM item; ::GetWindowTextW(GetDlgItem(IDC_COMBO_ITEM)->m_hWnd, text, _countof(text) - 1); for (int i = 0; i < list_.GetItemCount(); ++i) { list_.GetItemText(i, 1, val, _countof(val) - 1); if (wcscmp(text, val) == 0) { list_.SetItemState(i, LVNI_FOCUSED | LVIS_SELECTED, LVNI_FOCUSED | LVIS_SELECTED); list_.GetItemText(i, 2, val, _countof(val) - 1); set_checked(this, IDC_CHECK_ONLINE, wcscmp(val, L"true") == 0); list_.GetItemText(i, 3, val, _countof(val) - 1); set_checked(this, IDC_CHECK_FATAL, wcscmp(val, L"true") == 0); return; } } ::SendMessageW(GetParent()->m_hWnd, WM_GET_TEST_ITEM_NAME, (WPARAM)text, (LPARAM)&item); if (item.title == text) { set_checked(this, IDC_CHECK_ONLINE, !item.man); set_checked(this, IDC_CHECK_FATAL, item.fatal); } } void CDlgMgr::OnNMDblclkList1(NMHDR* pNMHDR, LRESULT* pResult) { LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast(pNMHDR); // TODO: 在此添加控件通知处理程序代码 POINT pos = { 0 }; RECT r = { 0 }; GetCursorPos(&pos); list_.ScreenToClient(&pos); r.left = list_.HitTest(pos); if (r.left != -1) { std::vector width; int ind = r.left, hpos = list_.GetScrollPos(SB_HORZ); for (int i = 0; i < list_.GetHeaderCtrl()->GetItemCount(); ++i) { RECT r = { 0 }; list_.GetHeaderCtrl()->GetItemRect(i, &r); width.push_back(r.right - r.left); } pos.x += hpos; for (int i = 0; i < width.size(); ++i) { if (pos.x <= width[i]) { wchar_t text[128] = { 0 }; if (i < 2) { std::wstring tips(L"\u5220\u9664\u6D4B\u8BD5\u9879\uFF1A"); list_.GetItemText(ind, 1, text, _countof(text) - 1); tips += text; tips += L"\uFF1F"; if (::MessageBoxW(m_hWnd,tips.c_str(), L"\u786E\u8BA4", MB_YESNO | MB_ICONQUESTION) == IDYES) { list_.DeleteItem(ind); for (; ind < list_.GetItemCount(); ++ind) { swprintf_s(text, _countof(text) - 1, L"%u", ind + 1); list_.SetItemText(ind, 0, text); } } } else { list_.GetItemText(ind, i, text, _countof(text) - 1); if (wcscmp(text, L"true")) list_.SetItemText(ind, i, L"true"); else list_.SetItemText(ind, i, L"false"); } break; } pos.x -= width[i]; } } *pResult = 0; } void CDlgMgr::OnBnClickedButtonAddAll() { // TODO: 在此添加控件通知处理程序代码 for (int i = 0; i < combo_.GetCount(); ++i) { combo_.SetCurSel(i); OnCbnSelchangeComboItem(); OnBnClickedButtonAdd(); } } void CDlgMgr::init_test_items(std::vector& items) { combo_.ResetContent(); for (size_t i = 0; i < items.size(); ++i) combo_.AddString(items[i].title.c_str()); if (items.size()) { combo_.SetCurSel(0); OnCbnSelchangeComboItem(); } } INTER_MODULE_CALLBACK(got_wstr) { *((std::wstring*)param) += std::wstring((const wchar_t*)data, len / 2); return inter_module_data::SET_RESULT_CONTINUE; } std::wstring CDlgMgr::export_config(bool *ok, bool used_in_code, int code_ver) { known_file_util::IJsonW * jsn = known_file_util::create_jsonW(), * child = known_file_util::create_jsonW(); wchar_t text[256] = { 0 }; bool result = false; if (!ok) ok = &result; *ok = false; if (!used_in_code) { WORD vid_f = vid_pid_edit_value(GetDlgItem(IDC_EDIT_VID_SRC)->m_hWnd), pid_f = vid_pid_edit_value(GetDlgItem(IDC_EDIT_PID_SRC)->m_hWnd), vid_t = vid_pid_edit_value(GetDlgItem(IDC_EDIT_VID_TO)->m_hWnd), pid_t = vid_pid_edit_value(GetDlgItem(IDC_EDIT_PID_TO)->m_hWnd), sleep = GetDlgItemInt(IDC_EDIT_SLEEP), speed = GetDlgItemInt(IDC_EDIT_SPEED), port = 0; bool report = is_checked(GetDlgItem(IDC_CHECK2)); BYTE ip1 = 0, ip2 = 0, ip3 = 0, ip4 = 0; if (!vid_f) { GotoDlgCtrl(GetDlgItem(IDC_EDIT_VID_SRC)); jsn->release(); return L"\u8BF7\u91CD\u65B0\u8F93\u5165 \u6E90\uFF36\uFF29\uFF24\uFF01"; } if (!pid_f) { GotoDlgCtrl(GetDlgItem(IDC_EDIT_PID_SRC)); jsn->release(); return L"\u8BF7\u91CD\u65B0\u8F93\u5165 \u6E90\uFF30\uFF29\uFF24\uFF01"; } if (!vid_t) { GotoDlgCtrl(GetDlgItem(IDC_EDIT_VID_TO)); jsn->release(); return L"\u8BF7\u91CD\u65B0\u8F93\u5165 \u76EE\u6807\uFF36\uFF29\uFF24\uFF01"; } if (!pid_t) { GotoDlgCtrl(GetDlgItem(IDC_EDIT_PID_TO)); jsn->release(); return L"\u8BF7\u91CD\u65B0\u8F93\u5165 \u76EE\u6807\uFF30\uFF29\uFF24\uFF01"; } if (report) { ip_.GetAddress(ip1, ip2, ip3, ip4); port = GetDlgItemInt(IDC_EDIT_PORT); ::GetDlgItemTextW(m_hWnd, IDC_EDIT_DB, text, _countof(text) - 1); } child->set_value(L"vid-org", vid_f); child->set_value(L"pid-org", pid_f); child->set_value(L"vid-to", vid_t); child->set_value(L"pid-to", pid_t); child->set_value(L"sleep-time", sleep); child->set_value(L"speed-mode", speed); if (report) { ::GetDlgItemTextW(m_hWnd, IDC_EDIT_DB, text, _countof(text) - 1); std::wstring url(text); swprintf_s(text, _countof(text) - 1, L"%u:", port); url.insert(0, text); swprintf_s(text, _countof(text) - 1, L"%u.%u.%u.%u:", ip1, ip2, ip3, ip4); url.insert(0, text); child->set_value(L"report-url", url.c_str()); } jsn->set_value(L"global", child); } child->release(); if (list_.GetItemCount() == 0) { jsn->release(); return L"\u6CA1\u6709\u8F93\u5165\u6709\u6548\u7684\u6D4B\u8BD5\u9879\u76EE\uFF01"; } for (size_t i = 0; i < list_.GetItemCount(); ++i) { page_config::ITEM item; child = known_file_util::create_jsonW(); list_.GetItemText(i, 1, text, _countof(text) - 1); ::SendMessageW(GetParent()->m_hWnd, WM_GET_TEST_ITEM_NAME, (WPARAM)text, (LPARAM)&item); if (item.name.empty()) { child->release(); jsn->release(); return L"\u6D4B\u8BD5\u9879\u76EE \u201C" + std::wstring(text) + L"\u201D \u4E0D\u5B58\u5728\u4E8E\u914D\u7F6E\u5E93\u4E2D\u3002"; } child->set_value(L"name", item.name.c_str()); if (!used_in_code) { child->set_value(L"title", text); list_.GetItemText(i, 2, text, _countof(text) - 1); child->set_value(L"man", wcscmp(text, L"false") == 0); list_.GetItemText(i, 3, text, _countof(text) - 1); child->set_value(L"err-level", wcscmp(text, L"true") == 0 ? L"fatal" : L"warning"); child->set_value(L"desc", item.desc.c_str()); } else { child->set_value(L"ver", code_ver); } swprintf_s(text, _countof(text) - 1, L"%u", i + 1); jsn->set_value(text, child); child->release(); } std::wstring ret(L""); jsn->to_string(got_wstr, &ret); jsn->release(); if (used_in_code) { size_t pos = ret.find(L"\""); while (pos != std::string::npos) { ret.insert(pos, L"\\"); pos = ret.find(L"\"", pos + 2); } pos = ret.find(L"\\u"); while (pos != std::string::npos) { ret.insert(pos, L"\\"); pos = ret.find(L"\\u", pos + 3); } // divide into multi-lines with 16KB per line ... int lines = 1; wchar_t var[80] = { 0 }; pos = ret.length(); while (pos > 16 * 1024) { pos -= 12 * 1024; while (ret[pos - 1] == L'\\') pos++; lines++; swprintf_s(var, _countof(var) - 1, L"\");\r\nstatic std::wstring jsontext%d(L\"", lines); ret.insert(pos, var); } ret.insert(0, L"static std::string jsontext1(\""); ret += L"\");\r\n"; } *ok = true; return ret; } static void trans_code_json(std::wstring& json) { size_t pos = json.find(L"(L\""); if (pos == std::wstring::npos) return; json.erase(0, pos + 3); pos = json.rfind(L'\"'); if (pos != std::wstring::npos) json.erase(pos); pos = 0; while ((pos = json.find(L"\\\""), pos) != std::wstring::npos) { json.erase(pos++, 1); } pos = 0; while ((pos = json.find(L"\\"), pos) != std::wstring::npos) { json.erase(pos++, 1); } } void CDlgMgr::reload(std::wstring& cont) { if (cont.find(L"static std::wstring") == 0) trans_code_json(cont); known_file_util::IJsonW* jsn = known_file_util::create_jsonW(); if (jsn->attach(cont.c_str())) { known_file_util::IJsonW* child = NULL; const wchar_t* val = NULL; cont = L""; jsn->get_value(L"global", &child); if (child) { int n = 0; child->get_value(L"vid-org", n); SetDlgItemInt(IDC_EDIT_VID_SRC, n); child->get_value(L"pid-org", n); SetDlgItemInt(IDC_EDIT_PID_SRC, n); child->get_value(L"vid-to", n); SetDlgItemInt(IDC_EDIT_VID_TO, n); child->get_value(L"pid-to", n); SetDlgItemInt(IDC_EDIT_PID_TO, n); child->get_value(L"sleep-time", n); SetDlgItemInt(IDC_EDIT_SLEEP, n); child->get_value(L"speed-mode", n); SetDlgItemInt(IDC_EDIT_SPEED, n); if (child->get_value(L"report-url", &val) && val) { size_t pos = 0; cont = val; pos = cont.find(L":"); if (pos++ != std::wstring::npos) { ip_.SetWindowTextW(cont.substr(0, pos).c_str()); cont.erase(0, pos); SetDlgItemInt(IDC_EDIT_PORT, _wtoi(cont.c_str())); pos = cont.find(L":"); if (pos++ != std::wstring::npos) cont.erase(0, pos); } ::SetDlgItemTextW(m_hWnd, IDC_EDIT_DB, cont.c_str()); set_checked(this, IDC_CHECK2, true); OnBnClickedCheckReport(); } child->release(); } list_.DeleteAllItems(); for (int i = 1; 1; ++i) { wchar_t sn[20] = { 0 }; swprintf_s(sn, _countof(sn) - 1, L"%d", i); if (!jsn->get_value(sn, &child)) break; if (child->get_value(L"title", &val)) { int ind = list_.InsertItem(list_.GetItemCount(), sn); list_.SetItemText(ind, 1, val); if (child->get_value(L"err-level", &val)) list_.SetItemText(ind, 3, wcscmp(val, L"fatal") == 0 ? L"true" : L"false"); bool man = false; child->get_value(L"man", man); list_.SetItemText(ind, 2, !man ? L"true" : L"false"); } else if (child->get_value(L"name", &val)) { page_config::ITEM item; ::SendMessageW(GetParent()->m_hWnd, WM_GET_TEST_ITEM_TITLE, (WPARAM)val, (LPARAM)&item); int ind = list_.InsertItem(list_.GetItemCount(), sn); list_.SetItemText(ind, 1, item.title.c_str()); list_.SetItemText(ind, 2, !item.man ? L"true" : L"false"); list_.SetItemText(ind, 3, item.fatal ? L"true" : L"false"); child->get_value(L"ver", ind); SetDlgItemInt(IDC_EDIT_VER, ind); } child->release(); } } jsn->release(); } void CDlgMgr::OnDropFiles(HDROP hDropInfo) { // TODO: 在此添加消息处理程序代码和/或调用默认值 wchar_t path[MAX_PATH] = { 0 }; std::wstring cont(L""); std::string bom(""); DragQueryFileW(hDropInfo, 0, path, _countof(path) - 1); file_util::load_file(path, got_str, &bom); coding_util::bom::to_unicode(bom.c_str(), bom.length(), got_wstr, &cont); reload(cont); __super::OnDropFiles(hDropInfo); } //UINT CDlgMgr::OnGetDlgCode() //{ // // TODO: 在此添加消息处理程序代码和/或调用默认值 // // return __super::OnGetDlgCode(); //} void CDlgMgr::OnListPasteClipboard() { // TODO: 在此添加命令处理程序代码 wchar_t* buf = NULL; size_t len = 0; if (file_util::get_clipboard(buf, &len, CF_UNICODETEXT) == ERROR_INSUFFICIENT_BUFFER) { buf = new wchar_t[len + 8]; memset(buf, 0, (len + 8) * 2); len++; if (file_util::get_clipboard(buf, &len, CF_UNICODETEXT) == ERROR_SUCCESS) { std::wstring cont(buf); reload(cont); } delete[] buf; } } void CDlgMgr::OnNMRClickList1(NMHDR* pNMHDR, LRESULT* pResult) { LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast(pNMHDR); // TODO: 在此添加控件通知处理程序代码 *pResult = 0; POINT pt = { 0 }; CMenu menu; menu.LoadMenuW(MAKEINTRESOURCE(IDR_MENU1)); GetCursorPos(&pt); menu.GetSubMenu(0)->TrackPopupMenu(0, pt.x, pt.y, this); } void CDlgMgr::OnListClear() { // TODO: 在此添加命令处理程序代码 list_.DeleteAllItems(); }