// EditorDlg.cpp : 实现文件 // #include "stdafx.h" #include "Editor.h" #include "EditorDlg.h" #include "AddDevice.h" #include "AddCmdImpl.h" #include "IniReader.h" #include "AddCmdStlye.h" #include "AddCmdImplItem.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // 用于应用程序“关于”菜单项的 CAboutDlg 对话框 class CAboutDlg : public CDialog { public: CAboutDlg(); // 对话框数据 enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 // 实现 protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CEditorDlg 对话框 CEditorDlg::CEditorDlg(CWnd* pParent /*=NULL*/) : CDialog(CEditorDlg::IDD, pParent) , m_strDeviceName(_T("")) , m_strDeviceID(_T("")) , m_strResponseTime(_T("")) , m_strLineType(_T("")) , m_strComType(_T("")) , m_strPindef(_T("")) , m_strFactory(_T("")) , m_strClassType(_T("")) , m_strDeviceName2(_T("")) , m_strModelNum(_T("")) , m_strSeries(_T("")) , m_strProtocol(_T("")) , m_strCmdSize(_T("")) , m_strCmdKey1(_T("")) , m_strKeyLen(_T("")) , m_strKeyContx1(_T("")) , m_strMark(_T("")) , m_strCmdTip(_T("")) , m_strCmdKey2(_T("")) , m_strKeyContx2(_T("")) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_strOldDeviceName = ""; m_strOldKey = ""; m_strOldMark = ""; } void CEditorDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_TREE1, m_CtrlTree); DDX_Control(pDX, IDC_TREE2, m_CtrlSubTree); DDX_Text(pDX, ET_DEVICENAME, m_strDeviceName); DDX_Text(pDX, ET_DEVICEID, m_strDeviceID); DDX_Control(pDX, CB_RATE, m_cobRate); DDX_Control(pDX, CB_DATABIT, m_cobDatabit); DDX_Control(pDX, CB_STOPBIT, m_cobStopbit); DDX_Control(pDX, CB_PARITY, m_cobParity); DDX_Text(pDX, ET_RESPONSETIME, m_strResponseTime); DDX_Text(pDX, ET_FREQUENCY, m_strFrequency); DDX_Text(pDX, ET_LINETYPE, m_strLineType); DDX_Text(pDX, ET_COMTYPE, m_strComType); DDX_Text(pDX, ET_PINDEF, m_strPindef); DDX_Control(pDX, CB_STORERECV, m_cobStore); DDX_Text(pDX, ET_FACTORY, m_strFactory); DDX_Text(pDX, ET_CLASSTYPE, m_strClassType); DDX_Text(pDX, ET_NAME, m_strDeviceName2); DDX_Text(pDX, ET_MODELNUM, m_strModelNum); DDX_Text(pDX, ET_SERIES, m_strSeries); DDX_Text(pDX, ET_PROTOCOL, m_strProtocol); DDX_Text(pDX, ET_CMDSIZE, m_strCmdSize); DDX_Text(pDX, ET_CMDKEY1, m_strCmdKey1); DDX_Text(pDX, ET_KEYLEN, m_strKeyLen); DDX_Text(pDX, ET_KEYCONTX, m_strKeyContx1); DDX_Text(pDX, ET_MARK, m_strMark); DDX_Text(pDX, ET_CMDTIP, m_strCmdTip); DDX_Text(pDX, ET_CMDKEY2, m_strCmdKey2); DDX_Text(pDX, ET_KEYCONTXT2, m_strKeyContx2); DDX_Control(pDX, Btn_ModifyDevice, m_btnModifyDevice); DDX_Control(pDX, Btn_ModifyCmdStyle, m_btnModifyCmdStyle); DDX_Control(pDX, Btn_ModifyCmdImpl, m_btnModifyCmdImpl); DDX_Control(pDX, CB_KEYTYPE, m_cobKeyType); } BEGIN_MESSAGE_MAP(CEditorDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_COMMAND(MU_ADDDEVICEPROPERTY, &CEditorDlg::OnAddDeviceProperty) ON_COMMAND(MU_ADDDEVICE, &CEditorDlg::OnAdddevice) ON_COMMAND(MU_ADDCMDFORMATITEM, &CEditorDlg::OnAddcmdStyle) ON_COMMAND(MU_ADDCMDIMPL, &CEditorDlg::OnAddcmdimpl) ON_COMMAND(MU_ADDCMDIMTEIMPL, &CEditorDlg::OnAddcmdimteimpl) ON_BN_CLICKED(Btn_ModifyDevice, &CEditorDlg::OnBnClickedModifydevice) ON_BN_CLICKED(Btn_ModifyCmdStyle, &CEditorDlg::OnBnClickedModifycmdstyle) ON_BN_CLICKED(Btn_ModifyCmdImpl, &CEditorDlg::OnBnClickedModifycmdimpl) ON_COMMAND(MU_DELETEDEVICE, &CEditorDlg::OnDeletedevice) ON_COMMAND(MU_DELETEITEM, &CEditorDlg::OnDeleteitem) ON_COMMAND(MU_DELETECMDIMPL, &CEditorDlg::OnDeletecmdimpl) ON_WM_SIZE() ON_WM_VSCROLL() ON_WM_HSCROLL() END_MESSAGE_MAP() // CEditorDlg 消息处理程序 BOOL CEditorDlg::OnInitDialog() { CDialog::OnInitDialog(); // 将\“关于...\”菜单项添加到系统菜单中。 // IDM_ABOUTBOX 必须在系统命令范围内。 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动 // 执行此操作 SetIcon(m_hIcon, TRUE); // 设置大图标 SetIcon(m_hIcon, FALSE); // 设置小图标 // TODO: 在此添加额外的初始化代码 GetWindowRect(m_rect); m_nHeightScrollPos = 0; m_nWidthScrollPos = 0; InitSTButtons(); ////////////////// CString strPath; TCHAR szFull[_MAX_PATH]; TCHAR szDrive[_MAX_DRIVE]; TCHAR szDir[_MAX_DIR]; ::GetModuleFileName(NULL, szFull, sizeof(szFull)/sizeof(TCHAR)); _tsplitpath(szFull, szDrive, szDir, NULL, NULL); _tcscpy(szFull, szDrive); _tcscat(szFull, szDir); strPath = CString(szFull); CString strIni; strIni.Format("%s\\config.ini",strPath); CIniReader IniReader(strIni); m_strDepotPath = IniReader.GetKeyValueText("name","DeviceLibrary"); m_strRutDepotPath = IniReader.GetKeyValueText("name","RunUnitLibrary"); // TODO: 在此添加额外的初始化 // [3/29/2013 Zero.t] m_imgList.Create(IDB_BITMAP1,16, 6, RGB(255,255,255)); m_CtrlTree.SetImageList(&m_imgList,TVSIL_NORMAL); m_CtrlSubTree.SetImageList(&m_imgList,TVSIL_NORMAL); hRunRootItem = m_CtrlTree.InsertItem("当前运行时设备库设备",2,2); InitTreeCtrlInfo(); return TRUE; // 除非设置了控件的焦点,否则返回 TRUE } void CEditorDlg::ClearCtrlText() { m_strDeviceName = ""; m_strDeviceName2 = ""; m_strDeviceID = ""; m_strClassType = ""; m_strCmdKey1 = ""; m_strCmdKey2 = ""; m_strCmdSize = ""; m_strCmdTip = ""; m_strComType = ""; m_strFactory = ""; m_strFrequency = ""; m_strKeyContx1 = ""; m_strKeyContx2 = ""; m_strKeyLen = ""; m_strLineType = ""; m_strMark = ""; m_strModelNum = ""; m_strPindef = ""; m_strProtocol = ""; m_strResponseTime = ""; m_strSeries = ""; } void CEditorDlg::InitSTButtons() { short shBtnColor = 30; m_btnModifyDevice.SetIcon(IDI_ICON3); m_btnModifyDevice.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, shBtnColor); m_btnModifyDevice.SetColor(CButtonST::BTNST_COLOR_FG_IN, RGB(0, 128, 0)); m_btnModifyCmdStyle.SetIcon(IDI_ICON3); m_btnModifyCmdStyle.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, shBtnColor); m_btnModifyCmdStyle.SetColor(CButtonST::BTNST_COLOR_FG_IN, RGB(0, 128, 0)); m_btnModifyCmdImpl.SetIcon(IDI_ICON3); m_btnModifyCmdImpl.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, shBtnColor); m_btnModifyCmdImpl.SetColor(CButtonST::BTNST_COLOR_FG_IN, RGB(0, 128, 0)); } void CEditorDlg::ClearTreeCtrlInfo(HTREEITEM hItem) { STTreeInfo tTreeInfo = {0}; vector ::iterator itType; if ( hItem == NULL ) { for ( itType = vtSTTreeInfo.begin(); itType != vtSTTreeInfo.end();) { tTreeInfo = *itType; STFactory tFactory = {0}; vector ::iterator itFactory; for ( itFactory = tTreeInfo.vtFactory.begin(); itFactory != tTreeInfo.vtFactory.end(); ) { tFactory = *itFactory; vector ::iterator itDevice; for( itDevice = tFactory.vtDevice.begin(); itDevice != tFactory.vtDevice.end(); ) { m_CtrlTree.DeleteItem((*itDevice).hDevice); itDevice = tFactory.vtDevice.erase(itDevice); } m_CtrlTree.DeleteItem((*itFactory).hFactory); itFactory = tTreeInfo.vtFactory.erase(itFactory); } m_CtrlTree.DeleteItem((*itType).hType); itType = vtSTTreeInfo.erase(itType); } } else { BOOL bIsDelete = FALSE; for ( itType = vtSTTreeInfo.begin(); itType != vtSTTreeInfo.end(); itType++) { tTreeInfo = *itType; STFactory tFactory = {0}; vector ::iterator itFactory; for ( itFactory = tTreeInfo.vtFactory.begin(); itFactory != tTreeInfo.vtFactory.end(); itFactory++) { tFactory = *itFactory; vector ::iterator itDevice; for( itDevice = tFactory.vtDevice.begin(); itDevice != tFactory.vtDevice.end();itDevice++ ) { if ( hItem == (*itDevice).hDevice ) { m_CtrlTree.DeleteItem((*itDevice).hDevice); tFactory.vtDevice.erase(itDevice); //goto End; bIsDelete = TRUE; break; } } if ( bIsDelete ) { *itFactory = tFactory; if ( tFactory.vtDevice.size() == 0) { m_CtrlTree.DeleteItem((*itFactory).hFactory); tTreeInfo.vtFactory.erase(itFactory); } break; } } if ( bIsDelete ) { *itType = tTreeInfo; if ( tTreeInfo.vtFactory.size() == 0) { m_CtrlTree.DeleteItem((*itType).hType); vtSTTreeInfo.erase(itType); } break; } } } //End: Sleep(10); } void CEditorDlg::InitTreeCtrlInfo() { ClearTreeCtrlInfo(); #if 1 CMarkup xml; if ( !xml.Load(m_strDepotPath) ) { //LOG4C((LOG_NOTICE,"设备库不存在")); return; } xml.FindElem(); xml.IntoElem(); int nCount = 0; BOOL bNoDevice = TRUE; BOOL bNoFactory = TRUE; BOOL bNoType = TRUE; while( xml.FindElem("object_depot")) { CString strDevice = xml.GetAttrib("name"); xml.FindChildElem("document"); CString strFactory = xml.GetChildAttrib("Factory"); CString strType = xml.GetChildAttrib("deviceType"); STTreeInfo tTreeInfo = {0}; vector ::iterator it; for ( it = vtSTTreeInfo.begin(); it != vtSTTreeInfo.end(); it++ ) { tTreeInfo = *it; if ( tTreeInfo.strType == strType && tTreeInfo.hType != NULL ) { bNoType = FALSE; STFactory tFactory = {0}; vector ::iterator itFactory; for ( itFactory = tTreeInfo.vtFactory.begin(); itFactory != tTreeInfo.vtFactory.end(); itFactory++) { tFactory = *itFactory; if ( tFactory.strFactory == strFactory && tFactory.hFactory != NULL ) { bNoFactory = FALSE; STDevice tDevice = {0}; vector ::iterator itDevice; for( itDevice = tFactory.vtDevice.begin(); itDevice != tFactory.vtDevice.end(); itDevice++) { tDevice = *itDevice; if ( tDevice.strDevice == strDevice && tDevice.hDevice != NULL ) { bNoDevice = FALSE; break; } } if ( bNoDevice ) { tDevice.strDevice = strDevice; tDevice.hDevice = m_CtrlTree.InsertItem(strDevice,3,3,tFactory.hFactory); tFactory.vtDevice.push_back(tDevice); *itFactory = tFactory; } else { bNoDevice = TRUE; } break; } } if ( bNoFactory ) { STFactory st_Factory = {0}; st_Factory.strFactory = strFactory; st_Factory.hFactory = m_CtrlTree.InsertItem(strFactory,0,1,tTreeInfo.hType); //st_Factory.hFactory = m_CtrlTree.InsertItem(strFactory,tTreeInfo.hType); STDevice stDevice = {0}; stDevice.strDevice = strDevice; stDevice.hDevice = m_CtrlTree.InsertItem(strDevice,3,3,st_Factory.hFactory); st_Factory.vtDevice.push_back(stDevice); tTreeInfo.vtFactory.push_back(st_Factory); }else { bNoFactory = TRUE; } *it = tTreeInfo; break; } } if ( bNoType ) { STTreeInfo st_TreeInfo={0}; st_TreeInfo.strType = strType; st_TreeInfo.hType = m_CtrlTree.InsertItem(strType,0,1,hRunRootItem); STFactory st_Factory = {0}; st_Factory.strFactory = strFactory; st_Factory.hFactory = m_CtrlTree.InsertItem(strFactory,0,1,st_TreeInfo.hType); //st_Factory.hFactory = m_CtrlTree.InsertItem(strFactory,st_TreeInfo.hType); STDevice st_Device = {0}; st_Device.strDevice = strDevice; st_Device.hDevice = m_CtrlTree.InsertItem(strDevice,3,3,st_Factory.hFactory); st_Factory.vtDevice.push_back(st_Device); st_TreeInfo.vtFactory.push_back(st_Factory); vtSTTreeInfo.push_back(st_TreeInfo); } else { bNoType = TRUE; } nCount++; } Expand_Tree_1(); CString strCount; strCount.Format("当前可使用设备总数:%d",nCount); SetDlgItemText(TX_COUNT,strCount); xml.OutOfElem(); #endif } /************************************************************************/ /* 函数:返回指定树项在vtSTTreeInfo中的层信息 返回值: = -1: 表示没有项的存在; = 0 : 表示hItem是根项; = 1 : 表示hItem是类别层的项; = 2 : 表示hItem是厂家层的项; = 3 : 表示hItem是设备层的项; */ /************************************************************************/ int CEditorDlg::TypeTreeItem(HTREEITEM &hItem) { int nType = -1; if ( hItem == hRunRootItem ) return 0; STTreeInfo tTreeInfo = {0}; vector ::iterator it; for ( it = vtSTTreeInfo.begin(); it != vtSTTreeInfo.end(); it++ ) { tTreeInfo = *it; if ( tTreeInfo.hType == hItem ) { nType = 1; break; } else { STFactory tFactory = {0}; vector ::iterator itFactory; for ( itFactory = tTreeInfo.vtFactory.begin(); itFactory != tTreeInfo.vtFactory.end(); itFactory++) { tFactory = *itFactory; if ( tFactory.hFactory == hItem ) { nType = 2; break; } else { STDevice tDevice = {0}; vector ::iterator itDevice; for( itDevice = tFactory.vtDevice.begin(); itDevice != tFactory.vtDevice.end(); itDevice++) { tDevice = *itDevice; if ( tDevice.hDevice == hItem ) { nType = 3; break; } } } if ( nType != -1) break; } } if ( nType != -1) break; } return nType; } int CEditorDlg::TypeCommandTreeItem(HTREEITEM &hItem) { int nType = -1; if ( hItem == tSTDeviceImpl.hDevice ) { return 0; } if ( hItem == tSTDeviceImpl.tSTComInfo.hComInfo ) { return 1; } if ( hItem == tSTDeviceImpl.tSTComImpl.hComImpl ) { return 2; } vector ::iterator itComInfoImplItem; for ( itComInfoImplItem = tSTDeviceImpl.tSTComInfo.vtComInfoImpl.begin(); itComInfoImplItem != tSTDeviceImpl.tSTComInfo.vtComInfoImpl.end(); itComInfoImplItem++ ) { if ( hItem == (*itComInfoImplItem).hComInfoImpl ) { nType = 3; break; } } STComTable tComTable; vector ::iterator itComTable ; for ( itComTable = tSTDeviceImpl.tSTComImpl.vtComTable.begin(); itComTable != tSTDeviceImpl.tSTComImpl.vtComTable.end(); itComTable++ ) { tComTable = *itComTable; if ( hItem == tComTable.hComTable ) { nType = 4; break; } else { vector ::iterator itComTableImpl; for ( itComTableImpl = tComTable.vtComTableImpl.begin(); itComTableImpl != tComTable.vtComTableImpl.end(); itComTableImpl++) { if ( hItem == (*itComTableImpl).hComTableImpl ) { nType = 5; break; } } } } return nType; } void CEditorDlg::InitDeviceComInfo(CString strName) { ClearTreeInfo(); CObjectdepot tObjectdepot; tObjectdepot.SetDevicesDepotPath(m_strDepotPath); tObjectdepot.SetRuntimeDevicesDepotPath(m_strRutDepotPath); STDepotObject *pDepotObject = tObjectdepot.LookupElement(strName) ; if ( pDepotObject == NULL ) return; // 显示界面数据 [4/2/2013 Zero.t] m_strDeviceName = strName; m_strDeviceID.Format("%s",pDepotObject->szSID); CString strRate ; strRate.Format("%d",pDepotObject->st_depotphy.iRate); m_cobRate.SelectString(-1,strRate); CString strDatabit; strDatabit.Format("%d",pDepotObject->st_depotphy.iDBit); m_cobDatabit.SelectString(-1,strDatabit); m_cobStopbit.SetCurSel(pDepotObject->st_depotphy.iSBit); m_cobParity.SetCurSel(pDepotObject->st_depotphy.iPaty); m_strResponseTime.Format("%d",pDepotObject->st_depotphy.iRsTm); m_strFrequency.Format("%d",pDepotObject->st_depotphy.iIntl); m_strComType.Format("%s",pDepotObject->st_depotphy.szComType); m_strLineType.Format("%s",pDepotObject->st_depotphy.szLineType); m_strPindef.Format("%s",pDepotObject->st_depotphy.szPinDef); m_strFactory.Format("%s",pDepotObject->st_depotdoc.szFactory); m_strClassType.Format("%s",pDepotObject->st_depotdoc.szdeviceType); m_strSeries.Format("%s",pDepotObject->st_depotdoc.szdeviceClass); m_strProtocol.Format("%s",pDepotObject->st_depotdoc.szProtocol); m_strDeviceName2.Format("%s",pDepotObject->st_depotdoc.szdeviceName); m_strModelNum.Format("%s",pDepotObject->st_depotdoc.szUnitType); UpdateData(FALSE); // [4/1/2013 Zero.t] tSTDeviceImpl.hDevice = m_CtrlSubTree.InsertItem(strName,2,2); tSTDeviceImpl.strDevice = strName; STCommandFormat tComformat; STCommandTable tCommtable; vector ::iterator itComformat; vector ::iterator itCommtable; tSTDeviceImpl.tSTComInfo.hComInfo = m_CtrlSubTree.InsertItem("指令格式",3,3,tSTDeviceImpl.hDevice); tSTDeviceImpl.tSTComInfo.strComInfo = "指令格式"; tSTDeviceImpl.tSTComImpl.hComImpl = m_CtrlSubTree.InsertItem("指令实现",3,3,tSTDeviceImpl.hDevice); tSTDeviceImpl.tSTComInfo.strComInfo = "指令实现"; for ( itComformat = pDepotObject->vt_commandformat.begin(); itComformat != pDepotObject->vt_commandformat.end(); itComformat++ ) { tComformat = *itComformat; STComInfoImplItem tComInfoImplItem; tComInfoImplItem.strComInfoImpl.Format("%s",tComformat.szName); // 以关键字为项名描述; tComInfoImplItem.hComInfoImpl = m_CtrlSubTree.InsertItem(tComInfoImplItem.strComInfoImpl,10,10,tSTDeviceImpl.tSTComInfo.hComInfo); tSTDeviceImpl.tSTComInfo.vtComInfoImpl.push_back(tComInfoImplItem); } for( itCommtable = pDepotObject->vt_commandtable.begin(); itCommtable != pDepotObject->vt_commandtable.end(); itCommtable++ ) { tCommtable = *itCommtable; STComTable tComTable; tComTable.strComTable.Format("%s",tCommtable.szMark); // 以指令的特征码为项名描述; tComTable.hComTable = m_CtrlSubTree.InsertItem(tComTable.strComTable,0,0,tSTDeviceImpl.tSTComImpl.hComImpl); STCommandStyle tComStyle; vector ::iterator itComStyle; for ( itComStyle = tCommtable.vt_commandstyle.begin(); itComStyle != tCommtable.vt_commandstyle.end(); itComStyle++) { tComStyle = *itComStyle; STComTableImpl tComTableImpl; tComTableImpl.strComTableImpl.Format("%s",tComStyle.szName); tComTableImpl.hComTableImpl = m_CtrlSubTree.InsertItem(tComTableImpl.strComTableImpl,10,10,tComTable.hComTable); tComTable.vtComTableImpl.push_back(tComTableImpl); } tSTDeviceImpl.tSTComImpl.vtComTable.push_back(tComTable); } Expand_Tree_2(); if ( pDepotObject ) { delete pDepotObject; pDepotObject = NULL; } } void CEditorDlg::ClearTreeInfo(HTREEITEM hItem) { // 1.清空树列表 if ( hItem == NULL ) { m_CtrlSubTree.DeleteItem(tSTDeviceImpl.hDevice); m_CtrlSubTree.DeleteItem(tSTDeviceImpl.tSTComInfo.hComInfo); m_CtrlSubTree.DeleteItem(tSTDeviceImpl.tSTComImpl.hComImpl); //STComInfoImplItem tComInfoImplItem; vector ::iterator itComInfoImplItem; for ( itComInfoImplItem = tSTDeviceImpl.tSTComInfo.vtComInfoImpl.begin(); itComInfoImplItem != tSTDeviceImpl.tSTComInfo.vtComInfoImpl.end();) { m_CtrlSubTree.DeleteItem((*itComInfoImplItem).hComInfoImpl); itComInfoImplItem = tSTDeviceImpl.tSTComInfo.vtComInfoImpl.erase(itComInfoImplItem); } STComTable tComTable; vector ::iterator itComTable; for ( itComTable = tSTDeviceImpl.tSTComImpl.vtComTable.begin(); itComTable != tSTDeviceImpl.tSTComImpl.vtComTable.end();) { tComTable = *itComTable; vector ::iterator itComTableImpl; for ( itComTableImpl = tComTable.vtComTableImpl.begin(); itComTableImpl != tComTable.vtComTableImpl.end();) { m_CtrlSubTree.DeleteItem((*itComTableImpl).hComTableImpl); itComTableImpl = tComTable.vtComTableImpl.erase(itComTableImpl); } m_CtrlSubTree.DeleteItem((*itComTable).hComTable); itComTable = tSTDeviceImpl.tSTComImpl.vtComTable.erase(itComTable); } // 2.清空控件; m_strCmdSize = ""; m_strCmdKey1 = ""; m_strKeyLen = ""; m_strKeyContx1 = ""; m_cobKeyType.SetCurSel(-1); m_cobStore.SetCurSel(-1); m_strMark = ""; m_strCmdTip = ""; m_strCmdKey2 = ""; m_strKeyContx2 = ""; UpdateData(FALSE); } else { //STComInfoImplItem tComInfoImplItem; vector ::iterator itComInfoImplItem; for ( itComInfoImplItem = tSTDeviceImpl.tSTComInfo.vtComInfoImpl.begin(); itComInfoImplItem != tSTDeviceImpl.tSTComInfo.vtComInfoImpl.end();itComInfoImplItem++) { if ( hItem == (*itComInfoImplItem).hComInfoImpl ) { m_CtrlSubTree.DeleteItem((*itComInfoImplItem).hComInfoImpl); tSTDeviceImpl.tSTComInfo.vtComInfoImpl.erase(itComInfoImplItem); return; } } STComTable tComTable; vector ::iterator itComTable; for ( itComTable = tSTDeviceImpl.tSTComImpl.vtComTable.begin(); itComTable != tSTDeviceImpl.tSTComImpl.vtComTable.end();itComTable++) { tComTable = *itComTable; if ( hItem == tComTable.hComTable ) { vector ::iterator itComTableImpl; for ( itComTableImpl = tComTable.vtComTableImpl.begin(); itComTableImpl != tComTable.vtComTableImpl.end();) { m_CtrlSubTree.DeleteItem(hItem); itComTableImpl = tComTable.vtComTableImpl.erase(itComTableImpl); } *itComTable = tComTable; m_CtrlSubTree.DeleteItem(hItem); tSTDeviceImpl.tSTComImpl.vtComTable.erase(itComTable); return; }else { vector ::iterator itComTableImpl; for ( itComTableImpl = tComTable.vtComTableImpl.begin(); itComTableImpl != tComTable.vtComTableImpl.end();itComTableImpl++) { if ( hItem == (*itComTableImpl).hComTableImpl ) { m_CtrlSubTree.DeleteItem(hItem); tComTable.vtComTableImpl.erase(itComTableImpl); return; } } } } } } void CEditorDlg::InitCommandInfo(HTREEITEM &hItem) { // 1.判断树结点属于哪个层次的; // 2.根据层次结点处理相应的事件; int nType = TypeCommandTreeItem(hItem); if ( nType != 5 && nType != 3 && nType != 4) { return; } CString strKeyName = m_CtrlSubTree.GetItemText(hItem); //AfxMessageBox(strName); CObjectdepot tObjectdepot; tObjectdepot.SetDevicesDepotPath(m_strDepotPath); tObjectdepot.SetRuntimeDevicesDepotPath(m_strRutDepotPath); STDepotObject *pDepotObject = tObjectdepot.LookupElement(m_strDeviceName) ; if ( pDepotObject == NULL ) return; if ( nType == 3 ) { GetDlgItem(Btn_ModifyCmdStyle)->EnableWindow(); m_strOldKey = strKeyName;//m_CtrlSubTree.GetItemText(hItem); vector ::iterator itCommandformat; for ( itCommandformat = pDepotObject->vt_commandformat.begin(); itCommandformat != pDepotObject->vt_commandformat.end();itCommandformat++ ) { if ( strKeyName.Compare((*itCommandformat).szName) == 0 ) { m_strCmdSize.Format("%d",pDepotObject->ByteCount); m_strCmdKey1.Format("%s",(*itCommandformat).szName); m_strKeyLen.Format("%s",(*itCommandformat).szLen); m_strKeyContx1.Format("%s",(*itCommandformat).szData); m_cobKeyType.SelectString(-1,(*itCommandformat).szType); UpdateData(FALSE); break; } } } if ( nType == 4 ) { GetDlgItem(Btn_ModifyCmdImpl)->EnableWindow(); m_strOldMark = strKeyName; HTREEITEM hParent = m_CtrlSubTree.GetParentItem(hItem); STCommandTable tCommandtable; vector ::iterator itCommandtable; for ( itCommandtable = pDepotObject->vt_commandtable.begin(); itCommandtable != pDepotObject->vt_commandtable.end();itCommandtable++ ) { tCommandtable = *itCommandtable; if ( m_strOldMark.Compare(tCommandtable.szMark) == 0 ) { m_cobStore.SetCurSel(tCommandtable.bRecv); m_strMark.Format("%s",tCommandtable.szMark); m_strCmdTip.Format("%s",tCommandtable.szTip); m_strCmdKey2 = ""; m_strKeyContx2 = ""; UpdateData(FALSE); break; } } } if ( nType == 5 ) { GetDlgItem(Btn_ModifyCmdImpl)->EnableWindow(); m_strOldKey = strKeyName; HTREEITEM hParent = m_CtrlSubTree.GetParentItem(hItem); //CString strMark = m_CtrlSubTree.GetItemText(hParent); m_strOldMark = m_CtrlSubTree.GetItemText(hParent); STCommandTable tCommandtable; vector ::iterator itCommandtable; for ( itCommandtable = pDepotObject->vt_commandtable.begin(); itCommandtable != pDepotObject->vt_commandtable.end();itCommandtable++ ) { tCommandtable = *itCommandtable; //if ( strMark.Compare(tCommandtable.szMark) != 0 ) if ( m_strOldMark.Compare(tCommandtable.szMark) != 0 ) { continue; } vector ::iterator itCommandstyle; for ( itCommandstyle = tCommandtable.vt_commandstyle.begin(); itCommandstyle != tCommandtable.vt_commandstyle.end(); itCommandstyle++ ) { if ( strKeyName.Compare((*itCommandstyle).szName) == 0 ) { m_cobStore.SetCurSel(tCommandtable.bRecv); m_strMark.Format("%s",tCommandtable.szMark); m_strCmdTip.Format("%s",tCommandtable.szTip); m_strCmdKey2.Format("%s",(*itCommandstyle).szName); m_strKeyContx2.Format("%s",(*itCommandstyle).szData); UpdateData(FALSE); break; } } } } if ( pDepotObject ) { delete pDepotObject; pDepotObject = NULL; } } void CEditorDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // 如果向对话框添加最小化按钮,则需要下面的代码 // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序, // 这将由框架自动完成。 void CEditorDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // 用于绘制的设备上下文 SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); // 使图标在工作矩形中居中 int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // 绘制图标 dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } //当用户拖动最小化窗口时系统调用此函数取得光标显示。 HCURSOR CEditorDlg::OnQueryDragIcon() { return static_cast(m_hIcon); } BOOL CEditorDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) { // TODO: 在此添加专用代码和/或调用基类 if ( !::IsWindow(m_CtrlTree)) { return CDialog::OnNotify(wParam, lParam, pResult); } LPNMHDR pNmhdr = (LPNMHDR)lParam; int idCtrl = LOWORD(wParam); // 获取控件ID; // 如果消息对象是该资源(树); if( idCtrl == IDC_TREE1 ) { CPoint point; ::GetCursorPos(&point); m_CtrlTree.ScreenToClient(&point); switch( pNmhdr->code ) { case NM_CLICK: // 单击; { // Get Click item's UINT uFlags; HTREEITEM hItem = m_CtrlTree.HitTest(point, &uFlags); if((hItem != NULL) && (TVHT_ONITEM & uFlags)) { m_CtrlTree.SelectItem(hItem); } // 对所有单击,禁用修改按钮 [4/8/2013 Zero.t] GetDlgItem(Btn_ModifyDevice)->EnableWindow(FALSE); return true;//Already process the notify } case NM_RCLICK: // 右击,专门处理菜单; { // Get RightClick item's UINT uFlags; HTREEITEM hItem = m_CtrlTree.HitTest(point, &uFlags); m_CtrlTree.SelectItem(hItem); if((hItem != NULL) && (TVHT_ONITEM & uFlags)) { GetCursorPos(&m_mousePoint); // 保存当前鼠标位置; HTREEITEM hSelectedItem = m_CtrlTree.GetSelectedItem(); // 获取项在容器中的层次信息; CString strName = m_CtrlTree.GetItemText(hSelectedItem); int nType = TypeTreeItem(hSelectedItem); #if 1 // 使用弹出菜单; CMenu menu; menu.LoadMenu(IDR_MENU1); if( nType == 0 ) { //menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL); } else if ( nType == 1 ) { menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL); } else if ( nType == 2 ) { menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL); } else if ( nType == 3 ) { menu.GetSubMenu(4)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL); } #endif } // 对所有单击,禁用修改按钮 [4/8/2013 Zero.t] GetDlgItem(Btn_ModifyDevice)->EnableWindow(FALSE); return true;//Already process the notify } case NM_DBLCLK: // 左键 双击; { UINT uFlags; HTREEITEM hItem = m_CtrlTree.HitTest(point, &uFlags); m_CtrlTree.SelectItem(hItem); if((hItem != NULL) && (TVHT_ONITEM & uFlags)) { GetCursorPos(&m_mousePoint); // 保存当前鼠标位置; HTREEITEM hSelectedItem = m_CtrlTree.GetSelectedItem(); if ( !m_CtrlTree.ItemHasChildren(hSelectedItem)) { //CString strName = m_CtrlTree.GetItemText(hSelectedItem); //InitDeviceComInfo(strName); m_strOldDeviceName = m_CtrlTree.GetItemText(hSelectedItem); InitDeviceComInfo(m_strOldDeviceName); // 对所有单击,禁用修改按钮 [4/8/2013 Zero.t] GetDlgItem(Btn_ModifyDevice)->EnableWindow(); } } return true; } } return false; // no match } if ( idCtrl == IDC_TREE2) { CPoint point; ::GetCursorPos(&point); m_CtrlSubTree.ScreenToClient(&point); switch( pNmhdr->code ) { case NM_CLICK: // 单击; { // Get Click item's UINT uFlags; HTREEITEM hItem = m_CtrlSubTree.HitTest(point, &uFlags); if((hItem != NULL) && (TVHT_ONITEM & uFlags)) { m_CtrlSubTree.SelectItem(hItem); } // 单击禁用修改按钮 [4/8/2013 Zero.t] GetDlgItem(Btn_ModifyCmdStyle)->EnableWindow(FALSE); GetDlgItem(Btn_ModifyCmdImpl)->EnableWindow(FALSE); return true;//Already process the notify } case NM_RCLICK: // 右击,专门处理菜单; { // Get RightClick item's UINT uFlags; HTREEITEM hItem = m_CtrlSubTree.HitTest(point, &uFlags); m_CtrlSubTree.SelectItem(hItem); if((hItem != NULL) && (TVHT_ONITEM & uFlags)) { GetCursorPos(&m_mousePoint); // 保存当前鼠标位置; HTREEITEM hSelectedItem = m_CtrlSubTree.GetSelectedItem(); // 获取项在容器中的层次信息; CString strName = m_CtrlSubTree.GetItemText(hSelectedItem); int nType = TypeCommandTreeItem(hSelectedItem); #if 1 // 使用弹出菜单; CMenu menu; menu.LoadMenu(IDR_MENU1); if( nType == 0 ) { //menu.GetSubMenu(2)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL); } else if ( nType == 1 ) { menu.GetSubMenu(1)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL); } else if ( nType == 2 ) { menu.GetSubMenu(2)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL); } else if ( nType == 3 ) { menu.GetSubMenu(5)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL); } else if ( nType == 4 ) { menu.GetSubMenu(3)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL); } else if ( nType ==5 ) { menu.GetSubMenu(5)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL); } #endif } // 单击禁用修改按钮 [4/8/2013 Zero.t] GetDlgItem(Btn_ModifyCmdStyle)->EnableWindow(FALSE); GetDlgItem(Btn_ModifyCmdImpl)->EnableWindow(FALSE); return true;//Already process the notify } case NM_DBLCLK: // 左键 双击; { UINT uFlags; HTREEITEM hItem = m_CtrlSubTree.HitTest(point, &uFlags); m_CtrlSubTree.SelectItem(hItem); if((hItem != NULL) && (TVHT_ONITEM & uFlags)) { GetCursorPos(&m_mousePoint); // 保存当前鼠标位置; HTREEITEM hSelectedItem = m_CtrlSubTree.GetSelectedItem(); InitCommandInfo(hSelectedItem); //// 单击禁用修改按钮 [4/8/2013 Zero.t] //GetDlgItem(Btn_ModifyCmdStyle)->EnableWindow(); //GetDlgItem(Btn_ModifyCmdImpl)->EnableWindow(); } return true; } } return false; // no match } return CDialog::OnNotify(wParam, lParam, pResult); } BOOL CEditorDlg::DestroyWindow() { // TODO: 在此添加专用代码和/或调用基类 return CDialog::DestroyWindow(); } void CEditorDlg::OnAddDeviceProperty() { // TODO: 在此添加命令处理程序代码 HTREEITEM hSelectItem = m_CtrlTree.GetSelectedItem(); CString strDevice = m_CtrlTree.GetItemText(hSelectItem); InitDeviceComInfo(strDevice); //AfxMessageBox(strDevice); } void CEditorDlg::OnDeletedevice() { // TODO: 在此添加命令处理程序代码 HTREEITEM hSelectItem = m_CtrlTree.GetSelectedItem(); CString strDevice = m_CtrlTree.GetItemText(hSelectItem); CObjectdepot tObjectdepot; tObjectdepot.SetDevicesDepotPath(m_strDepotPath); tObjectdepot.SetRuntimeDevicesDepotPath(m_strRutDepotPath); tObjectdepot.RemoveElement(strDevice.GetBuffer()); strDevice.ReleaseBuffer(); //AfxMessageBox("删除成功"); ClearTreeCtrlInfo(hSelectItem); } void CEditorDlg::OnAdddevice()// 添加设备; { // TODO: 在此添加命令处理程序代码 HTREEITEM hSelectItem = m_CtrlTree.GetSelectedItem(); CString strName = m_CtrlTree.GetItemText(hSelectItem); int nType = TypeTreeItem(hSelectItem); CAddDevice dlg; if ( nType == 1 ) { dlg.m_strClassType = strName; } else if ( nType == 2 ) { HTREEITEM hParent = m_CtrlTree.GetParentItem(hSelectItem); dlg.m_strClassType = m_CtrlTree.GetItemText(hParent); dlg.m_strDeviceName = strName; dlg.m_strFactory = strName; } if ( dlg.DoModal() == IDOK ) InitTreeCtrlInfo(); } void CEditorDlg::OnAddcmdStyle() //添加指令格式; { // TODO: 在此添加命令处理程序代码 HTREEITEM hSelectItem = m_CtrlSubTree.GetSelectedItem(); CString strName = m_CtrlSubTree.GetItemText(hSelectItem); CObjectdepot tObjectdepot; tObjectdepot.SetDevicesDepotPath(m_strDepotPath); tObjectdepot.SetRuntimeDevicesDepotPath(m_strRutDepotPath); STDepotObject *pDepotObject = tObjectdepot.LookupElement(m_strOldDeviceName) ; if ( pDepotObject == NULL ) return; CAddCmdStlye dlg; dlg.m_strCmdSize.Format("%d",pDepotObject->ByteCount); dlg.m_strOldDeviceName = m_strOldDeviceName; dlg.m_strRutDepotPath = m_strRutDepotPath; dlg.m_strDepotPath = m_strDepotPath; if ( dlg.DoModal() == IDOK ) { // 刷新; InitDeviceComInfo(m_strOldDeviceName); } if ( pDepotObject ) { delete pDepotObject; pDepotObject = NULL; } } void CEditorDlg::OnAddcmdimpl() { // TODO: 在此添加命令处理程序代码 HTREEITEM hSelectItem = m_CtrlSubTree.GetSelectedItem(); CString strName = m_CtrlSubTree.GetItemText(hSelectItem); CAddCmdImpl dlg; dlg.m_strOldDeviceName = m_strOldDeviceName; dlg.m_strRutDepotPath = m_strRutDepotPath; dlg.m_strDepotPath = m_strDepotPath; if ( dlg.DoModal() == IDOK ) { // 刷新; InitDeviceComInfo(m_strOldDeviceName); } } void CEditorDlg::OnAddcmdimteimpl() { // TODO: 在此添加命令处理程序代码 HTREEITEM hSelectItem = m_CtrlSubTree.GetSelectedItem(); CString strName = m_CtrlSubTree.GetItemText(hSelectItem); CAddCmdImplItem dlg; dlg.m_strOldDeviceName = m_strOldDeviceName; dlg.m_strRutDepotPath = m_strRutDepotPath; dlg.m_strDepotPath = m_strDepotPath; dlg.m_strOldMark = strName; if ( dlg.DoModal() == IDOK ) { // 刷新; InitDeviceComInfo(m_strOldDeviceName); } } void CEditorDlg::OnBnClickedModifydevice()//修改设备; { CString str; GetDlgItemText(Btn_ModifyDevice,str); if ( str == "修改属性" ) { #if 1 // 启用被禁用的按钮; GetDlgItem(ET_DEVICENAME)->EnableWindow(); GetDlgItem(ET_DEVICEID)->EnableWindow(); GetDlgItem(CB_RATE)->EnableWindow(); GetDlgItem(CB_DATABIT)->EnableWindow(); GetDlgItem(CB_STOPBIT)->EnableWindow(); GetDlgItem(CB_PARITY)->EnableWindow(); GetDlgItem(ET_RESPONSETIME)->EnableWindow(); GetDlgItem(ET_FREQUENCY)->EnableWindow(); GetDlgItem(ET_LINETYPE)->EnableWindow(); GetDlgItem(ET_COMTYPE)->EnableWindow(); GetDlgItem(ET_PINDEF)->EnableWindow(); GetDlgItem(ET_FACTORY)->EnableWindow(); GetDlgItem(ET_CLASSTYPE)->EnableWindow(); GetDlgItem(ET_SERIES)->EnableWindow(); GetDlgItem(ET_NAME)->EnableWindow(); GetDlgItem(ET_MODELNUM)->EnableWindow(); GetDlgItem(ET_PROTOCOL)->EnableWindow(); #endif SetDlgItemText(Btn_ModifyDevice,"应用修改"); } UpdateData(); if ( str == "应用修改" ) { #if 1 // 禁用的按钮; GetDlgItem(ET_DEVICENAME)->EnableWindow(FALSE); GetDlgItem(ET_DEVICEID)->EnableWindow(FALSE); GetDlgItem(CB_RATE)->EnableWindow(FALSE); GetDlgItem(CB_DATABIT)->EnableWindow(FALSE); GetDlgItem(CB_STOPBIT)->EnableWindow(FALSE); GetDlgItem(CB_PARITY)->EnableWindow(FALSE); GetDlgItem(ET_RESPONSETIME)->EnableWindow(FALSE); GetDlgItem(ET_FREQUENCY)->EnableWindow(FALSE); GetDlgItem(ET_LINETYPE)->EnableWindow(FALSE); GetDlgItem(ET_COMTYPE)->EnableWindow(FALSE); GetDlgItem(ET_PINDEF)->EnableWindow(FALSE); GetDlgItem(ET_FACTORY)->EnableWindow(FALSE); GetDlgItem(ET_CLASSTYPE)->EnableWindow(FALSE); GetDlgItem(ET_SERIES)->EnableWindow(FALSE); GetDlgItem(ET_NAME)->EnableWindow(FALSE); GetDlgItem(ET_MODELNUM)->EnableWindow(FALSE); GetDlgItem(ET_PROTOCOL)->EnableWindow(FALSE); #endif #if 1 // 修改属性 [4/3/2013 Zero.t] CObjectdepot tObjectdepot; tObjectdepot.SetDevicesDepotPath(m_strDepotPath); tObjectdepot.SetRuntimeDevicesDepotPath(m_strRutDepotPath); STDepotPhysical tDevicePhysical; STDeviceDocument tDeviceDocument; tDevicePhysical.iRate = GetDlgItemInt(CB_RATE); tDevicePhysical.iDBit = GetDlgItemInt(CB_DATABIT); tDevicePhysical.iSBit = m_cobStopbit.GetCurSel(); tDevicePhysical.iPaty = m_cobParity.GetCurSel(); tDevicePhysical.iRsTm = GetDlgItemInt(ET_RESPONSETIME); tDevicePhysical.iIntl = GetDlgItemInt(ET_FREQUENCY); sprintf(tDevicePhysical.szLineType,"%s",m_strLineType); sprintf(tDevicePhysical.szComType,"%s",m_strComType); sprintf(tDevicePhysical.szPinDef,"%s",m_strLineType); sprintf(tDeviceDocument.szdeviceClass,"%s",m_strSeries); sprintf(tDeviceDocument.szdeviceName,"%s",m_strDeviceName2); sprintf(tDeviceDocument.szdeviceType,"%s",m_strClassType); sprintf(tDeviceDocument.szFactory,"%s",m_strFactory); sprintf(tDeviceDocument.szProtocol,"%s",m_strProtocol); sprintf(tDeviceDocument.szUnitType,"%s",m_strModelNum); tObjectdepot.ModifyElementNode( m_strOldDeviceName, m_strDeviceName, m_strDeviceID, tDevicePhysical, tDeviceDocument); #endif SetDlgItemText(Btn_ModifyDevice,"修改属性"); InitTreeCtrlInfo(); } } void CEditorDlg::OnBnClickedModifycmdstyle()//修改指令格式; { CString str; GetDlgItemText(Btn_ModifyCmdStyle,str); if ( str == "修改属性" ) { #if 1 // 启用被禁用的按钮; GetDlgItem(ET_CMDSIZE)->EnableWindow(); GetDlgItem(ET_CMDKEY1)->EnableWindow(); GetDlgItem(ET_KEYLEN)->EnableWindow(); GetDlgItem(CB_KEYTYPE)->EnableWindow(); GetDlgItem(ET_KEYCONTX)->EnableWindow(); #endif SetDlgItemText(Btn_ModifyCmdStyle,"应用修改"); } UpdateData(); if ( str == "应用修改" ) { #if 1 // 禁用的按钮; GetDlgItem(ET_CMDSIZE)->EnableWindow(FALSE); GetDlgItem(ET_CMDKEY1)->EnableWindow(FALSE); GetDlgItem(ET_KEYLEN)->EnableWindow(FALSE); GetDlgItem(CB_KEYTYPE)->EnableWindow(FALSE); GetDlgItem(ET_KEYCONTX)->EnableWindow(FALSE); #endif #if 1 // 修改属性 [4/3/2013 Zero.t] CObjectdepot tObjectdepot; tObjectdepot.SetDevicesDepotPath(m_strDepotPath); tObjectdepot.SetRuntimeDevicesDepotPath(m_strRutDepotPath); char szKeyType[2] = {0}; itoa(GetDlgItemInt(CB_KEYTYPE),szKeyType,10); tObjectdepot.ModifyElementCommandStyle( m_strDeviceName.GetBuffer(), m_strOldKey.GetBuffer(), m_strCmdKey1.GetBuffer(), m_strKeyLen.GetBuffer(), m_strKeyContx1.GetBuffer(), szKeyType, GetDlgItemInt(ET_CMDSIZE) ); m_strDeviceName.ReleaseBuffer(); m_strOldKey.ReleaseBuffer(); m_strCmdKey1.ReleaseBuffer(); m_strKeyLen.ReleaseBuffer(); m_strKeyContx1.ReleaseBuffer(); #endif SetDlgItemText(Btn_ModifyCmdStyle,"修改属性"); } } void CEditorDlg::OnBnClickedModifycmdimpl()//修改指令实现 { CString str; GetDlgItemText(Btn_ModifyCmdImpl,str); if ( str == "修改属性" ) { #if 1 // 启用被禁用的按钮; GetDlgItem(CB_STORERECV)->EnableWindow(); GetDlgItem(ET_MARK)->EnableWindow(); GetDlgItem(ET_CMDTIP)->EnableWindow(); GetDlgItem(ET_CMDKEY2)->EnableWindow(); GetDlgItem(ET_KEYCONTXT2)->EnableWindow(); #endif SetDlgItemText(Btn_ModifyCmdImpl,"应用修改"); } UpdateData(); if ( str == "应用修改" ) { #if 1 // 禁用的按钮; GetDlgItem(CB_STORERECV)->EnableWindow(FALSE); GetDlgItem(ET_MARK)->EnableWindow(FALSE); GetDlgItem(ET_CMDTIP)->EnableWindow(FALSE); GetDlgItem(ET_CMDKEY2)->EnableWindow(FALSE); GetDlgItem(ET_KEYCONTXT2)->EnableWindow(FALSE); #endif #if 1 // 修改属性 [4/3/2013 Zero.t] CObjectdepot tObjectdepot; tObjectdepot.SetDevicesDepotPath(m_strDepotPath); tObjectdepot.SetRuntimeDevicesDepotPath(m_strRutDepotPath); if ( m_strCmdKey2 == "" && m_strKeyContx2 == "" ) { tObjectdepot.ModifyElementCommand( m_strDeviceName.GetBuffer(), m_strOldMark.GetBuffer(), m_strMark.GetBuffer(), m_cobStore.GetCurSel(), m_strCmdTip.GetBuffer() ); } else { tObjectdepot.ModifyElementCmdImpl( m_strDeviceName.GetBuffer(), m_strOldMark.GetBuffer(), m_strMark.GetBuffer(), m_cobStore.GetCurSel(), m_strCmdTip.GetBuffer(), m_strOldKey.GetBuffer(), m_strCmdKey2.GetBuffer(), m_strKeyContx2.GetBuffer() ); } InitDeviceComInfo(m_strOldDeviceName); m_strDeviceName.ReleaseBuffer(); m_strOldMark.ReleaseBuffer(); m_strMark.ReleaseBuffer(); m_strCmdTip.ReleaseBuffer(); m_strOldKey.ReleaseBuffer(); m_strCmdKey2.ReleaseBuffer(); m_strKeyContx2.ReleaseBuffer(); #endif SetDlgItemText(Btn_ModifyCmdImpl,"修改属性"); } } void CEditorDlg::OnDeleteitem() { HTREEITEM hSelectItem = m_CtrlSubTree.GetSelectedItem(); HTREEITEM hRootItem = m_CtrlSubTree.GetParentItem(hSelectItem); CString strParent = m_CtrlSubTree.GetItemText(hRootItem); CString strName = m_CtrlSubTree.GetItemText(hSelectItem); CObjectdepot tObjectdepot; tObjectdepot.SetDevicesDepotPath(m_strDepotPath); tObjectdepot.SetRuntimeDevicesDepotPath(m_strRutDepotPath); if ( strParent == "指令格式" ) { tObjectdepot.DeleteElementCommandStyle(m_strOldDeviceName.GetBuffer(),strName.GetBuffer()); } else { tObjectdepot.DeleteElementCommandImplItem(m_strOldDeviceName.GetBuffer(),strParent.GetBuffer(),strName.GetBuffer()); } m_strOldDeviceName.ReleaseBuffer(); strParent.ReleaseBuffer(); strName.ReleaseBuffer(); ClearTreeInfo(hSelectItem); } void CEditorDlg::OnDeletecmdimpl() { HTREEITEM hSelectItem = m_CtrlSubTree.GetSelectedItem(); HTREEITEM hRootItem = m_CtrlSubTree.GetParentItem(hSelectItem); CString strParent = m_CtrlSubTree.GetItemText(hRootItem); CString strName = m_CtrlSubTree.GetItemText(hSelectItem); CObjectdepot tObjectdepot; tObjectdepot.SetDevicesDepotPath(m_strDepotPath); tObjectdepot.SetRuntimeDevicesDepotPath(m_strRutDepotPath); if ( strParent == "指令实现" ) { tObjectdepot.DeleteElementCmdImpl(m_strOldDeviceName.GetBuffer(),strName.GetBuffer()); } m_strOldDeviceName.ReleaseBuffer(); strName.ReleaseBuffer(); ClearTreeInfo(hSelectItem); } void CEditorDlg::Enable_1(BOOL bSet) { // 启用被禁用的按钮; if ( bSet ) { GetDlgItem(ET_DEVICENAME)->EnableWindow(); GetDlgItem(ET_DEVICEID)->EnableWindow(); GetDlgItem(CB_RATE)->EnableWindow(); GetDlgItem(CB_DATABIT)->EnableWindow(); GetDlgItem(CB_STOPBIT)->EnableWindow(); GetDlgItem(CB_PARITY)->EnableWindow(); GetDlgItem(ET_RESPONSETIME)->EnableWindow(); GetDlgItem(ET_FREQUENCY)->EnableWindow(); GetDlgItem(ET_LINETYPE)->EnableWindow(); GetDlgItem(ET_COMTYPE)->EnableWindow(); GetDlgItem(ET_PINDEF)->EnableWindow(); GetDlgItem(ET_FACTORY)->EnableWindow(); GetDlgItem(ET_CLASSTYPE)->EnableWindow(); GetDlgItem(ET_SERIES)->EnableWindow(); GetDlgItem(ET_NAME)->EnableWindow(); GetDlgItem(ET_MODELNUM)->EnableWindow(); GetDlgItem(ET_PROTOCOL)->EnableWindow(); //SetDlgItemText(Btn_ModifyDevice,"应用修改"); } else { // 禁用的按钮; GetDlgItem(ET_DEVICENAME)->EnableWindow(FALSE); GetDlgItem(ET_DEVICEID)->EnableWindow(FALSE); GetDlgItem(CB_RATE)->EnableWindow(FALSE); GetDlgItem(CB_DATABIT)->EnableWindow(FALSE); GetDlgItem(CB_STOPBIT)->EnableWindow(FALSE); GetDlgItem(CB_PARITY)->EnableWindow(FALSE); GetDlgItem(ET_RESPONSETIME)->EnableWindow(FALSE); GetDlgItem(ET_FREQUENCY)->EnableWindow(FALSE); GetDlgItem(ET_LINETYPE)->EnableWindow(FALSE); GetDlgItem(ET_COMTYPE)->EnableWindow(FALSE); GetDlgItem(ET_PINDEF)->EnableWindow(FALSE); GetDlgItem(ET_FACTORY)->EnableWindow(FALSE); GetDlgItem(ET_CLASSTYPE)->EnableWindow(FALSE); GetDlgItem(ET_SERIES)->EnableWindow(FALSE); GetDlgItem(ET_NAME)->EnableWindow(FALSE); GetDlgItem(ET_MODELNUM)->EnableWindow(FALSE); GetDlgItem(ET_PROTOCOL)->EnableWindow(FALSE); } } void CEditorDlg::Enable_2(BOOL bSet) { if ( bSet ) { GetDlgItem(ET_CMDSIZE)->EnableWindow(); GetDlgItem(ET_CMDKEY1)->EnableWindow(); GetDlgItem(ET_KEYLEN)->EnableWindow(); GetDlgItem(CB_KEYTYPE)->EnableWindow(); GetDlgItem(ET_KEYCONTX)->EnableWindow(); } else { // 禁用的按钮; GetDlgItem(ET_CMDSIZE)->EnableWindow(FALSE); GetDlgItem(ET_CMDKEY1)->EnableWindow(FALSE); GetDlgItem(ET_KEYLEN)->EnableWindow(FALSE); GetDlgItem(CB_KEYTYPE)->EnableWindow(FALSE); GetDlgItem(ET_KEYCONTX)->EnableWindow(FALSE); } } void CEditorDlg::Enable_3(BOOL bSet) { if ( bSet ) { // 启用被禁用的按钮; GetDlgItem(CB_STORERECV)->EnableWindow(); GetDlgItem(ET_MARK)->EnableWindow(); GetDlgItem(ET_CMDTIP)->EnableWindow(); GetDlgItem(ET_CMDKEY2)->EnableWindow(); GetDlgItem(ET_KEYCONTXT2)->EnableWindow(); } else { // 禁用的按钮; GetDlgItem(CB_STORERECV)->EnableWindow(FALSE); GetDlgItem(ET_MARK)->EnableWindow(FALSE); GetDlgItem(ET_CMDTIP)->EnableWindow(FALSE); GetDlgItem(ET_CMDKEY2)->EnableWindow(FALSE); GetDlgItem(ET_KEYCONTXT2)->EnableWindow(FALSE); } } void CEditorDlg::Expand_Tree_1() { m_CtrlTree.Expand(hRunRootItem,TVE_EXPAND); STTreeInfo tTreeInfo = {0}; vector ::iterator it; for ( it = vtSTTreeInfo.begin(); it != vtSTTreeInfo.end(); it++ ) { tTreeInfo = *it; m_CtrlTree.Expand(tTreeInfo.hType,TVE_EXPAND); } } void CEditorDlg::Expand_Tree_2() { m_CtrlSubTree.Expand(tSTDeviceImpl.hDevice,TVE_EXPAND); m_CtrlSubTree.Expand(tSTDeviceImpl.tSTComInfo.hComInfo,TVE_EXPAND); m_CtrlSubTree.Expand(tSTDeviceImpl.tSTComImpl.hComImpl,TVE_EXPAND); } void CEditorDlg::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); // TODO: Add your message handler code here. // ---------------垂直滚动条; m_nCurHeight = cy; int nScrollMaxHeight; if (cy < m_rect.Height()) { nScrollMaxHeight = m_rect.Height() - cy; } else nScrollMaxHeight = 0; SCROLLINFO si_height; si_height.cbSize = sizeof(SCROLLINFO); si_height.fMask = SIF_ALL; // SIF_ALL = SIF_PAGE | SIF_RANGE | SIF_POS; si_height.nMin = 0; si_height.nMax = nScrollMaxHeight; si_height.nPage = si_height.nMax/10; si_height.nPos = 0; SetScrollInfo(SB_VERT, &si_height, TRUE); // --------------水平滚动条; m_nCurWidth = cx; int nScrollMaxWidth; if (cx < m_rect.Width()) { nScrollMaxWidth = m_rect.Width() - cx; } else nScrollMaxWidth = 0; SCROLLINFO si_width; si_width.cbSize = sizeof(SCROLLINFO); si_width.fMask = SIF_ALL; // SIF_ALL = SIF_PAGE | SIF_RANGE | SIF_POS; si_width.nMin = 0; si_width.nMax = nScrollMaxWidth; si_width.nPage = si_width.nMax/10; si_width.nPos = 0; SetScrollInfo(SB_HORZ, &si_width, TRUE); // TODO: 在此处添加消息处理程序代码 } // 垂直滚动条; void CEditorDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { // TODO: 在此添加消息处理程序代码和/或调用默认值 int nDelta; int nMaxPos = m_rect.Height() - m_nCurHeight; switch (nSBCode) { case SB_LINEDOWN: if (m_nHeightScrollPos >= nMaxPos) return; nDelta = min(nMaxPos/100,nMaxPos-m_nHeightScrollPos); break; case SB_LINEUP: if (m_nHeightScrollPos <= 0) return; nDelta = -min(nMaxPos/100,m_nHeightScrollPos); break; case SB_PAGEDOWN: if (m_nHeightScrollPos >= nMaxPos) return; nDelta = min(nMaxPos/10,nMaxPos-m_nHeightScrollPos); break; case SB_THUMBPOSITION: nDelta = (int)nPos - m_nHeightScrollPos; break; case SB_PAGEUP: if (m_nHeightScrollPos <= 0) return; nDelta = -min(nMaxPos/10,m_nHeightScrollPos); break; default: return; } m_nHeightScrollPos += nDelta; SetScrollPos(SB_VERT,m_nHeightScrollPos,TRUE); ScrollWindow(0,-nDelta); CDialog::OnVScroll(nSBCode, nPos, pScrollBar); } void CEditorDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { // TODO: 在此添加消息处理程序代码和/或调用默认值 int nDelta; int nMaxPos = m_rect.Width() - m_nCurWidth; //int minpos; //int maxpos; //pScrollBar->GetScrollRange(&minpos, &maxpos); switch (nSBCode) { case SB_LINELEFT: if (m_nWidthScrollPos >= nMaxPos) return; nDelta = min(nMaxPos/100,nMaxPos-m_nWidthScrollPos); break; case SB_LINERIGHT: if (m_nWidthScrollPos <= 0) return; nDelta = -min(nMaxPos/100,m_nWidthScrollPos); break; case SB_PAGEDOWN: if (m_nWidthScrollPos >= nMaxPos) return; nDelta = min(nMaxPos/10,nMaxPos-m_nWidthScrollPos); break; case SB_THUMBPOSITION: nDelta = (int)nPos - m_nWidthScrollPos; break; case SB_PAGEUP: if (m_nWidthScrollPos <= 0) return; nDelta = -min(nMaxPos/10,m_nWidthScrollPos); break; default: return; } m_nWidthScrollPos += nDelta; SetScrollPos(SB_HORZ,m_nWidthScrollPos,TRUE); ScrollWindow(-nDelta,0); CDialog::OnHScroll(nSBCode, nPos, pScrollBar); }