EditorDlg.cpp 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831
  1. // EditorDlg.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "Editor.h"
  5. #include "EditorDlg.h"
  6. #include "AddDevice.h"
  7. #include "AddCmdImpl.h"
  8. #include "IniReader.h"
  9. #include "AddCmdStlye.h"
  10. #include "AddCmdImplItem.h"
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #endif
  14. // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
  15. class CAboutDlg : public CDialog
  16. {
  17. public:
  18. CAboutDlg();
  19. // 对话框数据
  20. enum { IDD = IDD_ABOUTBOX };
  21. protected:
  22. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
  23. // 实现
  24. protected:
  25. DECLARE_MESSAGE_MAP()
  26. };
  27. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  28. {
  29. }
  30. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  31. {
  32. CDialog::DoDataExchange(pDX);
  33. }
  34. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  35. END_MESSAGE_MAP()
  36. // CEditorDlg 对话框
  37. CEditorDlg::CEditorDlg(CWnd* pParent /*=NULL*/)
  38. : CDialog(CEditorDlg::IDD, pParent)
  39. , m_strDeviceName(_T(""))
  40. , m_strDeviceID(_T(""))
  41. , m_strResponseTime(_T(""))
  42. , m_strLineType(_T(""))
  43. , m_strComType(_T(""))
  44. , m_strPindef(_T(""))
  45. , m_strFactory(_T(""))
  46. , m_strClassType(_T(""))
  47. , m_strDeviceName2(_T(""))
  48. , m_strModelNum(_T(""))
  49. , m_strSeries(_T(""))
  50. , m_strProtocol(_T(""))
  51. , m_strCmdSize(_T(""))
  52. , m_strCmdKey1(_T(""))
  53. , m_strKeyLen(_T(""))
  54. , m_strKeyContx1(_T(""))
  55. , m_strMark(_T(""))
  56. , m_strCmdTip(_T(""))
  57. , m_strCmdKey2(_T(""))
  58. , m_strKeyContx2(_T(""))
  59. {
  60. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  61. m_strOldDeviceName = "";
  62. m_strOldKey = "";
  63. m_strOldMark = "";
  64. }
  65. void CEditorDlg::DoDataExchange(CDataExchange* pDX)
  66. {
  67. CDialog::DoDataExchange(pDX);
  68. DDX_Control(pDX, IDC_TREE1, m_CtrlTree);
  69. DDX_Control(pDX, IDC_TREE2, m_CtrlSubTree);
  70. DDX_Text(pDX, ET_DEVICENAME, m_strDeviceName);
  71. DDX_Text(pDX, ET_DEVICEID, m_strDeviceID);
  72. DDX_Control(pDX, CB_RATE, m_cobRate);
  73. DDX_Control(pDX, CB_DATABIT, m_cobDatabit);
  74. DDX_Control(pDX, CB_STOPBIT, m_cobStopbit);
  75. DDX_Control(pDX, CB_PARITY, m_cobParity);
  76. DDX_Text(pDX, ET_RESPONSETIME, m_strResponseTime);
  77. DDX_Text(pDX, ET_FREQUENCY, m_strFrequency);
  78. DDX_Text(pDX, ET_LINETYPE, m_strLineType);
  79. DDX_Text(pDX, ET_COMTYPE, m_strComType);
  80. DDX_Text(pDX, ET_PINDEF, m_strPindef);
  81. DDX_Control(pDX, CB_STORERECV, m_cobStore);
  82. DDX_Text(pDX, ET_FACTORY, m_strFactory);
  83. DDX_Text(pDX, ET_CLASSTYPE, m_strClassType);
  84. DDX_Text(pDX, ET_NAME, m_strDeviceName2);
  85. DDX_Text(pDX, ET_MODELNUM, m_strModelNum);
  86. DDX_Text(pDX, ET_SERIES, m_strSeries);
  87. DDX_Text(pDX, ET_PROTOCOL, m_strProtocol);
  88. DDX_Text(pDX, ET_CMDSIZE, m_strCmdSize);
  89. DDX_Text(pDX, ET_CMDKEY1, m_strCmdKey1);
  90. DDX_Text(pDX, ET_KEYLEN, m_strKeyLen);
  91. DDX_Text(pDX, ET_KEYCONTX, m_strKeyContx1);
  92. DDX_Text(pDX, ET_MARK, m_strMark);
  93. DDX_Text(pDX, ET_CMDTIP, m_strCmdTip);
  94. DDX_Text(pDX, ET_CMDKEY2, m_strCmdKey2);
  95. DDX_Text(pDX, ET_KEYCONTXT2, m_strKeyContx2);
  96. DDX_Control(pDX, Btn_ModifyDevice, m_btnModifyDevice);
  97. DDX_Control(pDX, Btn_ModifyCmdStyle, m_btnModifyCmdStyle);
  98. DDX_Control(pDX, Btn_ModifyCmdImpl, m_btnModifyCmdImpl);
  99. DDX_Control(pDX, CB_KEYTYPE, m_cobKeyType);
  100. }
  101. BEGIN_MESSAGE_MAP(CEditorDlg, CDialog)
  102. ON_WM_SYSCOMMAND()
  103. ON_WM_PAINT()
  104. ON_WM_QUERYDRAGICON()
  105. //}}AFX_MSG_MAP
  106. ON_COMMAND(MU_ADDDEVICEPROPERTY, &CEditorDlg::OnAddDeviceProperty)
  107. ON_COMMAND(MU_ADDDEVICE, &CEditorDlg::OnAdddevice)
  108. ON_COMMAND(MU_ADDCMDFORMATITEM, &CEditorDlg::OnAddcmdStyle)
  109. ON_COMMAND(MU_ADDCMDIMPL, &CEditorDlg::OnAddcmdimpl)
  110. ON_COMMAND(MU_ADDCMDIMTEIMPL, &CEditorDlg::OnAddcmdimteimpl)
  111. ON_BN_CLICKED(Btn_ModifyDevice, &CEditorDlg::OnBnClickedModifydevice)
  112. ON_BN_CLICKED(Btn_ModifyCmdStyle, &CEditorDlg::OnBnClickedModifycmdstyle)
  113. ON_BN_CLICKED(Btn_ModifyCmdImpl, &CEditorDlg::OnBnClickedModifycmdimpl)
  114. ON_COMMAND(MU_DELETEDEVICE, &CEditorDlg::OnDeletedevice)
  115. ON_COMMAND(MU_DELETEITEM, &CEditorDlg::OnDeleteitem)
  116. ON_COMMAND(MU_DELETECMDIMPL, &CEditorDlg::OnDeletecmdimpl)
  117. ON_WM_SIZE()
  118. ON_WM_VSCROLL()
  119. ON_WM_HSCROLL()
  120. END_MESSAGE_MAP()
  121. // CEditorDlg 消息处理程序
  122. BOOL CEditorDlg::OnInitDialog()
  123. {
  124. CDialog::OnInitDialog();
  125. // 将\“关于...\”菜单项添加到系统菜单中。
  126. // IDM_ABOUTBOX 必须在系统命令范围内。
  127. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  128. ASSERT(IDM_ABOUTBOX < 0xF000);
  129. CMenu* pSysMenu = GetSystemMenu(FALSE);
  130. if (pSysMenu != NULL)
  131. {
  132. CString strAboutMenu;
  133. strAboutMenu.LoadString(IDS_ABOUTBOX);
  134. if (!strAboutMenu.IsEmpty())
  135. {
  136. pSysMenu->AppendMenu(MF_SEPARATOR);
  137. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  138. }
  139. }
  140. // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
  141. // 执行此操作
  142. SetIcon(m_hIcon, TRUE); // 设置大图标
  143. SetIcon(m_hIcon, FALSE); // 设置小图标
  144. // TODO: 在此添加额外的初始化代码
  145. GetWindowRect(m_rect);
  146. m_nHeightScrollPos = 0;
  147. m_nWidthScrollPos = 0;
  148. InitSTButtons();
  149. //////////////////
  150. CString strPath;
  151. TCHAR szFull[_MAX_PATH];
  152. TCHAR szDrive[_MAX_DRIVE];
  153. TCHAR szDir[_MAX_DIR];
  154. ::GetModuleFileName(NULL, szFull, sizeof(szFull)/sizeof(TCHAR));
  155. _tsplitpath(szFull, szDrive, szDir, NULL, NULL);
  156. _tcscpy(szFull, szDrive);
  157. _tcscat(szFull, szDir);
  158. strPath = CString(szFull);
  159. CString strIni;
  160. strIni.Format("%s\\config.ini",strPath);
  161. CIniReader IniReader(strIni);
  162. m_strDepotPath = IniReader.GetKeyValueText("name","DeviceLibrary");
  163. m_strRutDepotPath = IniReader.GetKeyValueText("name","RunUnitLibrary");
  164. // TODO: 在此添加额外的初始化
  165. // [3/29/2013 Zero.t]
  166. m_imgList.Create(IDB_BITMAP1,16, 6, RGB(255,255,255));
  167. m_CtrlTree.SetImageList(&m_imgList,TVSIL_NORMAL);
  168. m_CtrlSubTree.SetImageList(&m_imgList,TVSIL_NORMAL);
  169. hRunRootItem = m_CtrlTree.InsertItem("当前运行时设备库设备",2,2);
  170. InitTreeCtrlInfo();
  171. return TRUE; // 除非设置了控件的焦点,否则返回 TRUE
  172. }
  173. void CEditorDlg::ClearCtrlText()
  174. {
  175. m_strDeviceName = "";
  176. m_strDeviceName2 = "";
  177. m_strDeviceID = "";
  178. m_strClassType = "";
  179. m_strCmdKey1 = "";
  180. m_strCmdKey2 = "";
  181. m_strCmdSize = "";
  182. m_strCmdTip = "";
  183. m_strComType = "";
  184. m_strFactory = "";
  185. m_strFrequency = "";
  186. m_strKeyContx1 = "";
  187. m_strKeyContx2 = "";
  188. m_strKeyLen = "";
  189. m_strLineType = "";
  190. m_strMark = "";
  191. m_strModelNum = "";
  192. m_strPindef = "";
  193. m_strProtocol = "";
  194. m_strResponseTime = "";
  195. m_strSeries = "";
  196. }
  197. void CEditorDlg::InitSTButtons()
  198. {
  199. short shBtnColor = 30;
  200. m_btnModifyDevice.SetIcon(IDI_ICON3);
  201. m_btnModifyDevice.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, shBtnColor);
  202. m_btnModifyDevice.SetColor(CButtonST::BTNST_COLOR_FG_IN, RGB(0, 128, 0));
  203. m_btnModifyCmdStyle.SetIcon(IDI_ICON3);
  204. m_btnModifyCmdStyle.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, shBtnColor);
  205. m_btnModifyCmdStyle.SetColor(CButtonST::BTNST_COLOR_FG_IN, RGB(0, 128, 0));
  206. m_btnModifyCmdImpl.SetIcon(IDI_ICON3);
  207. m_btnModifyCmdImpl.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, shBtnColor);
  208. m_btnModifyCmdImpl.SetColor(CButtonST::BTNST_COLOR_FG_IN, RGB(0, 128, 0));
  209. }
  210. void CEditorDlg::ClearTreeCtrlInfo(HTREEITEM hItem)
  211. {
  212. STTreeInfo tTreeInfo = {0};
  213. vector <STTreeInfo>::iterator itType;
  214. if ( hItem == NULL )
  215. {
  216. for ( itType = vtSTTreeInfo.begin(); itType != vtSTTreeInfo.end();)
  217. {
  218. tTreeInfo = *itType;
  219. STFactory tFactory = {0};
  220. vector <STFactory>::iterator itFactory;
  221. for ( itFactory = tTreeInfo.vtFactory.begin(); itFactory != tTreeInfo.vtFactory.end(); )
  222. {
  223. tFactory = *itFactory;
  224. vector <STDevice>::iterator itDevice;
  225. for( itDevice = tFactory.vtDevice.begin(); itDevice != tFactory.vtDevice.end(); )
  226. {
  227. m_CtrlTree.DeleteItem((*itDevice).hDevice);
  228. itDevice = tFactory.vtDevice.erase(itDevice);
  229. }
  230. m_CtrlTree.DeleteItem((*itFactory).hFactory);
  231. itFactory = tTreeInfo.vtFactory.erase(itFactory);
  232. }
  233. m_CtrlTree.DeleteItem((*itType).hType);
  234. itType = vtSTTreeInfo.erase(itType);
  235. }
  236. }
  237. else
  238. {
  239. BOOL bIsDelete = FALSE;
  240. for ( itType = vtSTTreeInfo.begin(); itType != vtSTTreeInfo.end(); itType++)
  241. {
  242. tTreeInfo = *itType;
  243. STFactory tFactory = {0};
  244. vector <STFactory>::iterator itFactory;
  245. for ( itFactory = tTreeInfo.vtFactory.begin(); itFactory != tTreeInfo.vtFactory.end(); itFactory++)
  246. {
  247. tFactory = *itFactory;
  248. vector <STDevice>::iterator itDevice;
  249. for( itDevice = tFactory.vtDevice.begin(); itDevice != tFactory.vtDevice.end();itDevice++ )
  250. {
  251. if ( hItem == (*itDevice).hDevice )
  252. {
  253. m_CtrlTree.DeleteItem((*itDevice).hDevice);
  254. tFactory.vtDevice.erase(itDevice);
  255. //goto End;
  256. bIsDelete = TRUE;
  257. break;
  258. }
  259. }
  260. if ( bIsDelete )
  261. {
  262. *itFactory = tFactory;
  263. if ( tFactory.vtDevice.size() == 0)
  264. {
  265. m_CtrlTree.DeleteItem((*itFactory).hFactory);
  266. tTreeInfo.vtFactory.erase(itFactory);
  267. }
  268. break;
  269. }
  270. }
  271. if ( bIsDelete )
  272. {
  273. *itType = tTreeInfo;
  274. if ( tTreeInfo.vtFactory.size() == 0)
  275. {
  276. m_CtrlTree.DeleteItem((*itType).hType);
  277. vtSTTreeInfo.erase(itType);
  278. }
  279. break;
  280. }
  281. }
  282. }
  283. //End:
  284. Sleep(10);
  285. }
  286. void CEditorDlg::InitTreeCtrlInfo()
  287. {
  288. ClearTreeCtrlInfo();
  289. #if 1
  290. CMarkup xml;
  291. if ( !xml.Load(m_strDepotPath) )
  292. {
  293. //LOG4C((LOG_NOTICE,"设备库不存在"));
  294. return;
  295. }
  296. xml.FindElem();
  297. xml.IntoElem();
  298. int nCount = 0;
  299. BOOL bNoDevice = TRUE;
  300. BOOL bNoFactory = TRUE;
  301. BOOL bNoType = TRUE;
  302. while( xml.FindElem("object_depot"))
  303. {
  304. CString strDevice = xml.GetAttrib("name");
  305. xml.FindChildElem("document");
  306. CString strFactory = xml.GetChildAttrib("Factory");
  307. CString strType = xml.GetChildAttrib("deviceType");
  308. STTreeInfo tTreeInfo = {0};
  309. vector <STTreeInfo>::iterator it;
  310. for ( it = vtSTTreeInfo.begin(); it != vtSTTreeInfo.end(); it++ )
  311. {
  312. tTreeInfo = *it;
  313. if ( tTreeInfo.strType == strType && tTreeInfo.hType != NULL )
  314. {
  315. bNoType = FALSE;
  316. STFactory tFactory = {0};
  317. vector <STFactory>::iterator itFactory;
  318. for ( itFactory = tTreeInfo.vtFactory.begin(); itFactory != tTreeInfo.vtFactory.end(); itFactory++)
  319. {
  320. tFactory = *itFactory;
  321. if ( tFactory.strFactory == strFactory && tFactory.hFactory != NULL )
  322. {
  323. bNoFactory = FALSE;
  324. STDevice tDevice = {0};
  325. vector <STDevice>::iterator itDevice;
  326. for( itDevice = tFactory.vtDevice.begin(); itDevice != tFactory.vtDevice.end(); itDevice++)
  327. {
  328. tDevice = *itDevice;
  329. if ( tDevice.strDevice == strDevice && tDevice.hDevice != NULL )
  330. {
  331. bNoDevice = FALSE;
  332. break;
  333. }
  334. }
  335. if ( bNoDevice )
  336. {
  337. tDevice.strDevice = strDevice;
  338. tDevice.hDevice = m_CtrlTree.InsertItem(strDevice,3,3,tFactory.hFactory);
  339. tFactory.vtDevice.push_back(tDevice);
  340. *itFactory = tFactory;
  341. }
  342. else
  343. {
  344. bNoDevice = TRUE;
  345. }
  346. break;
  347. }
  348. }
  349. if ( bNoFactory )
  350. {
  351. STFactory st_Factory = {0};
  352. st_Factory.strFactory = strFactory;
  353. st_Factory.hFactory = m_CtrlTree.InsertItem(strFactory,0,1,tTreeInfo.hType);
  354. //st_Factory.hFactory = m_CtrlTree.InsertItem(strFactory,tTreeInfo.hType);
  355. STDevice stDevice = {0};
  356. stDevice.strDevice = strDevice;
  357. stDevice.hDevice = m_CtrlTree.InsertItem(strDevice,3,3,st_Factory.hFactory);
  358. st_Factory.vtDevice.push_back(stDevice);
  359. tTreeInfo.vtFactory.push_back(st_Factory);
  360. }else
  361. {
  362. bNoFactory = TRUE;
  363. }
  364. *it = tTreeInfo;
  365. break;
  366. }
  367. }
  368. if ( bNoType )
  369. {
  370. STTreeInfo st_TreeInfo={0};
  371. st_TreeInfo.strType = strType;
  372. st_TreeInfo.hType = m_CtrlTree.InsertItem(strType,0,1,hRunRootItem);
  373. STFactory st_Factory = {0};
  374. st_Factory.strFactory = strFactory;
  375. st_Factory.hFactory = m_CtrlTree.InsertItem(strFactory,0,1,st_TreeInfo.hType);
  376. //st_Factory.hFactory = m_CtrlTree.InsertItem(strFactory,st_TreeInfo.hType);
  377. STDevice st_Device = {0};
  378. st_Device.strDevice = strDevice;
  379. st_Device.hDevice = m_CtrlTree.InsertItem(strDevice,3,3,st_Factory.hFactory);
  380. st_Factory.vtDevice.push_back(st_Device);
  381. st_TreeInfo.vtFactory.push_back(st_Factory);
  382. vtSTTreeInfo.push_back(st_TreeInfo);
  383. }
  384. else
  385. {
  386. bNoType = TRUE;
  387. }
  388. nCount++;
  389. }
  390. Expand_Tree_1();
  391. CString strCount;
  392. strCount.Format("当前可使用设备总数:%d",nCount);
  393. SetDlgItemText(TX_COUNT,strCount);
  394. xml.OutOfElem();
  395. #endif
  396. }
  397. /************************************************************************/
  398. /*
  399. 函数:返回指定树项在vtSTTreeInfo中的层信息
  400. 返回值:
  401. = -1: 表示没有项的存在;
  402. = 0 : 表示hItem是根项;
  403. = 1 : 表示hItem是类别层的项;
  404. = 2 : 表示hItem是厂家层的项;
  405. = 3 : 表示hItem是设备层的项;
  406. */
  407. /************************************************************************/
  408. int CEditorDlg::TypeTreeItem(HTREEITEM &hItem)
  409. {
  410. int nType = -1;
  411. if ( hItem == hRunRootItem )
  412. return 0;
  413. STTreeInfo tTreeInfo = {0};
  414. vector <STTreeInfo>::iterator it;
  415. for ( it = vtSTTreeInfo.begin(); it != vtSTTreeInfo.end(); it++ )
  416. {
  417. tTreeInfo = *it;
  418. if ( tTreeInfo.hType == hItem )
  419. {
  420. nType = 1;
  421. break;
  422. }
  423. else
  424. {
  425. STFactory tFactory = {0};
  426. vector <STFactory>::iterator itFactory;
  427. for ( itFactory = tTreeInfo.vtFactory.begin(); itFactory != tTreeInfo.vtFactory.end(); itFactory++)
  428. {
  429. tFactory = *itFactory;
  430. if ( tFactory.hFactory == hItem )
  431. {
  432. nType = 2;
  433. break;
  434. }
  435. else
  436. {
  437. STDevice tDevice = {0};
  438. vector <STDevice>::iterator itDevice;
  439. for( itDevice = tFactory.vtDevice.begin(); itDevice != tFactory.vtDevice.end(); itDevice++)
  440. {
  441. tDevice = *itDevice;
  442. if ( tDevice.hDevice == hItem )
  443. {
  444. nType = 3;
  445. break;
  446. }
  447. }
  448. }
  449. if ( nType != -1)
  450. break;
  451. }
  452. }
  453. if ( nType != -1)
  454. break;
  455. }
  456. return nType;
  457. }
  458. int CEditorDlg::TypeCommandTreeItem(HTREEITEM &hItem)
  459. {
  460. int nType = -1;
  461. if ( hItem == tSTDeviceImpl.hDevice )
  462. {
  463. return 0;
  464. }
  465. if ( hItem == tSTDeviceImpl.tSTComInfo.hComInfo )
  466. {
  467. return 1;
  468. }
  469. if ( hItem == tSTDeviceImpl.tSTComImpl.hComImpl )
  470. {
  471. return 2;
  472. }
  473. vector <STComInfoImplItem>::iterator itComInfoImplItem;
  474. for ( itComInfoImplItem = tSTDeviceImpl.tSTComInfo.vtComInfoImpl.begin(); itComInfoImplItem != tSTDeviceImpl.tSTComInfo.vtComInfoImpl.end(); itComInfoImplItem++ )
  475. {
  476. if ( hItem == (*itComInfoImplItem).hComInfoImpl )
  477. {
  478. nType = 3;
  479. break;
  480. }
  481. }
  482. STComTable tComTable;
  483. vector <STComTable>::iterator itComTable ;
  484. for ( itComTable = tSTDeviceImpl.tSTComImpl.vtComTable.begin(); itComTable != tSTDeviceImpl.tSTComImpl.vtComTable.end(); itComTable++ )
  485. {
  486. tComTable = *itComTable;
  487. if ( hItem == tComTable.hComTable )
  488. {
  489. nType = 4;
  490. break;
  491. }
  492. else
  493. {
  494. vector <STComTableImpl>::iterator itComTableImpl;
  495. for ( itComTableImpl = tComTable.vtComTableImpl.begin(); itComTableImpl != tComTable.vtComTableImpl.end(); itComTableImpl++)
  496. {
  497. if ( hItem == (*itComTableImpl).hComTableImpl )
  498. {
  499. nType = 5;
  500. break;
  501. }
  502. }
  503. }
  504. }
  505. return nType;
  506. }
  507. void CEditorDlg::InitDeviceComInfo(CString strName)
  508. {
  509. ClearTreeInfo();
  510. CObjectdepot tObjectdepot;
  511. tObjectdepot.SetDevicesDepotPath(m_strDepotPath);
  512. tObjectdepot.SetRuntimeDevicesDepotPath(m_strRutDepotPath);
  513. STDepotObject *pDepotObject = tObjectdepot.LookupElement(strName) ;
  514. if ( pDepotObject == NULL )
  515. return;
  516. // 显示界面数据 [4/2/2013 Zero.t]
  517. m_strDeviceName = strName;
  518. m_strDeviceID.Format("%s",pDepotObject->szSID);
  519. CString strRate ;
  520. strRate.Format("%d",pDepotObject->st_depotphy.iRate);
  521. m_cobRate.SelectString(-1,strRate);
  522. CString strDatabit;
  523. strDatabit.Format("%d",pDepotObject->st_depotphy.iDBit);
  524. m_cobDatabit.SelectString(-1,strDatabit);
  525. m_cobStopbit.SetCurSel(pDepotObject->st_depotphy.iSBit);
  526. m_cobParity.SetCurSel(pDepotObject->st_depotphy.iPaty);
  527. m_strResponseTime.Format("%d",pDepotObject->st_depotphy.iRsTm);
  528. m_strFrequency.Format("%d",pDepotObject->st_depotphy.iIntl);
  529. m_strComType.Format("%s",pDepotObject->st_depotphy.szComType);
  530. m_strLineType.Format("%s",pDepotObject->st_depotphy.szLineType);
  531. m_strPindef.Format("%s",pDepotObject->st_depotphy.szPinDef);
  532. m_strFactory.Format("%s",pDepotObject->st_depotdoc.szFactory);
  533. m_strClassType.Format("%s",pDepotObject->st_depotdoc.szdeviceType);
  534. m_strSeries.Format("%s",pDepotObject->st_depotdoc.szdeviceClass);
  535. m_strProtocol.Format("%s",pDepotObject->st_depotdoc.szProtocol);
  536. m_strDeviceName2.Format("%s",pDepotObject->st_depotdoc.szdeviceName);
  537. m_strModelNum.Format("%s",pDepotObject->st_depotdoc.szUnitType);
  538. UpdateData(FALSE);
  539. // [4/1/2013 Zero.t]
  540. tSTDeviceImpl.hDevice = m_CtrlSubTree.InsertItem(strName,2,2);
  541. tSTDeviceImpl.strDevice = strName;
  542. STCommandFormat tComformat;
  543. STCommandTable tCommtable;
  544. vector <STCommandFormat>::iterator itComformat;
  545. vector <STCommandTable>::iterator itCommtable;
  546. tSTDeviceImpl.tSTComInfo.hComInfo = m_CtrlSubTree.InsertItem("指令格式",3,3,tSTDeviceImpl.hDevice);
  547. tSTDeviceImpl.tSTComInfo.strComInfo = "指令格式";
  548. tSTDeviceImpl.tSTComImpl.hComImpl = m_CtrlSubTree.InsertItem("指令实现",3,3,tSTDeviceImpl.hDevice);
  549. tSTDeviceImpl.tSTComInfo.strComInfo = "指令实现";
  550. for ( itComformat = pDepotObject->vt_commandformat.begin(); itComformat != pDepotObject->vt_commandformat.end(); itComformat++ )
  551. {
  552. tComformat = *itComformat;
  553. STComInfoImplItem tComInfoImplItem;
  554. tComInfoImplItem.strComInfoImpl.Format("%s",tComformat.szName); // 以关键字为项名描述;
  555. tComInfoImplItem.hComInfoImpl = m_CtrlSubTree.InsertItem(tComInfoImplItem.strComInfoImpl,10,10,tSTDeviceImpl.tSTComInfo.hComInfo);
  556. tSTDeviceImpl.tSTComInfo.vtComInfoImpl.push_back(tComInfoImplItem);
  557. }
  558. for( itCommtable = pDepotObject->vt_commandtable.begin(); itCommtable != pDepotObject->vt_commandtable.end(); itCommtable++ )
  559. {
  560. tCommtable = *itCommtable;
  561. STComTable tComTable;
  562. tComTable.strComTable.Format("%s",tCommtable.szMark); // 以指令的特征码为项名描述;
  563. tComTable.hComTable = m_CtrlSubTree.InsertItem(tComTable.strComTable,0,0,tSTDeviceImpl.tSTComImpl.hComImpl);
  564. STCommandStyle tComStyle;
  565. vector <STCommandStyle>::iterator itComStyle;
  566. for ( itComStyle = tCommtable.vt_commandstyle.begin(); itComStyle != tCommtable.vt_commandstyle.end(); itComStyle++)
  567. {
  568. tComStyle = *itComStyle;
  569. STComTableImpl tComTableImpl;
  570. tComTableImpl.strComTableImpl.Format("%s",tComStyle.szName);
  571. tComTableImpl.hComTableImpl = m_CtrlSubTree.InsertItem(tComTableImpl.strComTableImpl,10,10,tComTable.hComTable);
  572. tComTable.vtComTableImpl.push_back(tComTableImpl);
  573. }
  574. tSTDeviceImpl.tSTComImpl.vtComTable.push_back(tComTable);
  575. }
  576. Expand_Tree_2();
  577. if ( pDepotObject )
  578. {
  579. delete pDepotObject;
  580. pDepotObject = NULL;
  581. }
  582. }
  583. void CEditorDlg::ClearTreeInfo(HTREEITEM hItem)
  584. {
  585. // 1.清空树列表
  586. if ( hItem == NULL )
  587. {
  588. m_CtrlSubTree.DeleteItem(tSTDeviceImpl.hDevice);
  589. m_CtrlSubTree.DeleteItem(tSTDeviceImpl.tSTComInfo.hComInfo);
  590. m_CtrlSubTree.DeleteItem(tSTDeviceImpl.tSTComImpl.hComImpl);
  591. //STComInfoImplItem tComInfoImplItem;
  592. vector <STComInfoImplItem>::iterator itComInfoImplItem;
  593. for ( itComInfoImplItem = tSTDeviceImpl.tSTComInfo.vtComInfoImpl.begin(); itComInfoImplItem != tSTDeviceImpl.tSTComInfo.vtComInfoImpl.end();)
  594. {
  595. m_CtrlSubTree.DeleteItem((*itComInfoImplItem).hComInfoImpl);
  596. itComInfoImplItem = tSTDeviceImpl.tSTComInfo.vtComInfoImpl.erase(itComInfoImplItem);
  597. }
  598. STComTable tComTable;
  599. vector <STComTable>::iterator itComTable;
  600. for ( itComTable = tSTDeviceImpl.tSTComImpl.vtComTable.begin(); itComTable != tSTDeviceImpl.tSTComImpl.vtComTable.end();)
  601. {
  602. tComTable = *itComTable;
  603. vector <STComTableImpl>::iterator itComTableImpl;
  604. for ( itComTableImpl = tComTable.vtComTableImpl.begin(); itComTableImpl != tComTable.vtComTableImpl.end();)
  605. {
  606. m_CtrlSubTree.DeleteItem((*itComTableImpl).hComTableImpl);
  607. itComTableImpl = tComTable.vtComTableImpl.erase(itComTableImpl);
  608. }
  609. m_CtrlSubTree.DeleteItem((*itComTable).hComTable);
  610. itComTable = tSTDeviceImpl.tSTComImpl.vtComTable.erase(itComTable);
  611. }
  612. // 2.清空控件;
  613. m_strCmdSize = "";
  614. m_strCmdKey1 = "";
  615. m_strKeyLen = "";
  616. m_strKeyContx1 = "";
  617. m_cobKeyType.SetCurSel(-1);
  618. m_cobStore.SetCurSel(-1);
  619. m_strMark = "";
  620. m_strCmdTip = "";
  621. m_strCmdKey2 = "";
  622. m_strKeyContx2 = "";
  623. UpdateData(FALSE);
  624. }
  625. else
  626. {
  627. //STComInfoImplItem tComInfoImplItem;
  628. vector <STComInfoImplItem>::iterator itComInfoImplItem;
  629. for ( itComInfoImplItem = tSTDeviceImpl.tSTComInfo.vtComInfoImpl.begin(); itComInfoImplItem != tSTDeviceImpl.tSTComInfo.vtComInfoImpl.end();itComInfoImplItem++)
  630. {
  631. if ( hItem == (*itComInfoImplItem).hComInfoImpl )
  632. {
  633. m_CtrlSubTree.DeleteItem((*itComInfoImplItem).hComInfoImpl);
  634. tSTDeviceImpl.tSTComInfo.vtComInfoImpl.erase(itComInfoImplItem);
  635. return;
  636. }
  637. }
  638. STComTable tComTable;
  639. vector <STComTable>::iterator itComTable;
  640. for ( itComTable = tSTDeviceImpl.tSTComImpl.vtComTable.begin(); itComTable != tSTDeviceImpl.tSTComImpl.vtComTable.end();itComTable++)
  641. {
  642. tComTable = *itComTable;
  643. if ( hItem == tComTable.hComTable )
  644. {
  645. vector <STComTableImpl>::iterator itComTableImpl;
  646. for ( itComTableImpl = tComTable.vtComTableImpl.begin(); itComTableImpl != tComTable.vtComTableImpl.end();)
  647. {
  648. m_CtrlSubTree.DeleteItem(hItem);
  649. itComTableImpl = tComTable.vtComTableImpl.erase(itComTableImpl);
  650. }
  651. *itComTable = tComTable;
  652. m_CtrlSubTree.DeleteItem(hItem);
  653. tSTDeviceImpl.tSTComImpl.vtComTable.erase(itComTable);
  654. return;
  655. }else
  656. {
  657. vector <STComTableImpl>::iterator itComTableImpl;
  658. for ( itComTableImpl = tComTable.vtComTableImpl.begin(); itComTableImpl != tComTable.vtComTableImpl.end();itComTableImpl++)
  659. {
  660. if ( hItem == (*itComTableImpl).hComTableImpl )
  661. {
  662. m_CtrlSubTree.DeleteItem(hItem);
  663. tComTable.vtComTableImpl.erase(itComTableImpl);
  664. return;
  665. }
  666. }
  667. }
  668. }
  669. }
  670. }
  671. void CEditorDlg::InitCommandInfo(HTREEITEM &hItem)
  672. {
  673. // 1.判断树结点属于哪个层次的;
  674. // 2.根据层次结点处理相应的事件;
  675. int nType = TypeCommandTreeItem(hItem);
  676. if ( nType != 5 && nType != 3 && nType != 4)
  677. {
  678. return;
  679. }
  680. CString strKeyName = m_CtrlSubTree.GetItemText(hItem);
  681. //AfxMessageBox(strName);
  682. CObjectdepot tObjectdepot;
  683. tObjectdepot.SetDevicesDepotPath(m_strDepotPath);
  684. tObjectdepot.SetRuntimeDevicesDepotPath(m_strRutDepotPath);
  685. STDepotObject *pDepotObject = tObjectdepot.LookupElement(m_strDeviceName) ;
  686. if ( pDepotObject == NULL )
  687. return;
  688. if ( nType == 3 )
  689. {
  690. GetDlgItem(Btn_ModifyCmdStyle)->EnableWindow();
  691. m_strOldKey = strKeyName;//m_CtrlSubTree.GetItemText(hItem);
  692. vector <STCommandFormat>::iterator itCommandformat;
  693. for ( itCommandformat = pDepotObject->vt_commandformat.begin(); itCommandformat != pDepotObject->vt_commandformat.end();itCommandformat++ )
  694. {
  695. if ( strKeyName.Compare((*itCommandformat).szName) == 0 )
  696. {
  697. m_strCmdSize.Format("%d",pDepotObject->ByteCount);
  698. m_strCmdKey1.Format("%s",(*itCommandformat).szName);
  699. m_strKeyLen.Format("%s",(*itCommandformat).szLen);
  700. m_strKeyContx1.Format("%s",(*itCommandformat).szData);
  701. m_cobKeyType.SelectString(-1,(*itCommandformat).szType);
  702. UpdateData(FALSE);
  703. break;
  704. }
  705. }
  706. }
  707. if ( nType == 4 )
  708. {
  709. GetDlgItem(Btn_ModifyCmdImpl)->EnableWindow();
  710. m_strOldMark = strKeyName;
  711. HTREEITEM hParent = m_CtrlSubTree.GetParentItem(hItem);
  712. STCommandTable tCommandtable;
  713. vector <STCommandTable>::iterator itCommandtable;
  714. for ( itCommandtable = pDepotObject->vt_commandtable.begin(); itCommandtable != pDepotObject->vt_commandtable.end();itCommandtable++ )
  715. {
  716. tCommandtable = *itCommandtable;
  717. if ( m_strOldMark.Compare(tCommandtable.szMark) == 0 )
  718. {
  719. m_cobStore.SetCurSel(tCommandtable.bRecv);
  720. m_strMark.Format("%s",tCommandtable.szMark);
  721. m_strCmdTip.Format("%s",tCommandtable.szTip);
  722. m_strCmdKey2 = "";
  723. m_strKeyContx2 = "";
  724. UpdateData(FALSE);
  725. break;
  726. }
  727. }
  728. }
  729. if ( nType == 5 )
  730. {
  731. GetDlgItem(Btn_ModifyCmdImpl)->EnableWindow();
  732. m_strOldKey = strKeyName;
  733. HTREEITEM hParent = m_CtrlSubTree.GetParentItem(hItem);
  734. //CString strMark = m_CtrlSubTree.GetItemText(hParent);
  735. m_strOldMark = m_CtrlSubTree.GetItemText(hParent);
  736. STCommandTable tCommandtable;
  737. vector <STCommandTable>::iterator itCommandtable;
  738. for ( itCommandtable = pDepotObject->vt_commandtable.begin(); itCommandtable != pDepotObject->vt_commandtable.end();itCommandtable++ )
  739. {
  740. tCommandtable = *itCommandtable;
  741. //if ( strMark.Compare(tCommandtable.szMark) != 0 )
  742. if ( m_strOldMark.Compare(tCommandtable.szMark) != 0 )
  743. {
  744. continue;
  745. }
  746. vector <STCommandStyle>::iterator itCommandstyle;
  747. for ( itCommandstyle = tCommandtable.vt_commandstyle.begin(); itCommandstyle != tCommandtable.vt_commandstyle.end(); itCommandstyle++ )
  748. {
  749. if ( strKeyName.Compare((*itCommandstyle).szName) == 0 )
  750. {
  751. m_cobStore.SetCurSel(tCommandtable.bRecv);
  752. m_strMark.Format("%s",tCommandtable.szMark);
  753. m_strCmdTip.Format("%s",tCommandtable.szTip);
  754. m_strCmdKey2.Format("%s",(*itCommandstyle).szName);
  755. m_strKeyContx2.Format("%s",(*itCommandstyle).szData);
  756. UpdateData(FALSE);
  757. break;
  758. }
  759. }
  760. }
  761. }
  762. if ( pDepotObject )
  763. {
  764. delete pDepotObject;
  765. pDepotObject = NULL;
  766. }
  767. }
  768. void CEditorDlg::OnSysCommand(UINT nID, LPARAM lParam)
  769. {
  770. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  771. {
  772. CAboutDlg dlgAbout;
  773. dlgAbout.DoModal();
  774. }
  775. else
  776. {
  777. CDialog::OnSysCommand(nID, lParam);
  778. }
  779. }
  780. // 如果向对话框添加最小化按钮,则需要下面的代码
  781. // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
  782. // 这将由框架自动完成。
  783. void CEditorDlg::OnPaint()
  784. {
  785. if (IsIconic())
  786. {
  787. CPaintDC dc(this); // 用于绘制的设备上下文
  788. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  789. // 使图标在工作矩形中居中
  790. int cxIcon = GetSystemMetrics(SM_CXICON);
  791. int cyIcon = GetSystemMetrics(SM_CYICON);
  792. CRect rect;
  793. GetClientRect(&rect);
  794. int x = (rect.Width() - cxIcon + 1) / 2;
  795. int y = (rect.Height() - cyIcon + 1) / 2;
  796. // 绘制图标
  797. dc.DrawIcon(x, y, m_hIcon);
  798. }
  799. else
  800. {
  801. CDialog::OnPaint();
  802. }
  803. }
  804. //当用户拖动最小化窗口时系统调用此函数取得光标显示。
  805. HCURSOR CEditorDlg::OnQueryDragIcon()
  806. {
  807. return static_cast<HCURSOR>(m_hIcon);
  808. }
  809. BOOL CEditorDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  810. {
  811. // TODO: 在此添加专用代码和/或调用基类
  812. if ( !::IsWindow(m_CtrlTree))
  813. {
  814. return CDialog::OnNotify(wParam, lParam, pResult);
  815. }
  816. LPNMHDR pNmhdr = (LPNMHDR)lParam;
  817. int idCtrl = LOWORD(wParam); // 获取控件ID;
  818. // 如果消息对象是该资源(树);
  819. if( idCtrl == IDC_TREE1 )
  820. {
  821. CPoint point;
  822. ::GetCursorPos(&point);
  823. m_CtrlTree.ScreenToClient(&point);
  824. switch( pNmhdr->code )
  825. {
  826. case NM_CLICK: // 单击;
  827. {
  828. // Get Click item's
  829. UINT uFlags;
  830. HTREEITEM hItem = m_CtrlTree.HitTest(point, &uFlags);
  831. if((hItem != NULL) && (TVHT_ONITEM & uFlags))
  832. {
  833. m_CtrlTree.SelectItem(hItem);
  834. }
  835. // 对所有单击,禁用修改按钮 [4/8/2013 Zero.t]
  836. GetDlgItem(Btn_ModifyDevice)->EnableWindow(FALSE);
  837. return true;//Already process the notify
  838. }
  839. case NM_RCLICK: // 右击,专门处理菜单;
  840. {
  841. // Get RightClick item's
  842. UINT uFlags;
  843. HTREEITEM hItem = m_CtrlTree.HitTest(point, &uFlags);
  844. m_CtrlTree.SelectItem(hItem);
  845. if((hItem != NULL) && (TVHT_ONITEM & uFlags))
  846. {
  847. GetCursorPos(&m_mousePoint); // 保存当前鼠标位置;
  848. HTREEITEM hSelectedItem = m_CtrlTree.GetSelectedItem();
  849. // 获取项在容器中的层次信息;
  850. CString strName = m_CtrlTree.GetItemText(hSelectedItem);
  851. int nType = TypeTreeItem(hSelectedItem);
  852. #if 1 // 使用弹出菜单;
  853. CMenu menu;
  854. menu.LoadMenu(IDR_MENU1);
  855. if( nType == 0 )
  856. {
  857. //menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL);
  858. }
  859. else if ( nType == 1 )
  860. {
  861. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL);
  862. }
  863. else if ( nType == 2 )
  864. {
  865. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL);
  866. }
  867. else if ( nType == 3 )
  868. {
  869. menu.GetSubMenu(4)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL);
  870. }
  871. #endif
  872. }
  873. // 对所有单击,禁用修改按钮 [4/8/2013 Zero.t]
  874. GetDlgItem(Btn_ModifyDevice)->EnableWindow(FALSE);
  875. return true;//Already process the notify
  876. }
  877. case NM_DBLCLK: // 左键 双击;
  878. {
  879. UINT uFlags;
  880. HTREEITEM hItem = m_CtrlTree.HitTest(point, &uFlags);
  881. m_CtrlTree.SelectItem(hItem);
  882. if((hItem != NULL) && (TVHT_ONITEM & uFlags))
  883. {
  884. GetCursorPos(&m_mousePoint); // 保存当前鼠标位置;
  885. HTREEITEM hSelectedItem = m_CtrlTree.GetSelectedItem();
  886. if ( !m_CtrlTree.ItemHasChildren(hSelectedItem))
  887. {
  888. //CString strName = m_CtrlTree.GetItemText(hSelectedItem);
  889. //InitDeviceComInfo(strName);
  890. m_strOldDeviceName = m_CtrlTree.GetItemText(hSelectedItem);
  891. InitDeviceComInfo(m_strOldDeviceName);
  892. // 对所有单击,禁用修改按钮 [4/8/2013 Zero.t]
  893. GetDlgItem(Btn_ModifyDevice)->EnableWindow();
  894. }
  895. }
  896. return true;
  897. }
  898. }
  899. return false; // no match
  900. }
  901. if ( idCtrl == IDC_TREE2)
  902. {
  903. CPoint point;
  904. ::GetCursorPos(&point);
  905. m_CtrlSubTree.ScreenToClient(&point);
  906. switch( pNmhdr->code )
  907. {
  908. case NM_CLICK: // 单击;
  909. {
  910. // Get Click item's
  911. UINT uFlags;
  912. HTREEITEM hItem = m_CtrlSubTree.HitTest(point, &uFlags);
  913. if((hItem != NULL) && (TVHT_ONITEM & uFlags))
  914. {
  915. m_CtrlSubTree.SelectItem(hItem);
  916. }
  917. // 单击禁用修改按钮 [4/8/2013 Zero.t]
  918. GetDlgItem(Btn_ModifyCmdStyle)->EnableWindow(FALSE);
  919. GetDlgItem(Btn_ModifyCmdImpl)->EnableWindow(FALSE);
  920. return true;//Already process the notify
  921. }
  922. case NM_RCLICK: // 右击,专门处理菜单;
  923. {
  924. // Get RightClick item's
  925. UINT uFlags;
  926. HTREEITEM hItem = m_CtrlSubTree.HitTest(point, &uFlags);
  927. m_CtrlSubTree.SelectItem(hItem);
  928. if((hItem != NULL) && (TVHT_ONITEM & uFlags))
  929. {
  930. GetCursorPos(&m_mousePoint); // 保存当前鼠标位置;
  931. HTREEITEM hSelectedItem = m_CtrlSubTree.GetSelectedItem();
  932. // 获取项在容器中的层次信息;
  933. CString strName = m_CtrlSubTree.GetItemText(hSelectedItem);
  934. int nType = TypeCommandTreeItem(hSelectedItem);
  935. #if 1 // 使用弹出菜单;
  936. CMenu menu;
  937. menu.LoadMenu(IDR_MENU1);
  938. if( nType == 0 )
  939. {
  940. //menu.GetSubMenu(2)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL);
  941. }
  942. else if ( nType == 1 )
  943. {
  944. menu.GetSubMenu(1)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL);
  945. }
  946. else if ( nType == 2 )
  947. {
  948. menu.GetSubMenu(2)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL);
  949. }
  950. else if ( nType == 3 )
  951. {
  952. menu.GetSubMenu(5)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL);
  953. }
  954. else if ( nType == 4 )
  955. {
  956. menu.GetSubMenu(3)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL);
  957. }
  958. else if ( nType ==5 )
  959. {
  960. menu.GetSubMenu(5)->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, m_mousePoint.x, m_mousePoint.y, this, NULL);
  961. }
  962. #endif
  963. }
  964. // 单击禁用修改按钮 [4/8/2013 Zero.t]
  965. GetDlgItem(Btn_ModifyCmdStyle)->EnableWindow(FALSE);
  966. GetDlgItem(Btn_ModifyCmdImpl)->EnableWindow(FALSE);
  967. return true;//Already process the notify
  968. }
  969. case NM_DBLCLK: // 左键 双击;
  970. {
  971. UINT uFlags;
  972. HTREEITEM hItem = m_CtrlSubTree.HitTest(point, &uFlags);
  973. m_CtrlSubTree.SelectItem(hItem);
  974. if((hItem != NULL) && (TVHT_ONITEM & uFlags))
  975. {
  976. GetCursorPos(&m_mousePoint); // 保存当前鼠标位置;
  977. HTREEITEM hSelectedItem = m_CtrlSubTree.GetSelectedItem();
  978. InitCommandInfo(hSelectedItem);
  979. //// 单击禁用修改按钮 [4/8/2013 Zero.t]
  980. //GetDlgItem(Btn_ModifyCmdStyle)->EnableWindow();
  981. //GetDlgItem(Btn_ModifyCmdImpl)->EnableWindow();
  982. }
  983. return true;
  984. }
  985. }
  986. return false; // no match
  987. }
  988. return CDialog::OnNotify(wParam, lParam, pResult);
  989. }
  990. BOOL CEditorDlg::DestroyWindow()
  991. {
  992. // TODO: 在此添加专用代码和/或调用基类
  993. return CDialog::DestroyWindow();
  994. }
  995. void CEditorDlg::OnAddDeviceProperty()
  996. {
  997. // TODO: 在此添加命令处理程序代码
  998. HTREEITEM hSelectItem = m_CtrlTree.GetSelectedItem();
  999. CString strDevice = m_CtrlTree.GetItemText(hSelectItem);
  1000. InitDeviceComInfo(strDevice);
  1001. //AfxMessageBox(strDevice);
  1002. }
  1003. void CEditorDlg::OnDeletedevice()
  1004. {
  1005. // TODO: 在此添加命令处理程序代码
  1006. HTREEITEM hSelectItem = m_CtrlTree.GetSelectedItem();
  1007. CString strDevice = m_CtrlTree.GetItemText(hSelectItem);
  1008. CObjectdepot tObjectdepot;
  1009. tObjectdepot.SetDevicesDepotPath(m_strDepotPath);
  1010. tObjectdepot.SetRuntimeDevicesDepotPath(m_strRutDepotPath);
  1011. tObjectdepot.RemoveElement(strDevice.GetBuffer());
  1012. strDevice.ReleaseBuffer();
  1013. //AfxMessageBox("删除成功");
  1014. ClearTreeCtrlInfo(hSelectItem);
  1015. }
  1016. void CEditorDlg::OnAdddevice()// 添加设备;
  1017. {
  1018. // TODO: 在此添加命令处理程序代码
  1019. HTREEITEM hSelectItem = m_CtrlTree.GetSelectedItem();
  1020. CString strName = m_CtrlTree.GetItemText(hSelectItem);
  1021. int nType = TypeTreeItem(hSelectItem);
  1022. CAddDevice dlg;
  1023. if ( nType == 1 )
  1024. {
  1025. dlg.m_strClassType = strName;
  1026. }
  1027. else if ( nType == 2 )
  1028. {
  1029. HTREEITEM hParent = m_CtrlTree.GetParentItem(hSelectItem);
  1030. dlg.m_strClassType = m_CtrlTree.GetItemText(hParent);
  1031. dlg.m_strDeviceName = strName;
  1032. dlg.m_strFactory = strName;
  1033. }
  1034. if ( dlg.DoModal() == IDOK )
  1035. InitTreeCtrlInfo();
  1036. }
  1037. void CEditorDlg::OnAddcmdStyle() //添加指令格式;
  1038. {
  1039. // TODO: 在此添加命令处理程序代码
  1040. HTREEITEM hSelectItem = m_CtrlSubTree.GetSelectedItem();
  1041. CString strName = m_CtrlSubTree.GetItemText(hSelectItem);
  1042. CObjectdepot tObjectdepot;
  1043. tObjectdepot.SetDevicesDepotPath(m_strDepotPath);
  1044. tObjectdepot.SetRuntimeDevicesDepotPath(m_strRutDepotPath);
  1045. STDepotObject *pDepotObject = tObjectdepot.LookupElement(m_strOldDeviceName) ;
  1046. if ( pDepotObject == NULL )
  1047. return;
  1048. CAddCmdStlye dlg;
  1049. dlg.m_strCmdSize.Format("%d",pDepotObject->ByteCount);
  1050. dlg.m_strOldDeviceName = m_strOldDeviceName;
  1051. dlg.m_strRutDepotPath = m_strRutDepotPath;
  1052. dlg.m_strDepotPath = m_strDepotPath;
  1053. if ( dlg.DoModal() == IDOK )
  1054. {
  1055. // 刷新;
  1056. InitDeviceComInfo(m_strOldDeviceName);
  1057. }
  1058. if ( pDepotObject )
  1059. {
  1060. delete pDepotObject;
  1061. pDepotObject = NULL;
  1062. }
  1063. }
  1064. void CEditorDlg::OnAddcmdimpl()
  1065. {
  1066. // TODO: 在此添加命令处理程序代码
  1067. HTREEITEM hSelectItem = m_CtrlSubTree.GetSelectedItem();
  1068. CString strName = m_CtrlSubTree.GetItemText(hSelectItem);
  1069. CAddCmdImpl dlg;
  1070. dlg.m_strOldDeviceName = m_strOldDeviceName;
  1071. dlg.m_strRutDepotPath = m_strRutDepotPath;
  1072. dlg.m_strDepotPath = m_strDepotPath;
  1073. if ( dlg.DoModal() == IDOK )
  1074. {
  1075. // 刷新;
  1076. InitDeviceComInfo(m_strOldDeviceName);
  1077. }
  1078. }
  1079. void CEditorDlg::OnAddcmdimteimpl()
  1080. {
  1081. // TODO: 在此添加命令处理程序代码
  1082. HTREEITEM hSelectItem = m_CtrlSubTree.GetSelectedItem();
  1083. CString strName = m_CtrlSubTree.GetItemText(hSelectItem);
  1084. CAddCmdImplItem dlg;
  1085. dlg.m_strOldDeviceName = m_strOldDeviceName;
  1086. dlg.m_strRutDepotPath = m_strRutDepotPath;
  1087. dlg.m_strDepotPath = m_strDepotPath;
  1088. dlg.m_strOldMark = strName;
  1089. if ( dlg.DoModal() == IDOK )
  1090. {
  1091. // 刷新;
  1092. InitDeviceComInfo(m_strOldDeviceName);
  1093. }
  1094. }
  1095. void CEditorDlg::OnBnClickedModifydevice()//修改设备;
  1096. {
  1097. CString str;
  1098. GetDlgItemText(Btn_ModifyDevice,str);
  1099. if ( str == "修改属性" )
  1100. {
  1101. #if 1 // 启用被禁用的按钮;
  1102. GetDlgItem(ET_DEVICENAME)->EnableWindow();
  1103. GetDlgItem(ET_DEVICEID)->EnableWindow();
  1104. GetDlgItem(CB_RATE)->EnableWindow();
  1105. GetDlgItem(CB_DATABIT)->EnableWindow();
  1106. GetDlgItem(CB_STOPBIT)->EnableWindow();
  1107. GetDlgItem(CB_PARITY)->EnableWindow();
  1108. GetDlgItem(ET_RESPONSETIME)->EnableWindow();
  1109. GetDlgItem(ET_FREQUENCY)->EnableWindow();
  1110. GetDlgItem(ET_LINETYPE)->EnableWindow();
  1111. GetDlgItem(ET_COMTYPE)->EnableWindow();
  1112. GetDlgItem(ET_PINDEF)->EnableWindow();
  1113. GetDlgItem(ET_FACTORY)->EnableWindow();
  1114. GetDlgItem(ET_CLASSTYPE)->EnableWindow();
  1115. GetDlgItem(ET_SERIES)->EnableWindow();
  1116. GetDlgItem(ET_NAME)->EnableWindow();
  1117. GetDlgItem(ET_MODELNUM)->EnableWindow();
  1118. GetDlgItem(ET_PROTOCOL)->EnableWindow();
  1119. #endif
  1120. SetDlgItemText(Btn_ModifyDevice,"应用修改");
  1121. }
  1122. UpdateData();
  1123. if ( str == "应用修改" )
  1124. {
  1125. #if 1 // 禁用的按钮;
  1126. GetDlgItem(ET_DEVICENAME)->EnableWindow(FALSE);
  1127. GetDlgItem(ET_DEVICEID)->EnableWindow(FALSE);
  1128. GetDlgItem(CB_RATE)->EnableWindow(FALSE);
  1129. GetDlgItem(CB_DATABIT)->EnableWindow(FALSE);
  1130. GetDlgItem(CB_STOPBIT)->EnableWindow(FALSE);
  1131. GetDlgItem(CB_PARITY)->EnableWindow(FALSE);
  1132. GetDlgItem(ET_RESPONSETIME)->EnableWindow(FALSE);
  1133. GetDlgItem(ET_FREQUENCY)->EnableWindow(FALSE);
  1134. GetDlgItem(ET_LINETYPE)->EnableWindow(FALSE);
  1135. GetDlgItem(ET_COMTYPE)->EnableWindow(FALSE);
  1136. GetDlgItem(ET_PINDEF)->EnableWindow(FALSE);
  1137. GetDlgItem(ET_FACTORY)->EnableWindow(FALSE);
  1138. GetDlgItem(ET_CLASSTYPE)->EnableWindow(FALSE);
  1139. GetDlgItem(ET_SERIES)->EnableWindow(FALSE);
  1140. GetDlgItem(ET_NAME)->EnableWindow(FALSE);
  1141. GetDlgItem(ET_MODELNUM)->EnableWindow(FALSE);
  1142. GetDlgItem(ET_PROTOCOL)->EnableWindow(FALSE);
  1143. #endif
  1144. #if 1 // 修改属性 [4/3/2013 Zero.t]
  1145. CObjectdepot tObjectdepot;
  1146. tObjectdepot.SetDevicesDepotPath(m_strDepotPath);
  1147. tObjectdepot.SetRuntimeDevicesDepotPath(m_strRutDepotPath);
  1148. STDepotPhysical tDevicePhysical;
  1149. STDeviceDocument tDeviceDocument;
  1150. tDevicePhysical.iRate = GetDlgItemInt(CB_RATE);
  1151. tDevicePhysical.iDBit = GetDlgItemInt(CB_DATABIT);
  1152. tDevicePhysical.iSBit = m_cobStopbit.GetCurSel();
  1153. tDevicePhysical.iPaty = m_cobParity.GetCurSel();
  1154. tDevicePhysical.iRsTm = GetDlgItemInt(ET_RESPONSETIME);
  1155. tDevicePhysical.iIntl = GetDlgItemInt(ET_FREQUENCY);
  1156. sprintf(tDevicePhysical.szLineType,"%s",m_strLineType);
  1157. sprintf(tDevicePhysical.szComType,"%s",m_strComType);
  1158. sprintf(tDevicePhysical.szPinDef,"%s",m_strLineType);
  1159. sprintf(tDeviceDocument.szdeviceClass,"%s",m_strSeries);
  1160. sprintf(tDeviceDocument.szdeviceName,"%s",m_strDeviceName2);
  1161. sprintf(tDeviceDocument.szdeviceType,"%s",m_strClassType);
  1162. sprintf(tDeviceDocument.szFactory,"%s",m_strFactory);
  1163. sprintf(tDeviceDocument.szProtocol,"%s",m_strProtocol);
  1164. sprintf(tDeviceDocument.szUnitType,"%s",m_strModelNum);
  1165. tObjectdepot.ModifyElementNode(
  1166. m_strOldDeviceName,
  1167. m_strDeviceName,
  1168. m_strDeviceID,
  1169. tDevicePhysical,
  1170. tDeviceDocument);
  1171. #endif
  1172. SetDlgItemText(Btn_ModifyDevice,"修改属性");
  1173. InitTreeCtrlInfo();
  1174. }
  1175. }
  1176. void CEditorDlg::OnBnClickedModifycmdstyle()//修改指令格式;
  1177. {
  1178. CString str;
  1179. GetDlgItemText(Btn_ModifyCmdStyle,str);
  1180. if ( str == "修改属性" )
  1181. {
  1182. #if 1 // 启用被禁用的按钮;
  1183. GetDlgItem(ET_CMDSIZE)->EnableWindow();
  1184. GetDlgItem(ET_CMDKEY1)->EnableWindow();
  1185. GetDlgItem(ET_KEYLEN)->EnableWindow();
  1186. GetDlgItem(CB_KEYTYPE)->EnableWindow();
  1187. GetDlgItem(ET_KEYCONTX)->EnableWindow();
  1188. #endif
  1189. SetDlgItemText(Btn_ModifyCmdStyle,"应用修改");
  1190. }
  1191. UpdateData();
  1192. if ( str == "应用修改" )
  1193. {
  1194. #if 1 // 禁用的按钮;
  1195. GetDlgItem(ET_CMDSIZE)->EnableWindow(FALSE);
  1196. GetDlgItem(ET_CMDKEY1)->EnableWindow(FALSE);
  1197. GetDlgItem(ET_KEYLEN)->EnableWindow(FALSE);
  1198. GetDlgItem(CB_KEYTYPE)->EnableWindow(FALSE);
  1199. GetDlgItem(ET_KEYCONTX)->EnableWindow(FALSE);
  1200. #endif
  1201. #if 1 // 修改属性 [4/3/2013 Zero.t]
  1202. CObjectdepot tObjectdepot;
  1203. tObjectdepot.SetDevicesDepotPath(m_strDepotPath);
  1204. tObjectdepot.SetRuntimeDevicesDepotPath(m_strRutDepotPath);
  1205. char szKeyType[2] = {0};
  1206. itoa(GetDlgItemInt(CB_KEYTYPE),szKeyType,10);
  1207. tObjectdepot.ModifyElementCommandStyle(
  1208. m_strDeviceName.GetBuffer(),
  1209. m_strOldKey.GetBuffer(),
  1210. m_strCmdKey1.GetBuffer(),
  1211. m_strKeyLen.GetBuffer(),
  1212. m_strKeyContx1.GetBuffer(),
  1213. szKeyType,
  1214. GetDlgItemInt(ET_CMDSIZE)
  1215. );
  1216. m_strDeviceName.ReleaseBuffer();
  1217. m_strOldKey.ReleaseBuffer();
  1218. m_strCmdKey1.ReleaseBuffer();
  1219. m_strKeyLen.ReleaseBuffer();
  1220. m_strKeyContx1.ReleaseBuffer();
  1221. #endif
  1222. SetDlgItemText(Btn_ModifyCmdStyle,"修改属性");
  1223. }
  1224. }
  1225. void CEditorDlg::OnBnClickedModifycmdimpl()//修改指令实现
  1226. {
  1227. CString str;
  1228. GetDlgItemText(Btn_ModifyCmdImpl,str);
  1229. if ( str == "修改属性" )
  1230. {
  1231. #if 1 // 启用被禁用的按钮;
  1232. GetDlgItem(CB_STORERECV)->EnableWindow();
  1233. GetDlgItem(ET_MARK)->EnableWindow();
  1234. GetDlgItem(ET_CMDTIP)->EnableWindow();
  1235. GetDlgItem(ET_CMDKEY2)->EnableWindow();
  1236. GetDlgItem(ET_KEYCONTXT2)->EnableWindow();
  1237. #endif
  1238. SetDlgItemText(Btn_ModifyCmdImpl,"应用修改");
  1239. }
  1240. UpdateData();
  1241. if ( str == "应用修改" )
  1242. {
  1243. #if 1 // 禁用的按钮;
  1244. GetDlgItem(CB_STORERECV)->EnableWindow(FALSE);
  1245. GetDlgItem(ET_MARK)->EnableWindow(FALSE);
  1246. GetDlgItem(ET_CMDTIP)->EnableWindow(FALSE);
  1247. GetDlgItem(ET_CMDKEY2)->EnableWindow(FALSE);
  1248. GetDlgItem(ET_KEYCONTXT2)->EnableWindow(FALSE);
  1249. #endif
  1250. #if 1 // 修改属性 [4/3/2013 Zero.t]
  1251. CObjectdepot tObjectdepot;
  1252. tObjectdepot.SetDevicesDepotPath(m_strDepotPath);
  1253. tObjectdepot.SetRuntimeDevicesDepotPath(m_strRutDepotPath);
  1254. if ( m_strCmdKey2 == "" && m_strKeyContx2 == "" )
  1255. {
  1256. tObjectdepot.ModifyElementCommand(
  1257. m_strDeviceName.GetBuffer(),
  1258. m_strOldMark.GetBuffer(),
  1259. m_strMark.GetBuffer(),
  1260. m_cobStore.GetCurSel(),
  1261. m_strCmdTip.GetBuffer()
  1262. );
  1263. }
  1264. else
  1265. {
  1266. tObjectdepot.ModifyElementCmdImpl(
  1267. m_strDeviceName.GetBuffer(),
  1268. m_strOldMark.GetBuffer(),
  1269. m_strMark.GetBuffer(),
  1270. m_cobStore.GetCurSel(),
  1271. m_strCmdTip.GetBuffer(),
  1272. m_strOldKey.GetBuffer(),
  1273. m_strCmdKey2.GetBuffer(),
  1274. m_strKeyContx2.GetBuffer()
  1275. );
  1276. }
  1277. InitDeviceComInfo(m_strOldDeviceName);
  1278. m_strDeviceName.ReleaseBuffer();
  1279. m_strOldMark.ReleaseBuffer();
  1280. m_strMark.ReleaseBuffer();
  1281. m_strCmdTip.ReleaseBuffer();
  1282. m_strOldKey.ReleaseBuffer();
  1283. m_strCmdKey2.ReleaseBuffer();
  1284. m_strKeyContx2.ReleaseBuffer();
  1285. #endif
  1286. SetDlgItemText(Btn_ModifyCmdImpl,"修改属性");
  1287. }
  1288. }
  1289. void CEditorDlg::OnDeleteitem()
  1290. {
  1291. HTREEITEM hSelectItem = m_CtrlSubTree.GetSelectedItem();
  1292. HTREEITEM hRootItem = m_CtrlSubTree.GetParentItem(hSelectItem);
  1293. CString strParent = m_CtrlSubTree.GetItemText(hRootItem);
  1294. CString strName = m_CtrlSubTree.GetItemText(hSelectItem);
  1295. CObjectdepot tObjectdepot;
  1296. tObjectdepot.SetDevicesDepotPath(m_strDepotPath);
  1297. tObjectdepot.SetRuntimeDevicesDepotPath(m_strRutDepotPath);
  1298. if ( strParent == "指令格式" )
  1299. {
  1300. tObjectdepot.DeleteElementCommandStyle(m_strOldDeviceName.GetBuffer(),strName.GetBuffer());
  1301. }
  1302. else
  1303. {
  1304. tObjectdepot.DeleteElementCommandImplItem(m_strOldDeviceName.GetBuffer(),strParent.GetBuffer(),strName.GetBuffer());
  1305. }
  1306. m_strOldDeviceName.ReleaseBuffer();
  1307. strParent.ReleaseBuffer();
  1308. strName.ReleaseBuffer();
  1309. ClearTreeInfo(hSelectItem);
  1310. }
  1311. void CEditorDlg::OnDeletecmdimpl()
  1312. {
  1313. HTREEITEM hSelectItem = m_CtrlSubTree.GetSelectedItem();
  1314. HTREEITEM hRootItem = m_CtrlSubTree.GetParentItem(hSelectItem);
  1315. CString strParent = m_CtrlSubTree.GetItemText(hRootItem);
  1316. CString strName = m_CtrlSubTree.GetItemText(hSelectItem);
  1317. CObjectdepot tObjectdepot;
  1318. tObjectdepot.SetDevicesDepotPath(m_strDepotPath);
  1319. tObjectdepot.SetRuntimeDevicesDepotPath(m_strRutDepotPath);
  1320. if ( strParent == "指令实现" )
  1321. {
  1322. tObjectdepot.DeleteElementCmdImpl(m_strOldDeviceName.GetBuffer(),strName.GetBuffer());
  1323. }
  1324. m_strOldDeviceName.ReleaseBuffer();
  1325. strName.ReleaseBuffer();
  1326. ClearTreeInfo(hSelectItem);
  1327. }
  1328. void CEditorDlg::Enable_1(BOOL bSet)
  1329. {
  1330. // 启用被禁用的按钮;
  1331. if ( bSet )
  1332. {
  1333. GetDlgItem(ET_DEVICENAME)->EnableWindow();
  1334. GetDlgItem(ET_DEVICEID)->EnableWindow();
  1335. GetDlgItem(CB_RATE)->EnableWindow();
  1336. GetDlgItem(CB_DATABIT)->EnableWindow();
  1337. GetDlgItem(CB_STOPBIT)->EnableWindow();
  1338. GetDlgItem(CB_PARITY)->EnableWindow();
  1339. GetDlgItem(ET_RESPONSETIME)->EnableWindow();
  1340. GetDlgItem(ET_FREQUENCY)->EnableWindow();
  1341. GetDlgItem(ET_LINETYPE)->EnableWindow();
  1342. GetDlgItem(ET_COMTYPE)->EnableWindow();
  1343. GetDlgItem(ET_PINDEF)->EnableWindow();
  1344. GetDlgItem(ET_FACTORY)->EnableWindow();
  1345. GetDlgItem(ET_CLASSTYPE)->EnableWindow();
  1346. GetDlgItem(ET_SERIES)->EnableWindow();
  1347. GetDlgItem(ET_NAME)->EnableWindow();
  1348. GetDlgItem(ET_MODELNUM)->EnableWindow();
  1349. GetDlgItem(ET_PROTOCOL)->EnableWindow();
  1350. //SetDlgItemText(Btn_ModifyDevice,"应用修改");
  1351. }
  1352. else
  1353. {
  1354. // 禁用的按钮;
  1355. GetDlgItem(ET_DEVICENAME)->EnableWindow(FALSE);
  1356. GetDlgItem(ET_DEVICEID)->EnableWindow(FALSE);
  1357. GetDlgItem(CB_RATE)->EnableWindow(FALSE);
  1358. GetDlgItem(CB_DATABIT)->EnableWindow(FALSE);
  1359. GetDlgItem(CB_STOPBIT)->EnableWindow(FALSE);
  1360. GetDlgItem(CB_PARITY)->EnableWindow(FALSE);
  1361. GetDlgItem(ET_RESPONSETIME)->EnableWindow(FALSE);
  1362. GetDlgItem(ET_FREQUENCY)->EnableWindow(FALSE);
  1363. GetDlgItem(ET_LINETYPE)->EnableWindow(FALSE);
  1364. GetDlgItem(ET_COMTYPE)->EnableWindow(FALSE);
  1365. GetDlgItem(ET_PINDEF)->EnableWindow(FALSE);
  1366. GetDlgItem(ET_FACTORY)->EnableWindow(FALSE);
  1367. GetDlgItem(ET_CLASSTYPE)->EnableWindow(FALSE);
  1368. GetDlgItem(ET_SERIES)->EnableWindow(FALSE);
  1369. GetDlgItem(ET_NAME)->EnableWindow(FALSE);
  1370. GetDlgItem(ET_MODELNUM)->EnableWindow(FALSE);
  1371. GetDlgItem(ET_PROTOCOL)->EnableWindow(FALSE);
  1372. }
  1373. }
  1374. void CEditorDlg::Enable_2(BOOL bSet)
  1375. {
  1376. if ( bSet )
  1377. {
  1378. GetDlgItem(ET_CMDSIZE)->EnableWindow();
  1379. GetDlgItem(ET_CMDKEY1)->EnableWindow();
  1380. GetDlgItem(ET_KEYLEN)->EnableWindow();
  1381. GetDlgItem(CB_KEYTYPE)->EnableWindow();
  1382. GetDlgItem(ET_KEYCONTX)->EnableWindow();
  1383. }
  1384. else
  1385. {
  1386. // 禁用的按钮;
  1387. GetDlgItem(ET_CMDSIZE)->EnableWindow(FALSE);
  1388. GetDlgItem(ET_CMDKEY1)->EnableWindow(FALSE);
  1389. GetDlgItem(ET_KEYLEN)->EnableWindow(FALSE);
  1390. GetDlgItem(CB_KEYTYPE)->EnableWindow(FALSE);
  1391. GetDlgItem(ET_KEYCONTX)->EnableWindow(FALSE);
  1392. }
  1393. }
  1394. void CEditorDlg::Enable_3(BOOL bSet)
  1395. {
  1396. if ( bSet )
  1397. {
  1398. // 启用被禁用的按钮;
  1399. GetDlgItem(CB_STORERECV)->EnableWindow();
  1400. GetDlgItem(ET_MARK)->EnableWindow();
  1401. GetDlgItem(ET_CMDTIP)->EnableWindow();
  1402. GetDlgItem(ET_CMDKEY2)->EnableWindow();
  1403. GetDlgItem(ET_KEYCONTXT2)->EnableWindow();
  1404. }
  1405. else
  1406. {
  1407. // 禁用的按钮;
  1408. GetDlgItem(CB_STORERECV)->EnableWindow(FALSE);
  1409. GetDlgItem(ET_MARK)->EnableWindow(FALSE);
  1410. GetDlgItem(ET_CMDTIP)->EnableWindow(FALSE);
  1411. GetDlgItem(ET_CMDKEY2)->EnableWindow(FALSE);
  1412. GetDlgItem(ET_KEYCONTXT2)->EnableWindow(FALSE);
  1413. }
  1414. }
  1415. void CEditorDlg::Expand_Tree_1()
  1416. {
  1417. m_CtrlTree.Expand(hRunRootItem,TVE_EXPAND);
  1418. STTreeInfo tTreeInfo = {0};
  1419. vector <STTreeInfo>::iterator it;
  1420. for ( it = vtSTTreeInfo.begin(); it != vtSTTreeInfo.end(); it++ )
  1421. {
  1422. tTreeInfo = *it;
  1423. m_CtrlTree.Expand(tTreeInfo.hType,TVE_EXPAND);
  1424. }
  1425. }
  1426. void CEditorDlg::Expand_Tree_2()
  1427. {
  1428. m_CtrlSubTree.Expand(tSTDeviceImpl.hDevice,TVE_EXPAND);
  1429. m_CtrlSubTree.Expand(tSTDeviceImpl.tSTComInfo.hComInfo,TVE_EXPAND);
  1430. m_CtrlSubTree.Expand(tSTDeviceImpl.tSTComImpl.hComImpl,TVE_EXPAND);
  1431. }
  1432. void CEditorDlg::OnSize(UINT nType, int cx, int cy)
  1433. {
  1434. CDialog::OnSize(nType, cx, cy);
  1435. // TODO: Add your message handler code here.
  1436. // ---------------垂直滚动条;
  1437. m_nCurHeight = cy;
  1438. int nScrollMaxHeight;
  1439. if (cy < m_rect.Height())
  1440. {
  1441. nScrollMaxHeight = m_rect.Height() - cy;
  1442. }
  1443. else
  1444. nScrollMaxHeight = 0;
  1445. SCROLLINFO si_height;
  1446. si_height.cbSize = sizeof(SCROLLINFO);
  1447. si_height.fMask = SIF_ALL; // SIF_ALL = SIF_PAGE | SIF_RANGE | SIF_POS;
  1448. si_height.nMin = 0;
  1449. si_height.nMax = nScrollMaxHeight;
  1450. si_height.nPage = si_height.nMax/10;
  1451. si_height.nPos = 0;
  1452. SetScrollInfo(SB_VERT, &si_height, TRUE);
  1453. // --------------水平滚动条;
  1454. m_nCurWidth = cx;
  1455. int nScrollMaxWidth;
  1456. if (cx < m_rect.Width())
  1457. {
  1458. nScrollMaxWidth = m_rect.Width() - cx;
  1459. }
  1460. else
  1461. nScrollMaxWidth = 0;
  1462. SCROLLINFO si_width;
  1463. si_width.cbSize = sizeof(SCROLLINFO);
  1464. si_width.fMask = SIF_ALL; // SIF_ALL = SIF_PAGE | SIF_RANGE | SIF_POS;
  1465. si_width.nMin = 0;
  1466. si_width.nMax = nScrollMaxWidth;
  1467. si_width.nPage = si_width.nMax/10;
  1468. si_width.nPos = 0;
  1469. SetScrollInfo(SB_HORZ, &si_width, TRUE);
  1470. // TODO: 在此处添加消息处理程序代码
  1471. }
  1472. // 垂直滚动条;
  1473. void CEditorDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1474. {
  1475. // TODO: 在此添加消息处理程序代码和/或调用默认值
  1476. int nDelta;
  1477. int nMaxPos = m_rect.Height() - m_nCurHeight;
  1478. switch (nSBCode)
  1479. {
  1480. case SB_LINEDOWN:
  1481. if (m_nHeightScrollPos >= nMaxPos)
  1482. return;
  1483. nDelta = min(nMaxPos/100,nMaxPos-m_nHeightScrollPos);
  1484. break;
  1485. case SB_LINEUP:
  1486. if (m_nHeightScrollPos <= 0)
  1487. return;
  1488. nDelta = -min(nMaxPos/100,m_nHeightScrollPos);
  1489. break;
  1490. case SB_PAGEDOWN:
  1491. if (m_nHeightScrollPos >= nMaxPos)
  1492. return;
  1493. nDelta = min(nMaxPos/10,nMaxPos-m_nHeightScrollPos);
  1494. break;
  1495. case SB_THUMBPOSITION:
  1496. nDelta = (int)nPos - m_nHeightScrollPos;
  1497. break;
  1498. case SB_PAGEUP:
  1499. if (m_nHeightScrollPos <= 0)
  1500. return;
  1501. nDelta = -min(nMaxPos/10,m_nHeightScrollPos);
  1502. break;
  1503. default:
  1504. return;
  1505. }
  1506. m_nHeightScrollPos += nDelta;
  1507. SetScrollPos(SB_VERT,m_nHeightScrollPos,TRUE);
  1508. ScrollWindow(0,-nDelta);
  1509. CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
  1510. }
  1511. void CEditorDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1512. {
  1513. // TODO: 在此添加消息处理程序代码和/或调用默认值
  1514. int nDelta;
  1515. int nMaxPos = m_rect.Width() - m_nCurWidth;
  1516. //int minpos;
  1517. //int maxpos;
  1518. //pScrollBar->GetScrollRange(&minpos, &maxpos);
  1519. switch (nSBCode)
  1520. {
  1521. case SB_LINELEFT:
  1522. if (m_nWidthScrollPos >= nMaxPos)
  1523. return;
  1524. nDelta = min(nMaxPos/100,nMaxPos-m_nWidthScrollPos);
  1525. break;
  1526. case SB_LINERIGHT:
  1527. if (m_nWidthScrollPos <= 0)
  1528. return;
  1529. nDelta = -min(nMaxPos/100,m_nWidthScrollPos);
  1530. break;
  1531. case SB_PAGEDOWN:
  1532. if (m_nWidthScrollPos >= nMaxPos)
  1533. return;
  1534. nDelta = min(nMaxPos/10,nMaxPos-m_nWidthScrollPos);
  1535. break;
  1536. case SB_THUMBPOSITION:
  1537. nDelta = (int)nPos - m_nWidthScrollPos;
  1538. break;
  1539. case SB_PAGEUP:
  1540. if (m_nWidthScrollPos <= 0)
  1541. return;
  1542. nDelta = -min(nMaxPos/10,m_nWidthScrollPos);
  1543. break;
  1544. default:
  1545. return;
  1546. }
  1547. m_nWidthScrollPos += nDelta;
  1548. SetScrollPos(SB_HORZ,m_nWidthScrollPos,TRUE);
  1549. ScrollWindow(-nDelta,0);
  1550. CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
  1551. }