下面是各类头文件的代码:
(以/*************************************/分界)
#pragma once // C16TH 对话框 class C16TH : public CDialogEx { DECLARE_DYNAMIC(C16TH) public: C16TH(CWnd* pParent = nullptr); // 标准构造函数 virtual ~C16TH(); // 对话框数据 #ifdef AFX_DESIGN_TIME enum { IDD = IDD_DIALOG_16th }; #endif protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 DECLARE_MESSAGE_MAP() public: CListBox m_campanyList; CComboBox m_levelCombox; afx_msg void OnBnClickedButton1(); CString m_namelistcom; }; /*****************************************/ #pragma once // C17TH 对话框 class C17TH : public CDialogEx { DECLARE_DYNAMIC(C17TH) public: C17TH(CWnd* pParent = nullptr); // 标准构造函数 virtual ~C17TH(); // 对话框数据 #ifdef AFX_DESIGN_TIME enum { IDD = IDD_DIALOG_17th }; #endif protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 DECLARE_MESSAGE_MAP() public: CListCtrl m_school; afx_msg void OnLvnItemchangedListschool(NMHDR *pNMHDR, LRESULT *pResult); // //列表控件添加的姓名 CString m_strName; BOOL m_radio; afx_msg void OnBnClickedButton1(); CListCtrl m_addelems; CImageList m_pImageList; // 创建图像列表对象 //CImageList m_pImageList_treeicon; // 创建树图图像列表对象 afx_msg void OnBnClickedRadio3(); afx_msg void OnBnClickedRadio4(); CTreeCtrl m_treeSchool; afx_msg void OnTvnSelchangedTree1(NMHDR *pNMHDR, LRESULT *pResult); afx_msg void OnBnClickedButton2(); // CEdit m_strNodeName; CString m_strNodeName; afx_msg void OnBnClickedButton3(); afx_msg void OnBnClickedButton4(); }; /*****************************************/ #pragma once // CComputerName 对话框 class CComputerName : public CDialogEx { DECLARE_DYNAMIC(CComputerName) public: CComputerName(CWnd* pParent = nullptr); // 标准构造函数 virtual ~CComputerName(); // 对话框数据 #ifdef AFX_DESIGN_TIME enum { IDD = IDD_DIALOGComputerName }; #endif protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 DECLARE_MESSAGE_MAP() }; /*****************************************/ #pragma once // CIDName 对话框 class CIDName : public CDialogEx { DECLARE_DYNAMIC(CIDName) public: CIDName(CWnd* pParent = nullptr); // 标准构造函数 virtual ~CIDName(); // 对话框数据 #ifdef AFX_DESIGN_TIME enum { IDD = IDD_DIALOGID }; #endif protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 DECLARE_MESSAGE_MAP() public: // DWORD m_strIPadress; afx_msg void OnBnClickedButton1(); CIPAddressCtrl m_IDAdress; }; /*****************************************/ #pragma once // CSYSTime 对话框 class CSYSTime : public CDialogEx { DECLARE_DYNAMIC(CSYSTime) public: CSYSTime(CWnd* pParent = nullptr); // 标准构造函数 virtual ~CSYSTime(); // 对话框数据 #ifdef AFX_DESIGN_TIME enum { IDD = IDD_DIALOGTime }; #endif protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 DECLARE_MESSAGE_MAP() public: void TimeD_Value(); //时间差函数 // //日历时间变量 CMonthCalCtrl m_canluner; afx_msg void OnMcnSelchangeMonthcalendar1(NMHDR *pNMHDR, LRESULT *pResult); CDateTimeCtrl m_startTime; CDateTimeCtrl m_endTime; afx_msg void OnDtnDatetimechangeDatetimepicker1(NMHDR *pNMHDR, LRESULT *pResult); afx_msg void OnDtnDatetimechangeDatetimepicker2(NMHDR *pNMHDR, LRESULT *pResult); };
下面是各类源文件的代码:
(以/*************************************/分界)
// C16TH.cpp: 实现文件 // #include "pch.h" #include "MFCApplication1.h" #include "C16TH.h" #include "afxdialogex.h" // C16TH 对话框 IMPLEMENT_DYNAMIC(C16TH, CDialogEx) C16TH::C16TH(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_DIALOG_16th, pParent) , m_namelistcom(_T("")) { } C16TH::~C16TH() { } void C16TH::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_LIST1, m_campanyList); DDX_Control(pDX, IDC_COMBO1, m_levelCombox); DDX_Text(pDX, IDC_EDIT1, m_namelistcom); } BEGIN_MESSAGE_MAP(C16TH, CDialogEx) ON_BN_CLICKED(IDC_BUTTON1, &C16TH::OnBnClickedButton1) END_MESSAGE_MAP() // C16TH 消息处理程序 void C16TH::OnBnClickedButton1() { CString strsuminfo; // 总信息 CString strInfo_box; // 存放用户选择学历 CString strInfo_list; // 存放用户选择公司名称 //combox int nSel; nSel = m_levelCombox.GetCurSel(); m_levelCombox.GetLBText(nSel, strInfo_box); // 根据选中索引ID获取该项字符串 //list //if (m_campanyList.GetDlgItem(IDC_LIST1)==NULL) //{ // MessageBox("", "", MB_OK | MB_ICONASTERISK); // return; //} int nCurSelect; // 用户选项ID nCurSelect = m_campanyList.GetCurSel(); // 获取当前选中列表选项的ID // 再根据ID获取对应文本内容 m_campanyList.GetText(nCurSelect, strInfo_list); strsuminfo += "姓名:" + m_namelistcom+"//"+"公司:" + strInfo_list + "//" + "学历:" + strInfo_box + "//"; if (((CButton *)GetDlgItem(IDC_RADIOMAN))->GetCheck() == TRUE) { strsuminfo += "性别:男" ; //strsuminfo += "//"; } else if (((CButton *)GetDlgItem(IDC_RADIOwoman))->GetCheck() == TRUE) { strsuminfo += "性别:女"; //strsuminfo += "//"; } else if (((CButton *)GetDlgItem(IDC_RADIOno))->GetCheck() == TRUE) { strsuminfo += "性别:外星人"; //strsuminfo += "//"; } SetDlgItemText(IDC_EDIT2, strsuminfo); }
// C17TH.cpp: 实现文件 // #include "pch.h" #include "MFCApplication1.h" #include "C17TH.h" #include "afxdialogex.h" // C17TH 对话框 IMPLEMENT_DYNAMIC(C17TH, CDialogEx) C17TH::C17TH(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_DIALOG_17th, pParent) , m_strName(_T("")) , m_radio(FALSE) , m_strNodeName(_T("")) { } C17TH::~C17TH() { } void C17TH::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_LIST_school, m_school); DDX_Text(pDX, IDC_EDIT2, m_strName); DDX_Radio(pDX, IDC_RADIO1, m_radio); DDX_Control(pDX, IDC_LIST2, m_addelems); DDX_Control(pDX, IDC_TREE1, m_treeSchool); // DDX_Control(pDX, IDC_EDIT5, m_strNodeName); DDX_Text(pDX, IDC_EDIT5, m_strNodeName); } BEGIN_MESSAGE_MAP(C17TH, CDialogEx) ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_school, &C17TH::OnLvnItemchangedListschool) ON_BN_CLICKED(IDC_BUTTON1, &C17TH::OnBnClickedButton1) ON_BN_CLICKED(IDC_RADIO3, &C17TH::OnBnClickedRadio3) ON_BN_CLICKED(IDC_RADIO4, &C17TH::OnBnClickedRadio4) ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, &C17TH::OnTvnSelchangedTree1) ON_BN_CLICKED(IDC_BUTTON2, &C17TH::OnBnClickedButton2) ON_BN_CLICKED(IDC_BUTTON3, &C17TH::OnBnClickedButton3) ON_BN_CLICKED(IDC_BUTTON4, &C17TH::OnBnClickedButton4) END_MESSAGE_MAP() // C17TH 消息处理程序 void C17TH::OnLvnItemchangedListschool(NMHDR *pNMHDR, LRESULT *pResult) { LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR); // TODO: 在此添加控件通知处理程序代码 NMLISTVIEW *pNMListView = (NMLISTVIEW*)pNMHDR; CString strSchoolName; // 此变量用来存放字符串 if (pNMListView->iItem != -1) // 如果iItem不是-1,就证明有列表项被选择 { strSchoolName = "排名:"; strSchoolName += m_school.GetItemText(pNMListView->iItem, 0); strSchoolName += " 名称:"; strSchoolName += m_school.GetItemText(pNMListView->iItem, 1); strSchoolName += " 地区:"; strSchoolName += m_school.GetItemText(pNMListView->iItem, 2); SetDlgItemText(IDC_EDIT_schoolinfo, strSchoolName); } *pResult = 0; } void C17TH::OnBnClickedButton1() { // TODO: 在此添加控件通知处理程序代码 UpdateData(TRUE); int iNum = m_addelems.GetItemCount(); CString strSex; // 性别 int iconIndex; // 图标 if (m_radio == 0) { strSex = "男"; iconIndex = 0; } else { strSex = "女"; iconIndex = 1; } m_addelems.InsertItem(iNum, strSex, iconIndex); // 插入行 m_addelems.SetItemText(iNum, 1, m_strName); UpdateData(false); } void C17TH::OnBnClickedRadio3() { // TODO: 在此添加控件通知处理程序代码 m_addelems.ModifyStyle(LVS_ICON | LVS_LIST | LVS_REPORT | CBS_OWNERDRAWFIXED, IDC_LIST2, TRUE); } void C17TH::OnBnClickedRadio4() { // TODO: 在此添加控件通知处理程序代码 m_addelems.ModifyStyle(LVS_ICON | LVS_LIST | LVS_SMALLICON, LVS_REPORT, TRUE); } void C17TH::OnTvnSelchangedTree1(NMHDR *pNMHDR, LRESULT *pResult) { LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR); // TODO: 在此添加控件通知处理程序代码 CString strName = m_treeSchool.GetItemText(pNMTreeView->itemNew.hItem); // 获取活动结点文本 SetDlgItemText(IDC_EDIT_ShowElem, strName); *pResult = 0; } void C17TH::OnBnClickedButton2() { // TODO: 在此添加控件通知处理程序代码 UpdateData(true); if (m_strNodeName.IsEmpty()) { MessageBox("添加结点名称不能为空!!!", "提示", MB_OK | MB_ICONERROR); return; } HTREEITEM hNew = m_treeSchool.InsertItem(m_strNodeName, 1, 0, m_treeSchool.GetSelectedItem()); m_strNodeName = ""; UpdateData(false); m_treeSchool.SetFocus(); // 更新控件显示 } void C17TH::OnBnClickedButton3() { // TODO: 在此添加控件通知处理程序代码 HTREEITEM m_CurTree = m_treeSchool.GetSelectedItem(); CString m_find = m_treeSchool.GetItemText(m_CurTree); if (m_find =="燕山大学") { MessageBox("不能删除根节点!", "提示", MB_OK | MB_ICONINFORMATION); return; } else { m_treeSchool.DeleteItem(m_CurTree); } } void C17TH::OnBnClickedButton4() { // TODO: 在此添加控件通知处理程序代码 m_treeSchool.DeleteAllItems(); HTREEITEM hRoot = m_treeSchool.InsertItem("燕山大学", 1, 0, TVI_ROOT); // 添加一级结点 MessageBox("所有结点全部已经删除成功!", "提示", MB_OK | MB_ICONINFORMATION); }
// CComputerName.cpp: 实现文件 // #include "pch.h" #include "MFCApplication1.h" #include "CComputerName.h" #include "afxdialogex.h" // CComputerName 对话框 IMPLEMENT_DYNAMIC(CComputerName, CDialogEx) CComputerName::CComputerName(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_DIALOGComputerName, pParent) { } CComputerName::~CComputerName() { } void CComputerName::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CComputerName, CDialogEx) END_MESSAGE_MAP() // CComputerName 消息处理程序
// CIDName.cpp: 实现文件 // #include "pch.h" #include "MFCApplication1.h" #include "CIDName.h" #include "afxdialogex.h" // CIDName 对话框 IMPLEMENT_DYNAMIC(CIDName, CDialogEx) CIDName::CIDName(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_DIALOGID, pParent) { } CIDName::~CIDName() { } void CIDName::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); // DDX_IPAddress(pDX, IDC_IPADDRESS1, m_strIPadress); DDX_Control(pDX, IDC_IPADDRESS1, m_IDAdress); } BEGIN_MESSAGE_MAP(CIDName, CDialogEx) ON_BN_CLICKED(IDC_BUTTON1, &CIDName::OnBnClickedButton1) END_MESSAGE_MAP() // CIDName 消息处理程序 void CIDName::OnBnClickedButton1() { // TODO: 在此添加控件通知处理程序代码 WORD wVersionRequested; WSADATA wsaData; char strLocalName[255]; CString strIpAddress; PHOSTENT pHostInfo; wVersionRequested = MAKEWORD(2, 0); if (WSAStartup(wVersionRequested, &wsaData) == 0) // 初始数据 { if (gethostname(strLocalName, sizeof(strLocalName)) == 0) // 获取主机名称 { if ((pHostInfo = gethostbyname(strLocalName)) != NULL) // 根据主机名称获取对应主机地址 { strIpAddress = inet_ntoa(*(struct in_addr*)*pHostInfo->h_addr_list); } } WSACleanup(); } m_IDAdress.SetWindowText(strIpAddress); // 将获取本机的IP显示到IP控件 UpdateData(FALSE); }
// CSYSTime.cpp: 实现文件 // #include "pch.h" #include "MFCApplication1.h" #include "CSYSTime.h" #include "afxdialogex.h" // CSYSTime 对话框 IMPLEMENT_DYNAMIC(CSYSTime, CDialogEx) CSYSTime::CSYSTime(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_DIALOGTime, pParent) { } CSYSTime::~CSYSTime() { } void CSYSTime::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_MONTHCALENDAR1, m_canluner); DDX_Control(pDX, IDC_DATETIMEPICKER1, m_startTime); DDX_Control(pDX, IDC_DATETIMEPICKER2, m_endTime); } BEGIN_MESSAGE_MAP(CSYSTime, CDialogEx) ON_NOTIFY(MCN_SELCHANGE, IDC_MONTHCALENDAR1, &CSYSTime::OnMcnSelchangeMonthcalendar1) ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER1, &CSYSTime::OnDtnDatetimechangeDatetimepicker1) ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER2, &CSYSTime::OnDtnDatetimechangeDatetimepicker2) END_MESSAGE_MAP() // CSYSTime 消息处理程序 void CSYSTime::OnMcnSelchangeMonthcalendar1(NMHDR *pNMHDR, LRESULT *pResult) { LPNMSELCHANGE pSelChange = reinterpret_cast<LPNMSELCHANGE>(pNMHDR); // TODO: 在此添加控件通知处理程序代码 SYSTEMTIME st = { 0 }; m_canluner.GetCurSel(&st); CString strOutTime; strOutTime.Format("【你选择的日期为】:%d年%d月%d日", st.wYear, st.wMonth, st.wDay/*,st.wHour,st.wMinute,st.wSecond*/); SetDlgItemText(IDC_STATIC_TimeUp, strOutTime); *pResult = 0; } void CSYSTime::OnDtnDatetimechangeDatetimepicker1(NMHDR *pNMHDR, LRESULT *pResult) { LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR); // TODO: 在此添加控件通知处理程序代码 TimeD_Value(); *pResult = 0; } void CSYSTime::OnDtnDatetimechangeDatetimepicker2(NMHDR *pNMHDR, LRESULT *pResult) { LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR); // TODO: 在此添加控件通知处理程序代码 TimeD_Value(); *pResult = 0; } void CSYSTime::TimeD_Value() { SYSTEMTIME time_begin = { 0 }, time_end = { 0 }; m_startTime.GetTime(&time_begin); // 获取起始时间 m_endTime.GetTime(&time_end); // 获取结束时间 FILETIME ft_begin, ft_end; SystemTimeToFileTime(&time_begin, &ft_begin); SystemTimeToFileTime(&time_end, &ft_end); ULARGE_INTEGER u_begin, u_end; u_begin.u.HighPart = ft_begin.dwHighDateTime; u_begin.u.LowPart = ft_begin.dwLowDateTime; u_end.u.HighPart = ft_end.dwHighDateTime; u_end.u.LowPart = ft_end.dwLowDateTime; ULONGLONG ull_span = 0; if (u_end.QuadPart >= u_begin.QuadPart) { ull_span = u_end.QuadPart - u_begin.QuadPart; } else { ull_span = u_begin.QuadPart - u_end.QuadPart; } int n_seconds = static_cast<int>(ull_span / 10000000); // 秒 int n_minuts = n_seconds / 60; // 分 int n_hour = n_minuts / 60; // 小时 int n_days = n_hour / 24; // 天 CString strOutTime; strOutTime.Format("秒数:%d秒\r\n分钟:%d分钟\r\n小时:%d小时\r\n天数:%d天\r\n", n_seconds, n_minuts, n_hour, n_days); SetDlgItemText(IDC_EDIT_TimeDTime, strOutTime); }