1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831 |
- // 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 <STTreeInfo>::iterator itType;
- if ( hItem == NULL )
- {
- for ( itType = vtSTTreeInfo.begin(); itType != vtSTTreeInfo.end();)
- {
- tTreeInfo = *itType;
- STFactory tFactory = {0};
- vector <STFactory>::iterator itFactory;
- for ( itFactory = tTreeInfo.vtFactory.begin(); itFactory != tTreeInfo.vtFactory.end(); )
- {
- tFactory = *itFactory;
- vector <STDevice>::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 <STFactory>::iterator itFactory;
- for ( itFactory = tTreeInfo.vtFactory.begin(); itFactory != tTreeInfo.vtFactory.end(); itFactory++)
- {
- tFactory = *itFactory;
- vector <STDevice>::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 <STTreeInfo>::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 <STFactory>::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 <STDevice>::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 <STTreeInfo>::iterator it;
- for ( it = vtSTTreeInfo.begin(); it != vtSTTreeInfo.end(); it++ )
- {
- tTreeInfo = *it;
- if ( tTreeInfo.hType == hItem )
- {
- nType = 1;
- break;
- }
- else
- {
- STFactory tFactory = {0};
- vector <STFactory>::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 <STDevice>::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 <STComInfoImplItem>::iterator itComInfoImplItem;
- for ( itComInfoImplItem = tSTDeviceImpl.tSTComInfo.vtComInfoImpl.begin(); itComInfoImplItem != tSTDeviceImpl.tSTComInfo.vtComInfoImpl.end(); itComInfoImplItem++ )
- {
- if ( hItem == (*itComInfoImplItem).hComInfoImpl )
- {
- nType = 3;
- break;
- }
- }
- STComTable tComTable;
- vector <STComTable>::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 <STComTableImpl>::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 <STCommandFormat>::iterator itComformat;
- vector <STCommandTable>::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 <STCommandStyle>::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 <STComInfoImplItem>::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 <STComTable>::iterator itComTable;
- for ( itComTable = tSTDeviceImpl.tSTComImpl.vtComTable.begin(); itComTable != tSTDeviceImpl.tSTComImpl.vtComTable.end();)
- {
- tComTable = *itComTable;
- vector <STComTableImpl>::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 <STComInfoImplItem>::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 <STComTable>::iterator itComTable;
- for ( itComTable = tSTDeviceImpl.tSTComImpl.vtComTable.begin(); itComTable != tSTDeviceImpl.tSTComImpl.vtComTable.end();itComTable++)
- {
- tComTable = *itComTable;
-
- if ( hItem == tComTable.hComTable )
- {
- vector <STComTableImpl>::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 <STComTableImpl>::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 <STCommandFormat>::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 <STCommandTable>::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 <STCommandTable>::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 <STCommandStyle>::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<WPARAM>(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<HCURSOR>(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 <STTreeInfo>::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);
- }
|