MainFrm.cpp 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228
  1. // MainFrm.cpp : CMainFrame 类的实现
  2. //
  3. #include "stdafx.h"
  4. #include "IDE.h"
  5. #include "Dlg_Pwd.h"
  6. #include "MainFrm.h"
  7. #include ".\mainfrm.h"
  8. #include <afxwin.h>
  9. #include <afxext.h>
  10. #include <math.h>
  11. #include <io.h>
  12. #include <time.h>
  13. #include <afxdao.h>
  14. //#include <afxtempl.h>
  15. #include "Shlwapi.h"
  16. #include "DrawObj.h"
  17. #include "Graph.h"
  18. #include "ViewNameDlg.h"
  19. #include "Login.h"
  20. #include "IDEView.h"
  21. #include "SystemParaSetDlg.h"
  22. #include "public.h"
  23. #include "SysLib.h"
  24. #include "ffsco.h"
  25. #include "Wizard.h"
  26. #include "DlgEditPwd.h"
  27. #include "Dlg_EditView.h"
  28. #include "FileAndFolderClass.h"
  29. using namespace helper_coffs;
  30. #pragma warning ( disable: 4800 )
  31. #ifdef _DEBUG
  32. #define new DEBUG_NEW
  33. #endif
  34. #if USE_TRAYICON
  35. #define WM_MY_TRAY_NOTIFICATION WM_USER + 1
  36. const UINT WM_TASKBARCREATED =
  37. ::RegisterWindowMessage(_T("TaskbarCreated"));
  38. #endif
  39. // CMainFrame
  40. IMPLEMENT_DYNAMIC(CMainFrame, CMDIAutoHideFrame)
  41. BEGIN_MESSAGE_MAP(CMainFrame, CMDIAutoHideFrame)
  42. ON_WM_CREATE()
  43. ON_COMMAND(IP_SUPER_END, OnSuperEnd)
  44. ON_COMMAND(ID_TRAY_OPEN, OnTrayOpen)
  45. #if USE_TRAYICON
  46. ON_MESSAGE(WM_MY_TRAY_NOTIFICATION, OnTrayNotification)
  47. ON_REGISTERED_MESSAGE(WM_TASKBARCREATED, OnTaskBarCreated)
  48. #endif
  49. ON_WM_CLOSE()
  50. ON_COMMAND(ID_ADDDEVOCE, OnAdddevoce)
  51. ON_UPDATE_COMMAND_UI(ID_ADDDEVOCE, OnUpdateAdddevoce)
  52. ON_COMMAND(IDM_MENU_ZUTAIADD, OnZuTaiAdd)
  53. ON_UPDATE_COMMAND_UI(IDM_MENU_ZUTAIADD, OnUpdateZuTaiAdd)
  54. ON_COMMAND(ID_DELETEPORT, OnDeleteport)
  55. ON_UPDATE_COMMAND_UI(ID_DELETEPORT, OnUpdateDeleteport)
  56. ON_COMMAND(ID_ADD_PORT, OnAddPort)
  57. ON_UPDATE_COMMAND_UI(ID_ADD_PORT, OnUpdateAddPort)
  58. ON_COMMAND(ID_ADD_SCRIPT, OnAddScript)
  59. ON_UPDATE_COMMAND_UI(ID_ADD_SCRIPT, OnUpdateAddScript)
  60. ON_COMMAND(ID_ADDVIEW, OnAddview)
  61. ON_UPDATE_COMMAND_UI(ID_ADDVIEW, OnUpdateAddview)
  62. ON_COMMAND(ID_ADDVIEW2, OnAddview2)
  63. ON_UPDATE_COMMAND_UI(ID_ADDVIEW2, OnUpdateAddview2)
  64. ON_COMMAND(ID_ONLYADD_SORT, OnEditSort)
  65. ON_UPDATE_COMMAND_UI(ID_ONLYADD_SORT, OnUpdateEditSort)
  66. ON_COMMAND(ID_DELETEDEVICE, OnDeletedevice)
  67. ON_UPDATE_COMMAND_UI(ID_DELETEDEVICE, OnUpdateDeletedevice)
  68. ON_COMMAND(ID_DELETEVIEW, OnDeleteview)
  69. ON_UPDATE_COMMAND_UI(ID_DELETEVIEW, OnUpdateDeleteview)
  70. ON_COMMAND(ID_MODIFYVIEWNAME, OnModifyViewName)
  71. ON_UPDATE_COMMAND_UI(ID_MODIFYVIEWNAME, OnUpdateModifyViewName)
  72. ON_COMMAND(ID_DELETESCRIPT, OnDeletescript)
  73. ON_UPDATE_COMMAND_UI(ID_DELETESCRIPT, OnUpdateDeletescript)
  74. ON_COMMAND(ID_SETSCRIPT, OnSetscript)
  75. ON_UPDATE_COMMAND_UI(ID_SETSCRIPT, OnUpdateSetscript)
  76. ON_COMMAND(ID_EDITSCRIPT, OnEditscript)
  77. ON_UPDATE_COMMAND_UI(ID_EDITSCRIPT, OnUpdateEditscript)
  78. ON_COMMAND(ID_USERS, OnUsers)
  79. ON_UPDATE_COMMAND_UI(ID_USERS, OnUpdateUsers)
  80. ON_COMMAND(ID_EDITPWD, OnEditPwdTool)
  81. ON_UPDATE_COMMAND_UI(ID_EDITPWD, OnUpdateEditPwd)
  82. ON_COMMAND(ID_SYSPARE, OnSysPara)
  83. ON_UPDATE_COMMAND_UI(ID_SYSPARE, OnUpdateSysPare)
  84. ON_COMMAND(ID_EVENTMANAGE, OnEventmanage)
  85. ON_COMMAND(ID_EVENT, OnEvent)
  86. ON_COMMAND(ID_SUMMARY_LOG, OnSummaryLog)
  87. ON_UPDATE_COMMAND_UI(ID_EVENT, OnUpdateEvent)
  88. ON_UPDATE_COMMAND_UI(ID_SUMMARY_LOG, OnUpdateSummaryLog)
  89. ON_COMMAND(ID_CONTROLDIALOG, OnControldialog)
  90. ON_WM_DESTROY()
  91. ON_WM_TIMER()
  92. ON_COMMAND(ID_SYSTEMLOG, OnSystemLog)
  93. ON_UPDATE_COMMAND_UI(ID_SYSTEMLOG, OnUpdateSystemLog)
  94. ON_COMMAND(ID_NOTICEREC, OnNoticeRec)
  95. ON_UPDATE_COMMAND_UI(ID_NOTICEREC, OnUpdateNoticeRec)
  96. ON_COMMAND(ID_USER_MANAGER, OnUserManager)
  97. ON_COMMAND(ID_EDIT_PWD, OnEditPwd)
  98. ON_COMMAND(ID_GROUP_MANAGER, OnGroupManager)
  99. ON_COMMAND(ID_SINGLE_ANALOG, OnSingleAnalog)
  100. ON_UPDATE_COMMAND_UI(ID_SINGLE_ANALOG, OnUpdateSingleAnalog)
  101. ON_UPDATE_COMMAND_UI(ID_FILE_PRINT, OnUpdatePrint)
  102. END_MESSAGE_MAP()
  103. static UINT indicators[] =
  104. {
  105. ID_SEPARATOR, // 状态行指示器
  106. ID_INDICATOR_CAPS,
  107. ID_INDICATOR_NUM,
  108. ID_INDICATOR_SCRL,
  109. };
  110. HANDLE m_hFreshVarThread;
  111. HANDLE m_hReConnectSrvThread;
  112. CRITICAL_SECTION g_CSLimit;
  113. // CMainFrame 构造/析构
  114. CMainFrame::CMainFrame():m_trayIcon(IDR_TRAYICON)
  115. {
  116. // TODO: 在此添加成员初始化代码
  117. m_bShowTrayNotifications = TRUE;//zxn
  118. m_bShutdown = FALSE;//zxn
  119. #if USE_NEWTOP
  120. m_pToolBar = NULL;
  121. #else
  122. m_wndOfTop = NULL;
  123. #endif
  124. g_bRun=FALSE;
  125. g_nElementNo=0; //选择
  126. g_bEdit=TRUE;
  127. m_bHideLeft=FALSE;
  128. m_mousePoint=CPoint(0,0);
  129. // View个数
  130. m_nViewCount = 0;
  131. m_nPortNum = 0;
  132. m_nScripts = 0;
  133. int i, j;
  134. //mdi子窗体
  135. for( i = 0; i < MAX_VIEW_NUM; i++ )
  136. {
  137. m_pViewIDE[i] = NULL;
  138. }
  139. m_bEvent = true;
  140. m_bPrint = true;
  141. m_bUsers = true;
  142. m_bSysPare = true;
  143. m_bAnalog = true;
  144. m_bDeviceLog = true;
  145. m_bSystemLog = true;
  146. m_bNoticeRec = true;
  147. m_bEditPwd = true;
  148. m_hCurrent = NULL;
  149. for( int i=0;i<VIEW_MAX_NUM;i++ )
  150. {
  151. m_PIC_VAR[i].sPicPath = "";
  152. for( int j=0;j<1000;j++ )
  153. {
  154. m_PIC_VAR[i].sCaption[j] = "";
  155. m_PIC_VAR[i].nType[i] = 0;
  156. }
  157. }
  158. g_nRunEditVarTick = 0;//在运行状态编辑变量的TICK
  159. g_bRunEditVar = false;//是否在运行状态编辑变量
  160. m_dlgControl = NULL;
  161. m_pDlgZuTaiAdd = NULL;
  162. }
  163. CMainFrame::~CMainFrame()
  164. {
  165. }
  166. #if USE_TRAYICON
  167. BOOL CMainFrame::InstallIcons()
  168. {
  169. return Shell_NotifyIcon(NIM_ADD, &m_trayIcon.m_nid);
  170. }
  171. LRESULT CMainFrame::OnTaskBarCreated(WPARAM wp, LPARAM lp)
  172. {
  173. VERIFY(InstallIcons());
  174. return 0;
  175. }
  176. //////////////////
  177. // Handle notification from tray icon: display a message.
  178. //
  179. LRESULT CMainFrame::OnTrayNotification(WPARAM uID, LPARAM lEvent)
  180. {
  181. if (m_bShowTrayNotifications) {
  182. static LPCSTR MouseMessages[] = { "WM_MOUSEMOVE",
  183. "WM_LBUTTONDOWN", "WM_LBUTTONUP", "WM_LBUTTONDBLCLK",
  184. "WM_RBUTTONDOWN", "WM_RBUTTONUP", "WM_RBUTTONDBLCLK",
  185. "WM_MBUTTONDOWN", "WM_MBUTTONUP", "WM_MBUTTONDBLCLK" };
  186. }
  187. // let tray icon do default stuff
  188. return m_trayIcon.OnTrayNotification(uID, lEvent);
  189. }
  190. #endif
  191. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  192. {
  193. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  194. return -1;
  195. if (!m_wndTree.Create(WS_CHILD|WS_VISIBLE|
  196. TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT,
  197. CRect(0, 0, 0, 0), this, IDD_TREE_LEFT))
  198. {
  199. TRACE0("Failed to create instant bar child\n");
  200. return -1;
  201. }
  202. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  203. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  204. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  205. {
  206. TRACE0(g_strTrace2);
  207. return -1; // 未能创建
  208. }
  209. if (!m_wndDrawToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  210. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  211. !m_wndDrawToolBar.LoadToolBar(IDR_DRAWTOOLS))
  212. {
  213. TRACE0("Failed to create toolbar\n");
  214. return -1; // fail to create
  215. }
  216. if (!m_wndDrawAlignBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  217. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  218. !m_wndDrawAlignBar.LoadToolBar(IDR_ALIGN))
  219. {
  220. TRACE0("Failed to create toolbar\n");
  221. return -1; // fail to create
  222. }
  223. //if (!m_wndRunToolBar.Create(this) ||
  224. // !m_wndRunToolBar.LoadToolBar(IDR_RUNTOOLBAR))
  225. //{
  226. // TRACE0("Failed to create toolbar\n");
  227. // return -1; // fail to create
  228. //}
  229. if (!m_wndStatusBar.Create(this) ||
  230. !m_wndStatusBar.SetIndicators(indicators,
  231. sizeof(indicators)/sizeof(UINT)))
  232. {
  233. TRACE0("未能创建状态栏\n");
  234. return -1; // 未能创建
  235. }
  236. // m_wndRunToolBar.SetBitmap( IDB_LG, COOBmpToolBar::LargeHot, RGB( 33, 231, 222 ) );
  237. // m_wndRunToolBar.SetBitmap( IDB_LG, COOBmpToolBar::LargeStandard, RGB( 33, 231, 222 ) );
  238. // m_wndRunToolBar.InitImageList();
  239. //m_wndRunToolBar.SetTextMode(TRUE);
  240. // TODO: 如果不需要工具栏可停靠,则删除这三行
  241. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  242. m_wndDrawToolBar.EnableDocking(CBRS_ALIGN_ANY);
  243. m_wndDrawAlignBar.EnableDocking(CBRS_ALIGN_ANY);
  244. EnableDocking(CBRS_ALIGN_ANY);
  245. DockControlBar(&m_wndToolBar);
  246. m_wndStatusBar.SetPaneInfo(1, ID_INDICATOR_LOG, SBPS_NOBORDERS,160);
  247. m_wndStatusBar.SetPaneInfo(3, ID_INDICATOR_LOG, SBPS_NOBORDERS,80);
  248. RecalcLayout();
  249. CRect rect;
  250. m_wndToolBar.GetWindowRect(rect);
  251. rect.OffsetRect(1, 0); //偏移一个位置
  252. DockControlBar(&m_wndDrawAlignBar, CBRS_ALIGN_ANY, rect);
  253. DockControlBar(&m_wndDrawToolBar);
  254. //m_wndRunToolBar.EnableDocking(FALSE);
  255. //m_wndRunToolBar.ShowWindow(SW_HIDE);
  256. //上面工具栏
  257. if( g_bStartRun && g_nToolbarRun )
  258. {
  259. //if (!m_wndDockPageBar3.Create(_T("DockPageBar3"), this, CSize(230,105),TRUE,123))
  260. // CSize(),是用来设置高和宽的.
  261. if (!m_htopDockBar.Create(_T("topDockbar"), this, CSize(1920,78),TRUE,123))
  262. {
  263. TRACE0("创建顶部工具栏失败.\n");
  264. return -1;
  265. }
  266. m_htopDockBar.SetBarStyle(m_htopDockBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC );
  267. m_htopDockBar.EnableDocking (CBRS_ALIGN_ANY);
  268. m_htopDockBar.m_bDrawTitleBar = false;
  269. DockControlBar(&m_htopDockBar, AFX_IDW_DOCKBAR_TOP);
  270. }
  271. //左边树形
  272. if (!m_hleftDockBar.Create(_T("leftDockbar"), this, CSize(180,260),TRUE,123))
  273. {
  274. TRACE0("创建左侧边栏失败.\n");
  275. return -1;
  276. }
  277. m_hleftDockBar.SetBarStyle(m_hleftDockBar.GetBarStyle() |
  278. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC );
  279. m_hleftDockBar.EnableDocking (CBRS_ALIGN_ANY);
  280. DockControlBar(&m_hleftDockBar, AFX_IDW_DOCKBAR_LEFT);
  281. CString strTitle;
  282. strTitle.LoadString(IDS_TREE_TITLE);
  283. m_hleftDockBar.AddPage(&m_wndTree, strTitle, IDR_MAINFRAME);
  284. //下面通知列表
  285. if (!m_hbottomDockBar.Create(_T("bottomDockbar"), this, CSize(230,120),TRUE,123))
  286. {
  287. TRACE0("创建底部通知栏失败.\n");
  288. return -1;
  289. }
  290. m_hbottomDockBar.SetBarStyle(m_hbottomDockBar.GetBarStyle() |
  291. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC );
  292. m_hbottomDockBar.EnableDocking (CBRS_ALIGN_BOTTOM);
  293. DockControlBar(&m_hbottomDockBar, AFX_IDW_DOCKBAR_BOTTOM);
  294. CDrawObj::RegisterClass(g_strTline,RUNTIME_CLASS(CDrawTLine));
  295. CDrawObj::RegisterClass(g_strText,RUNTIME_CLASS(CDrawText));
  296. CDrawObj::RegisterClass(g_strRect,RUNTIME_CLASS(CDrawRect));
  297. CDrawObj::RegisterClass(g_strOval,RUNTIME_CLASS(CDrawOval));
  298. CDrawObj::RegisterClass(g_strButton,RUNTIME_CLASS(CDrawButton));
  299. CDrawObj::RegisterClass(g_strData,RUNTIME_CLASS(CDrawDatabox));
  300. CDrawObj::RegisterClass(g_strLed,RUNTIME_CLASS(CDraw3dCircle));
  301. CDrawObj::RegisterClass(g_strBar,RUNTIME_CLASS(CDrawBar));
  302. CDrawObj::RegisterClass(g_strCurve,RUNTIME_CLASS(CDrawCurve));
  303. CDrawObj::RegisterClass(g_strLine,RUNTIME_CLASS(CDrawLine));
  304. CDrawObj::RegisterClass(g_strBreaker,RUNTIME_CLASS(CDrawBreaker));
  305. CDrawObj::RegisterClass(g_strSwitch,RUNTIME_CLASS(CDrawSwitch));
  306. CDrawObj::RegisterClass(g_strGrid,RUNTIME_CLASS(CDrawGrid));
  307. CDrawObj::RegisterClass(g_strBitmap,RUNTIME_CLASS(CDrawBitmap));
  308. //CDrawObj::RegisterClass(g_strGif, RUNTIME_CLASS(CDrawGif));
  309. CDrawObj::RegisterClass(g_strTransfer,RUNTIME_CLASS(CDrawTransfer));
  310. CDrawObj::RegisterClass(g_strArc,RUNTIME_CLASS(CDrawArc));
  311. CDrawObj::RegisterClass(g_strArrow,RUNTIME_CLASS(CDrawArrow));
  312. CDrawObj::RegisterClass(g_strPoly,RUNTIME_CLASS(CDrawPoly));
  313. CDrawObj::RegisterClass(g_strMLine,RUNTIME_CLASS(CDrawMLine));
  314. CDrawObj::RegisterClass(g_strPipe,RUNTIME_CLASS(CDrawPipe));
  315. CDrawObj::RegisterClass(g_strZhePipe,RUNTIME_CLASS(CDrawZhePipe));
  316. CDrawObj::RegisterClass(g_strYPipe,RUNTIME_CLASS(CDrawYPipe));
  317. CDrawObj::RegisterClass(g_strWatch,RUNTIME_CLASS(CDrawWatch));
  318. CDrawObj::RegisterClass(g_strSingleBar,RUNTIME_CLASS(CDrawSingleBar));
  319. CDrawObj::RegisterClass(g_strRoundRect,RUNTIME_CLASS(CDrawRoundRect));
  320. CDrawObj::RegisterClass(g_strPie,RUNTIME_CLASS(CDrawPie));
  321. CDrawObj::RegisterClass(g_strFan,RUNTIME_CLASS(CDrawFan));
  322. CDrawObj::RegisterClass(g_strHisCurve,RUNTIME_CLASS(CDrawHisCurve));
  323. CDrawObj::RegisterClass(g_strTable,RUNTIME_CLASS(CDrawTable));
  324. CDrawObj::RegisterClass(g_strComposite,RUNTIME_CLASS(CDrawComposite));
  325. CDrawObj::RegisterClass(g_strOCX,RUNTIME_CLASS(CDrawOCX));
  326. //CDrawObj::RegisterClass(g_strGIF,RUNTIME_CLASS(CDrawGif));
  327. CDrawObj::RegisterClass(g_strFlash,RUNTIME_CLASS(CDrawFlash));
  328. LoadRunPara();
  329. ///////////////////////////////////////////////////////////////////////
  330. //MakeFolderExist( "D:\\isP-Other\\StoueULog\\" );
  331. //////////////////////////////////////////////////////////////
  332. if( g_nIsDemo == 0 )
  333. {
  334. bool bIsBoxAppear = false;
  335. for( int iPortIndex=0;iPortIndex<2;iPortIndex++ )
  336. {
  337. CString sPortTemp;
  338. sPortTemp.Format("%d",atoi(g_strServerPort)+iPortIndex );
  339. }
  340. }
  341. CRect rect1;
  342. GetWindowRect(&rect1);
  343. ScreenToClient(&rect1);
  344. if( g_nAlarmModeIsDlg && g_bStartRun )
  345. {
  346. int screenx=GetSystemMetrics(SM_CXSCREEN);
  347. int screeny=GetSystemMetrics(SM_CYSCREEN);
  348. //系统任务栏的高度
  349. HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL);
  350. RECT rc;
  351. ::GetWindowRect(hWnd, &rc);
  352. int nHeight = rc.bottom-rc.top;
  353. m_dlgControl = new CDlgBmp();
  354. m_dlgControl->Create(IDD_DIALOGCONTROL, this);
  355. m_dlgControl->ShowWindow(SW_HIDE);
  356. CRect rct1;
  357. m_dlgControl->GetWindowRect(&rct1);
  358. m_dlgControl->SetWindowPos(&wndTop, screenx-rct1.Width(), screeny-rct1.Height(), rct1.Width(), rct1.Height(), SWP_NOZORDER);
  359. }
  360. if( !g_bStartRun )
  361. {
  362. m_pDlgZuTaiAdd = new CDlg_ZuTaiAdd();
  363. m_pDlgZuTaiAdd->Create(IDD_DLG_ZUTAI_ADD, this);
  364. m_pDlgZuTaiAdd->ShowWindow(SW_HIDE);
  365. int screenx=GetSystemMetrics(SM_CXSCREEN);
  366. int screeny=GetSystemMetrics(SM_CYSCREEN);
  367. //系统任务栏的高度
  368. HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL);
  369. RECT rc;
  370. ::GetWindowRect(hWnd, &rc);
  371. int nHeight = rc.bottom-rc.top;
  372. CRect rct;
  373. m_pDlgZuTaiAdd->GetWindowRect(&rct);
  374. m_pDlgZuTaiAdd->SetWindowPos(&wndTop, (screenx-rct.Width())/2, (screeny-rct.Height())/2, rct.Width(), rct.Height(), SWP_NOZORDER);
  375. }
  376. // 初始化左边树形
  377. InitTreeInfo();
  378. int W=0,H=0;
  379. if (g_bStartRun)
  380. {
  381. if( g_nIsDemo == 0 )
  382. {
  383. // 加载脚本信息
  384. //LoadScriptFromFiles();
  385. }
  386. OnRun();
  387. }
  388. else
  389. {
  390. //LONG style=::GetWindowLong(m_hWnd,GWL_STYLE);
  391. //style&=~WS_CAPTION;
  392. //style&=~WS_BORDER;
  393. //::SetWindowLong(m_hWnd,GWL_STYLE,style);
  394. int screenx=GetSystemMetrics(SM_CXSCREEN);
  395. int screeny=GetSystemMetrics(SM_CYSCREEN);
  396. // 系统任务栏的高度;
  397. HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL);
  398. RECT rc;
  399. ::GetWindowRect(hWnd, &rc);
  400. int nHeight = rc.bottom -rc.top;
  401. printf("非全屏下计算任务栏高度:%d\n", nHeight);
  402. if( !g_bFullScreen )
  403. {
  404. W = screenx;
  405. H = screeny - nHeight;
  406. // 以屏幕尺寸的3/2来显示 [5/11/2016 IT]
  407. W /= 2;
  408. H /= 2;
  409. printf("W:%d, H:%d\n", W, H);
  410. //SetWindowPos(&wndTopMost,0,0,screenx,screeny-nHeight,SWP_NOZORDER);
  411. }
  412. else
  413. {
  414. W = screenx;
  415. H = screeny;
  416. //SetWindowPos(NULL,0,0,screenx,screeny,SWP_NOZORDER);// 全屏
  417. }
  418. }
  419. #if USE_TRAYICON
  420. m_trayIcon.SetNotificationWnd(this, WM_MY_TRAY_NOTIFICATION);
  421. m_trayIcon.SetIcon(IDR_MAINFRAME);
  422. #endif
  423. // Install the tab view here
  424. VERIFY(m_MDIClient.SubclassMDIClient(this, &m_wndViewManager));
  425. if( g_nToolbarTop )
  426. {
  427. m_wndViewManager.ShowWindow(SW_SHOW);
  428. }
  429. else
  430. {
  431. m_wndViewManager.ShowWindow(SW_HIDE);
  432. }
  433. if( g_strStartPic.Compare("") )
  434. {
  435. char picDir[_MAX_PATH] = {0};
  436. strcpy(picDir, g_strDirectory);
  437. strcat(picDir, "\\");
  438. strcat(picDir, _PICTUREDIR);
  439. strcat(picDir, g_strStartPic);
  440. strcat(picDir, ".view");
  441. AddIDEView( g_strStartPic, CString(picDir) );
  442. }
  443. if( g_nIsPoll == 1 )
  444. {
  445. SetTimer(1, 1000, NULL);
  446. }
  447. if( g_bStartRun )
  448. {
  449. ShowCaptionMenu(FALSE);
  450. }
  451. //展开树
  452. //m_wndTree.Expand(m_wndTree.GetRootItem(),TVE_EXPAND);
  453. //HTREEITEM handleTreeItem = m_wndTree.GetRootItem();
  454. //while(handleTreeItem)
  455. //{
  456. // handleTreeItem = m_wndTree.GetChildItem(handleTreeItem);
  457. // m_wndTree.Expand(handleTreeItem, TVE_EXPAND);
  458. //}
  459. MyExpandTree( m_wndTree.GetRootItem() );
  460. m_wndStatusBar.SetPaneText(2, "ver");
  461. m_wndStatusBar.SetPaneText(3, g_strVersion);
  462. if( g_bRun )
  463. SetTimer(2, 1000*15*1, NULL);//狗信息定时器
  464. //SetTimer(3, 1000*60*2, NULL);//判断变量在这个时间段时否报警
  465. if( !g_nToolbarLeft && g_bStartRun )
  466. m_hleftDockBar.ShowWindow( SW_HIDE );
  467. //m_wndDockPageBar1.OnStudClick();
  468. //通知列表
  469. if( g_nAlarmModeIsDlg && g_bRun )
  470. {
  471. m_hbottomDockBar.ShowWindow(SW_SHOW);
  472. CSize sz;
  473. sz = m_hbottomDockBar.GetHorSize();
  474. m_hbottomDockBar.OnStudClick();
  475. }
  476. else
  477. {
  478. m_hbottomDockBar.ShowWindow(SW_HIDE);
  479. }
  480. //工具栏
  481. if( g_bStartRun && g_nToolbarRun )
  482. {
  483. #if USE_NEWTOP
  484. m_pToolBar = new CDlg_ToolBar();
  485. m_pToolBar->Create(IDD_DLG_TOOLBAR, this);
  486. m_pToolBar->ShowWindow( SW_SHOW );
  487. m_htopDockBar.AddPage( m_pToolBar, "工具栏", IDR_MAINFRAME );
  488. m_htopDockBar.ShowWindow(SW_SHOW);
  489. CSize sz;
  490. sz = m_htopDockBar.GetHorSize(); // 获取顶部工具栏大小;
  491. m_pToolBar->SetPos( sz.cx,sz.cy );
  492. #else
  493. // 1.获取实际工具栏长宽 [8/29/2013 Z.t]
  494. CSize sz;
  495. sz = m_htopDockBar.GetHorSize();
  496. printf("x:%d, y:%d \n",sz.cx, sz.cy);
  497. // 2.创建工具栏上的对话框 [8/29/2013 Z.t]
  498. m_wndOfTop = new CDlgOfTop();
  499. // 3.传递对话框的大小;
  500. m_wndOfTop->_ClientSize.cx = sz.cx;
  501. m_wndOfTop->_ClientSize.cy = sz.cy;
  502. m_wndOfTop->Create(IDD_TOP, this);
  503. m_wndOfTop->ShowWindow( SW_SHOW );
  504. m_htopDockBar.AddPage( m_wndOfTop, "工具栏", IDR_MAINFRAME );
  505. m_htopDockBar.ShowWindow(SW_SHOW);
  506. //m_wndOfTop->CalcWindowRect(sz);
  507. #if 0 // 一直为1 [8/29/2013 Z.t]
  508. m_wndOfTop->MoveWindow(0,0,sz.cx,sz.cy);
  509. CRect rtOfTop;
  510. m_wndOfTop->GetWindowRect(rtOfTop);
  511. // sz,得到是运行后工具栏的实际长宽 [7/27/2013 Zero]
  512. // sy,得到是创建m_htopDockBar时的原始大小 [7/27/2013 Zero]
  513. CSize sy = m_htopDockBar.GetVerSize();
  514. //m_wndOfTop->SetPos( sz.cx,sz.cy );
  515. TRACE("--on--");
  516. #endif
  517. #endif
  518. }
  519. if( !g_bStartRun && g_nIsDemo==0 )
  520. {
  521. this->SetFocus();
  522. // 使连接服务器失败的情况下,第一时间显示在桌面;
  523. SetWindowPos(NULL,0,0,W,H,SWP_NOZORDER);
  524. CenterWindow();
  525. }
  526. else if( g_nIsDemo==1 )
  527. {
  528. printf("g_nIsDemo = 1\n");
  529. int screenx=GetSystemMetrics(SM_CXSCREEN);
  530. int screeny=GetSystemMetrics(SM_CYSCREEN);
  531. //系统任务栏的高度
  532. HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL);
  533. RECT rc;
  534. ::GetWindowRect(hWnd, &rc);
  535. int nHeight = rc.bottom-rc.top;
  536. SetWindowPos(NULL,0,0,screenx,screeny-nHeight,SWP_NOZORDER);
  537. }
  538. return 0;
  539. }
  540. void CMainFrame::MyExpandTree(HTREEITEM hTreeItem)
  541. {
  542. if(!m_wndTree.ItemHasChildren(hTreeItem))
  543. {
  544. return;
  545. }
  546. HTREEITEM hNextItem = m_wndTree.GetChildItem(hTreeItem);
  547. while (hNextItem != NULL)
  548. {
  549. MyExpandTree(hNextItem);
  550. hNextItem = m_wndTree.GetNextItem(hNextItem, TVGN_NEXT);
  551. }
  552. m_wndTree.Expand(hTreeItem,TVE_EXPAND);
  553. }
  554. DWORD WINAPI CMainFrame::ViewPollThread( void *pData )
  555. {
  556. CMainFrame *pMainFrm = (CMainFrame *)pData;
  557. DWORD dwTick = 0;
  558. do
  559. {
  560. if (g_bStartRun && g_nIsPoll == 1)
  561. {
  562. for( int i = 0; i < g_nPollCount; i++ )
  563. {
  564. if( dwTick == 0 )
  565. {
  566. if( g_nPollIndex == i )
  567. {
  568. dwTick = GetTickCount();
  569. if( pMainFrm )
  570. {
  571. //TRACE("Enter AddIDEView %s, %s\r\n", g_strPollPath, g_strPollDesc);
  572. //pMainFrm->AddIDEView(g_strPollDesc[i], g_strPollPath[i]);
  573. //TRACE("Leave AddIDEView\r\n");
  574. ((CIDEView *)pMainFrm->m_pActiveView)->ChangeView();
  575. int nIndex = pMainFrm->GetIDEViewIndex(g_strPollPath[i]);
  576. if( nIndex == -1 )
  577. {
  578. nIndex = pMainFrm->GetIDEViewFreeIndex(g_strPollPath[i]);
  579. if( nIndex == -1 ) nIndex = 0;
  580. CCreateContext context;
  581. pMainFrm->m_pViewIDE[nIndex] = new CChildFrame;
  582. pMainFrm->m_pViewIDE[nIndex]->m_strPath = g_strPollPath[i];
  583. pMainFrm->m_pViewIDE[nIndex]->m_strDesc = g_strPollDesc[i];
  584. context.m_pCurrentDoc = pMainFrm->m_pDoc;
  585. context.m_pNewDocTemplate = pMainFrm->m_pDoc->GetDocTemplate();
  586. context.m_pNewViewClass = RUNTIME_CLASS( CIDEView );
  587. context.m_pCurrentFrame = pMainFrm;
  588. context.m_pLastView = NULL;
  589. if( !pMainFrm->m_pViewIDE[nIndex]->LoadFrame(IDI_SUMMARY, WS_MAXIMIZE|WS_OVERLAPPEDWINDOW, pMainFrm, &context) )
  590. {
  591. }
  592. pMainFrm->m_pViewIDE[nIndex]->ShowWindow(SW_SHOWMAXIMIZED);
  593. pMainFrm->m_pViewIDE[nIndex]->InitialUpdateFrame(pMainFrm->m_pDoc,true);
  594. pMainFrm->m_pViewIDE[nIndex]->MDIActivate();
  595. pMainFrm->m_nViewCount++;
  596. }
  597. else
  598. {
  599. pMainFrm->m_pActiveView = (CFormView *)pMainFrm->m_pViewIDE[nIndex]->GetActiveView();
  600. pMainFrm->m_pViewIDE[nIndex]->MDIActivate();
  601. }
  602. pMainFrm->m_pViewIDE[ nIndex ]->m_bClose = FALSE;
  603. pMainFrm->m_pActiveView = (CFormView *)pMainFrm->m_pViewIDE[nIndex]->GetActiveView();
  604. g_strViewName = g_strPollPath[i];
  605. ((CIDEView *)pMainFrm->m_pActiveView)->ChangeView();
  606. }
  607. }
  608. }
  609. else if( GetTickCount() - dwTick > (DWORD)g_nPollInterval * 1000 )
  610. {
  611. if( g_nPollIndex == g_nPollCount - 1 )
  612. {
  613. g_nPollIndex = 0;
  614. }
  615. else
  616. {
  617. g_nPollIndex++;
  618. }
  619. dwTick = 0;
  620. }
  621. }
  622. }
  623. }while( WaitForSingleObject( g_hRunObject, 125L ) == WAIT_TIMEOUT );
  624. return 0;
  625. }
  626. void CMainFrame::ShowCaptionMenu(BOOL bShow)
  627. {
  628. static HMENU hMenu=NULL;
  629. if(hMenu == NULL)
  630. {
  631. hMenu=::GetMenu(this->GetSafeHwnd());
  632. }
  633. if(bShow)
  634. {
  635. ::SetMenu(this->GetSafeHwnd(),hMenu);
  636. this->ModifyStyle(0,WS_CAPTION,SWP_FRAMECHANGED);
  637. }
  638. else
  639. {
  640. ::SetMenu(this->GetSafeHwnd(),NULL);
  641. this->ModifyStyle(WS_CAPTION,0,SWP_FRAMECHANGED);
  642. }
  643. }
  644. void CMainFrame::LoadRunPara()
  645. {
  646. char Path[_MAX_PATH] = {0};
  647. strcat(Path, g_strDirectory);
  648. strcat(Path,"\\");
  649. strcat(Path, _PROJECTDIR);
  650. strcat(Path,"\\");
  651. strcat(Path, "runpara.ini");
  652. char RUN[MAX_PATH] = {0};
  653. memset(RUN, 0, sizeof(RUN));
  654. //CString str;
  655. if ( GetPrivateProfileString("RUNPARA", "STARTRUN","",RUN, 10, Path) != 0)
  656. {
  657. g_bStartRun = (RUN[0] == '1' ? true:false);
  658. }
  659. if ( GetPrivateProfileString("RUNPARA", "STARTPIC","", RUN, sizeof(RUN), Path) != 0)
  660. {
  661. g_strStartPic = RUN;
  662. }
  663. if ( GetPrivateProfileString("RUNPARA", "STARTPATH","",RUN, sizeof(RUN), Path) != 0)
  664. {
  665. g_strStartPath = RUN;
  666. }
  667. if ( GetPrivateProfileString("RUNPARA", "ALARM","",RUN, 10, Path) != 0)
  668. {
  669. g_bEventAlarm = RUN[0] == '1' ? true:false;
  670. }
  671. if ( GetPrivateProfileString("RUNPARA", "VOICE", "",RUN, 10, Path) != 0)
  672. {
  673. g_bAlarmVoice = RUN[0] == '1' ? true:false;
  674. }
  675. if ( GetPrivateProfileString("RUNPARA", "HIDETASK","",RUN, 10, Path) != 0)
  676. {
  677. g_bHideTask = RUN[0] == '1' ? true:false;
  678. }
  679. }
  680. BOOL CMainFrame::DirSearch(CString strPath, CString strFileName)
  681. {
  682. BOOL bResult = FALSE;
  683. long hDir;
  684. struct _finddata_t fDir;
  685. int nDone;
  686. strPath += "*.*";
  687. hDir = _findfirst( (char *)(LPCTSTR)strPath, &fDir );
  688. if( -1L != hDir )
  689. {
  690. while( !( nDone = _findnext(hDir, &fDir) ) )
  691. {
  692. if( !strcmp(fDir.name, "..") ) continue;
  693. if( (_A_SUBDIR == fDir.attrib) )
  694. {
  695. CString str = fDir.name;
  696. if( !str.Compare(strFileName) )
  697. {
  698. bResult = TRUE;
  699. }
  700. }
  701. }
  702. }
  703. return bResult;
  704. }
  705. int CMainFrame::GetLevel( CString sContent )
  706. {
  707. int nRet=0;
  708. for( int i=0;i<sContent.GetLength();i++ )
  709. {
  710. if( sContent[i]=='\\' )
  711. nRet++;
  712. if( sContent[i]=='[' )
  713. break;
  714. }
  715. return nRet;
  716. }
  717. CString CMainFrame::GetPreStr( CString sContent )
  718. {
  719. CString sRet;
  720. for( int i=sContent.GetLength()-1;i>=0;i-- )
  721. {
  722. if( sContent[i]=='\\' )
  723. {
  724. sRet = sContent.Left( i );
  725. break;
  726. }
  727. }
  728. return sRet;
  729. }
  730. CString CMainFrame::GetLastStr( CString sContent )
  731. {
  732. CString sRet;
  733. for( int i=sContent.GetLength()-1;i>=0;i-- )
  734. {
  735. if( sContent[i]=='\\' )
  736. {
  737. sRet = sContent.Right( sContent.GetLength()-i-1 );
  738. break;
  739. }
  740. }
  741. return sRet;
  742. }
  743. void CMainFrame::InsertToCStringArray( CStringArray &SA,int iInsertIndex,CString sContent,CString sPath )
  744. {
  745. CString str;
  746. if( sContent.Find(".view")!=-1 )
  747. sContent = sContent.Left( sContent.GetLength()-5 );
  748. CString sParent;
  749. if( m_sPath!=sPath )
  750. sParent = sPath.Right( sPath.GetLength()-m_sPath.GetLength() );
  751. if( sParent!="" )
  752. {
  753. sContent = sParent+sContent;
  754. }
  755. bool bExist=false;
  756. for( int i=0;i<SA.GetCount();i++ )
  757. {
  758. str = SA.GetAt( i );
  759. if( str==sContent )
  760. {
  761. bExist = true;
  762. break;
  763. }
  764. }
  765. if( !bExist )
  766. {
  767. int nInsert=SA.GetCount();
  768. CString s1;
  769. s1 = GetPreStr( sContent );
  770. for( int i=nInsert-1;i>=0;i-- )
  771. {
  772. str = SA.GetAt( i );
  773. if( str.Find( s1 )==0 )
  774. {
  775. nInsert = i+1;
  776. break;
  777. }
  778. }
  779. SA.InsertAt( nInsert,sContent );
  780. }
  781. }
  782. void CMainFrame::FileSearchCHN( CStringArray &SA,CStringArray &SATemp,int iInsertIndex, CString strPath, CString strFileName, int nLayer )
  783. {
  784. long hfile;
  785. struct _finddata_t fFile;
  786. CString strCurr = strPath + strFileName; // + "\\" +
  787. CString sIndex,sContent;
  788. int nDone=0;
  789. int nTime = 0;
  790. hfile = _findfirst( (char *)(LPCTSTR)strCurr, &fFile );
  791. if( -1L != hfile )
  792. {
  793. while( !( nDone = _findnext(hfile, &fFile) ) )
  794. {
  795. if( !strcmp(fFile.name,"..") ) continue;
  796. if( (_A_SUBDIR == fFile.attrib) )
  797. {
  798. strCurr = strPath + "\\" + fFile.name + "\\";
  799. int nPos = strCurr.Find("\\\\");
  800. if( nPos!=-1 )
  801. {
  802. strCurr.Delete( nPos );
  803. }
  804. CString str = fFile.name;
  805. sContent = str;
  806. InsertToCStringArray( SA,iInsertIndex,sContent,strPath );
  807. ////////////////////////////////////////////////////////////
  808. if( sContent.Find(".view")!=-1 )
  809. sContent = sContent.Left( sContent.GetLength()-5 );
  810. CString sParent;
  811. if( m_sPath!=strPath )
  812. sParent = strPath.Right( strPath.GetLength()-m_sPath.GetLength() );
  813. if( sParent!="" )
  814. {
  815. sContent = sParent+sContent;
  816. }
  817. SATemp.Add( sContent );
  818. ////////////////////////////////////////////////////////////
  819. iInsertIndex++;
  820. FileSearchCHN( SA,SATemp,iInsertIndex, strCurr, "*.*", nLayer + 1);
  821. if( g_bStartRun )
  822. {
  823. CString sPath = strCurr;
  824. int nPos = sPath.Find("*");
  825. if( nPos!=-1 )
  826. {
  827. sPath = sPath.Left( sPath.GetLength()-3 );
  828. }
  829. sPath = sPath+".view";
  830. nPos = sPath.Find("\\.");
  831. if( nPos!=-1 )
  832. {
  833. sPath.Delete( nPos );
  834. }
  835. }
  836. }
  837. else
  838. {
  839. CString str = fFile.name;
  840. if( str.Right(4).Compare("view") ) continue;
  841. CString strTemp = str.Left(str.GetLength()-5);
  842. if( !DirSearch(strPath + "\\", strTemp ) )
  843. {
  844. sContent = str;
  845. InsertToCStringArray( SA,iInsertIndex,sContent,strPath );
  846. iInsertIndex++;
  847. ////////////////////////////////////////////////////////////
  848. CString str;
  849. if( sContent.Find(".view")!=-1 )
  850. sContent = sContent.Left( sContent.GetLength()-5 );
  851. CString sParent;
  852. if( m_sPath!=strPath )
  853. sParent = strPath.Right( strPath.GetLength()-m_sPath.GetLength() );
  854. if( sParent!="" )
  855. {
  856. sContent = sParent+sContent;
  857. }
  858. SATemp.Add( sContent );
  859. ////////////////////////////////////////////////////////////
  860. }
  861. }
  862. }
  863. _findclose(hfile);
  864. }
  865. }
  866. //交换机
  867. //服务器
  868. //服务器\1号服务器
  869. //服务器\1号服务器\1号服务器
  870. //服务器\1号服务器\2号服务器
  871. //服务器\1号服务器\3号服务器
  872. //服务器\2号服务器
  873. //服务器\2号服务器\1号服务器
  874. //服务器\2号服务器\2号服务器
  875. //a
  876. void CMainFrame::AddViewToTree( HTREEITEM hItem, CStringArray &SA )
  877. {
  878. HTREEITEM hRoot;
  879. HTREEITEM hTemp[10];
  880. HTREEITEM hItemInsert=hItem;
  881. hRoot = hItem;
  882. hTemp[0] = hItem;
  883. int nSize = SA.GetCount();
  884. int nLevel1=0,nLevel2=0;
  885. CString sView,sPath,sTemp;
  886. for( int i=0;i<nSize;i++ )
  887. {
  888. sView = SA.GetAt( i );
  889. sTemp = sView;
  890. nLevel2 = GetLevel( sView );
  891. if( nLevel2==0 )
  892. hItemInsert = hRoot;
  893. else
  894. {
  895. hItemInsert = hTemp[nLevel2-1];
  896. }
  897. if( nLevel2>0 )
  898. sView = GetLastStr( sView );
  899. hItem = m_wndTree.InsertItem(sView, 1, 1, hItemInsert);
  900. hTemp[nLevel2] = hItem;
  901. if( nLevel1!=nLevel2 )
  902. nLevel1 = nLevel2;
  903. sPath = m_sPath + sTemp+".view";
  904. int nInsertIndex=0;
  905. if( !GetPicIndexByPicPath( nInsertIndex,sPath ) )
  906. {
  907. InsertPicPathToStruct( nInsertIndex,sPath );
  908. //LOG4C((LOG_NOTICE, "画面%d:%s", nInsertIndex,sPath));
  909. }
  910. }
  911. }
  912. void CMainFrame::FileSearch(HTREEITEM hItem, CString strPath, CString strFileName, int nLayer)
  913. {
  914. long hfile;
  915. struct _finddata_t fFile;
  916. CString strCurr = strPath + strFileName; // + "\\" +
  917. HTREEITEM hTemp = hItem;
  918. int nDone=0;
  919. int nTime = 0;
  920. hfile = _findfirst( (char *)(LPCTSTR)strCurr, &fFile );
  921. if( -1L != hfile )
  922. {
  923. while( !( nDone = _findnext(hfile, &fFile) ) )
  924. {
  925. if( !strcmp(fFile.name,"..") ) continue;
  926. if( (_A_SUBDIR == fFile.attrib) )
  927. {
  928. strCurr = strPath + "\\" + fFile.name + "\\";
  929. int nPos = strCurr.Find("\\\\");
  930. if( nPos!=-1 )
  931. {
  932. strCurr.Delete( nPos );
  933. }
  934. CString str = fFile.name;
  935. HTREEITEM hReturn = hItem;
  936. hItem = m_wndTree.InsertItem(str, 1, 1, hItem);
  937. FileSearch(hItem, strCurr, "*.*", nLayer + 1);
  938. hItem = hReturn;
  939. if( g_bStartRun )
  940. {
  941. CString sPath = strCurr;
  942. int nPos = sPath.Find("*");
  943. if( nPos!=-1 )
  944. {
  945. sPath = sPath.Left( sPath.GetLength()-3 );
  946. }
  947. sPath = sPath+".view";
  948. nPos = sPath.Find("\\.");
  949. if( nPos!=-1 )
  950. {
  951. sPath.Delete( nPos );
  952. }
  953. int nInsertIndex=0;
  954. if( !GetPicIndexByPicPath( nInsertIndex,sPath ) )
  955. {
  956. InsertPicPathToStruct( nInsertIndex,sPath );
  957. //LOG4C((LOG_NOTICE, "画面%d:%s", nInsertIndex,sPath));
  958. }
  959. }
  960. }
  961. else
  962. {
  963. CString str = fFile.name;
  964. if( str.Right(4).Compare("view") ) continue;
  965. CString strTemp = str.Left(str.GetLength()-5);
  966. if( !DirSearch(strPath + "\\", strTemp ) )
  967. {
  968. m_wndTree.InsertItem(strTemp, 1, 1, hTemp);
  969. }
  970. //m_wndTree.SortChildren( hItem );
  971. if( g_bStartRun )
  972. {
  973. CString sPath = strPath;
  974. int nPos = sPath.Find("*");
  975. if( nPos!=-1 )
  976. {
  977. sPath = sPath.Left( sPath.GetLength()-3 );
  978. }
  979. sPath = sPath+strTemp+".view";
  980. int nInsertIndex=0;
  981. if( !GetPicIndexByPicPath( nInsertIndex,sPath ) )
  982. {
  983. InsertPicPathToStruct( nInsertIndex,sPath );
  984. //LOG4C((LOG_NOTICE, "画面%d:%s", nInsertIndex,sPath));
  985. }
  986. }
  987. }
  988. }
  989. _findclose(hfile);
  990. }
  991. }
  992. // 删除目录
  993. void CMainFrame::DeleteDirectory(CString strDir)
  994. {
  995. if(strDir.IsEmpty())
  996. {
  997. RemoveDirectory(strDir);
  998. return;
  999. }
  1000. // 首先删除文件及子文件夹
  1001. CFileFind ff;
  1002. BOOL bFound = ff.FindFile(strDir+"\\*", 0);
  1003. while(bFound)
  1004. {
  1005. bFound = ff.FindNextFile();
  1006. if(ff.GetFileName()=="."||ff.GetFileName()=="..") continue;
  1007. // 去掉文件(夹)只读等属性
  1008. SetFileAttributes(ff.GetFilePath(), FILE_ATTRIBUTE_NORMAL);
  1009. if(ff.IsDirectory())
  1010. {
  1011. // 递归删除子文件夹
  1012. DeleteDirectory(ff.GetFilePath());
  1013. RemoveDirectory(ff.GetFilePath());
  1014. }
  1015. else
  1016. {
  1017. DeleteFile(ff.GetFilePath()); // 删除文件
  1018. }
  1019. }
  1020. ff.Close();
  1021. // 然后删除该文件夹
  1022. if (!RemoveDirectory(strDir))
  1023. {
  1024. //ff.Close();
  1025. //Sleep( 1000 );
  1026. RemoveDirectory(strDir);
  1027. }
  1028. }
  1029. void CMainFrame::InitTreeInfo(void)
  1030. {
  1031. m_wndTree.SetItemHeight(20);
  1032. m_wndImageList.DeleteImageList();
  1033. m_wndImageList.Create(IDB_LEFT, 16, 1, RGB(255, 0, 255));
  1034. m_wndTree.SetImageList(&m_wndImageList, LVSIL_NORMAL);
  1035. m_wndTree.SetBkColor( RGB(230,241,249) );
  1036. m_wndTree.DeleteAllItems();
  1037. m_hMonitor = m_wndTree.InsertItem(g_strMoniterSite,0,0);
  1038. //显示画面
  1039. CString strFindPicFile = "*.view";
  1040. char szPicDir[MAX_PATH] = {0};
  1041. strcpy(szPicDir, g_strDirectory);
  1042. strcat(szPicDir, "\\");
  1043. strcat(szPicDir, _PICTUREDIR);
  1044. m_sPath.Format( "%s",szPicDir );
  1045. //FileSearch(m_hMonitor, szPicDir, "*.*", 0);
  1046. ///////////////////////
  1047. strcpy(szPicDir, g_strDirectory);
  1048. strcat(szPicDir, "\\");
  1049. strcat(szPicDir, _PICTUREDIR);
  1050. strcat(szPicDir, "sort.txt");
  1051. CStringArray SA,SATemp;
  1052. if( PathFileExists( szPicDir ) )
  1053. {
  1054. CString sTemp,strTemp1,strTemp2,sTemp2;
  1055. CStdioFile File;
  1056. if(!File.Open(szPicDir,CFile::modeRead))
  1057. File.Open(szPicDir,CFile::modeCreate|CFile::modeRead);
  1058. while(File.ReadString(sTemp))
  1059. {
  1060. SA.Add( sTemp );
  1061. }
  1062. File.Close();
  1063. }
  1064. strcpy(szPicDir, g_strDirectory);
  1065. strcat(szPicDir, "\\");
  1066. strcat(szPicDir, _PICTUREDIR);
  1067. FileSearchCHN( SA,SATemp,0, szPicDir, "*.*", 0);
  1068. CString sShow,s;
  1069. for( int i=0;i<SA.GetCount();i++ )
  1070. {
  1071. s = SA.GetAt( i );
  1072. sShow = sShow + s + "\n";
  1073. }
  1074. //AfxMessageBox( sShow );
  1075. bool bExist=false;
  1076. int nSize1=SA.GetCount();
  1077. int nSize2=SATemp.GetCount();
  1078. CString str1,str2;
  1079. for( int i=nSize1-1;i>=0;i-- )
  1080. {
  1081. str1 = SA.GetAt(i);
  1082. for( int j=0;j<nSize2;j++ )
  1083. {
  1084. str2 = SATemp.GetAt(j);
  1085. if( str1==str2 )
  1086. {
  1087. bExist = true;
  1088. break;
  1089. }
  1090. }
  1091. if( !bExist )
  1092. SA.RemoveAt( i );
  1093. bExist = false;
  1094. }
  1095. AddViewToTree( m_hMonitor,SA );
  1096. ///////////////////////
  1097. //m_wndTree.SortChildren( m_hMonitor );
  1098. }
  1099. void CMainFrame::OnFullScreen()
  1100. {
  1101. GetWindowPlacement(&m_OldWndPlacement);
  1102. CRect WindowRect;
  1103. GetWindowRect(&WindowRect);
  1104. CRect ClientRect;
  1105. RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery, &ClientRect);
  1106. ClientToScreen(&ClientRect);// 获取屏幕的分辨率
  1107. int nFullWidth=GetSystemMetrics(SM_CXSCREEN);
  1108. int nFullHeight=GetSystemMetrics(SM_CYSCREEN);// 将除控制条外的客户区全屏显示到从(0,0)到(nFullWidth, nFullHeight)区
  1109. //域, 将(0,0)和(nFullWidth, nFullHeight)两个点外扩充原窗口和除控制条之外的 客
  1110. //户区位置间的差值, 就得到全屏显示的窗口位置
  1111. m_FullScreenRect.left=0;//WindowRect.left-ClientRect.left-1;
  1112. m_FullScreenRect.top=0;//WindowRect.top-ClientRect.top-1;
  1113. m_FullScreenRect.right=WindowRect.right-ClientRect.right+nFullWidth+2;
  1114. m_FullScreenRect.bottom=nFullHeight;//WindowRect.bottom-ClientRect.bottom+nFullHeight+2;
  1115. // 进入全屏显示状态
  1116. WINDOWPLACEMENT wndpl;
  1117. wndpl.length=sizeof(WINDOWPLACEMENT);
  1118. wndpl.flags=0;
  1119. wndpl.showCmd=SW_SHOWNORMAL;
  1120. wndpl.rcNormalPosition=m_FullScreenRect;
  1121. SetWindowPlacement(&wndpl);
  1122. }
  1123. void CMainFrame::OnRun()
  1124. {
  1125. g_bRun = TRUE; //运行否
  1126. g_bEdit = FALSE; //编辑否
  1127. CDrawObj::bRuning = TRUE;
  1128. m_wndToolBar.ShowWindow(SW_HIDE);
  1129. m_wndDrawToolBar.ShowWindow(SW_HIDE);
  1130. m_wndDrawAlignBar.ShowWindow(SW_HIDE);
  1131. //if( g_nToolbarRun )//&& !g_bFullScreen )
  1132. //{
  1133. // m_wndRunToolBar.ShowWindow(SW_SHOW);
  1134. //}
  1135. //else
  1136. //{
  1137. // m_wndRunToolBar.ShowWindow(SW_HIDE);
  1138. //}
  1139. RecalcLayout();
  1140. if( g_nToolBarStatus )//&& !g_bFullScreen )
  1141. {
  1142. m_wndStatusBar.ShowWindow(SW_SHOW);
  1143. }
  1144. else
  1145. {
  1146. m_wndStatusBar.ShowWindow(SW_HIDE);
  1147. }
  1148. m_hleftDockBar.ShowWindow(SW_SHOW);
  1149. //if( g_nToolbarLeft )
  1150. //{
  1151. // m_wndDockPageBar1.ShowWindow(SW_SHOW);
  1152. //}
  1153. //else
  1154. //{
  1155. // m_wndDockPageBar1.ShowWindow(SW_HIDE);
  1156. //}
  1157. if ( g_bHideTask )
  1158. {
  1159. HWND wnd = ::FindWindow("Shell_TrayWnd", NULL);
  1160. ::ShowWindow(wnd, SW_HIDE);
  1161. }
  1162. //else
  1163. //{
  1164. // HWND wnd = ::FindWindow("Shell_TrayWnd", NULL);
  1165. // ::ShowWindow(wnd, SW_SHOW);
  1166. //}
  1167. LONG style=::GetWindowLong(m_hWnd,GWL_STYLE);
  1168. style&=~WS_CAPTION;
  1169. style&=~WS_BORDER;
  1170. ::SetWindowLong(m_hWnd,GWL_STYLE,style);
  1171. int screenx=GetSystemMetrics(SM_CXSCREEN);
  1172. int screeny=GetSystemMetrics(SM_CYSCREEN);
  1173. //系统任务栏的高度
  1174. HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL);
  1175. RECT rc;
  1176. ::GetWindowRect(hWnd, &rc);
  1177. int nHeight = rc.bottom-rc.top;
  1178. if( g_nIsDemo == 0 )
  1179. {
  1180. if(!g_bFullScreen)
  1181. {
  1182. SetWindowPos(NULL,0,0,screenx,screeny-nHeight,SWP_NOZORDER);
  1183. }
  1184. else
  1185. {
  1186. SetWindowPos(NULL,0,0,screenx,screeny+0,SWP_FRAMECHANGED);//关于全屏
  1187. }
  1188. }
  1189. SetMenu((CMenu*)NULL);
  1190. }
  1191. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  1192. {
  1193. if( !CMDIFrameWnd::PreCreateWindow(cs) )
  1194. return FALSE;
  1195. // TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或
  1196. // 样式
  1197. if (!g_bStartRun)
  1198. {
  1199. cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
  1200. | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;
  1201. }
  1202. else
  1203. {
  1204. cs.style=WS_OVERLAPPED | WS_SYSMENU |WS_MINIMIZEBOX |WS_TILED ;
  1205. }
  1206. return TRUE;
  1207. }
  1208. // CMainFrame 诊断
  1209. #ifdef _DEBUG
  1210. void CMainFrame::AssertValid() const
  1211. {
  1212. CMDIFrameWnd::AssertValid();
  1213. }
  1214. void CMainFrame::Dump(CDumpContext& dc) const
  1215. {
  1216. CMDIFrameWnd::Dump(dc);
  1217. }
  1218. #endif //_DEBUG
  1219. // CMainFrame 消息处理程序
  1220. void CMainFrame::OnSuperEnd()
  1221. {
  1222. // TODO: 在此添加命令处理程序代码
  1223. m_bShutdown = TRUE; // really exit
  1224. SendMessage(WM_CLOSE);
  1225. }
  1226. void CMainFrame::OnTrayOpen()
  1227. {
  1228. // TODO: 在此添加命令处理程序代码
  1229. ShowWindow(SW_MAXIMIZE);
  1230. SetForegroundWindow();
  1231. }
  1232. void CMainFrame::OnClose()
  1233. {
  1234. // TODO: 在此添加消息处理程序代码和/或调用默认值
  1235. #if USE_TRAYICON
  1236. #else
  1237. m_bShutdown = TRUE;
  1238. #endif
  1239. if( m_bShutdown )
  1240. {
  1241. if( g_nIsDemo == 1 )
  1242. {
  1243. if(MessageBox(g_strExitConfirm, g_strTip, MB_YESNO|MB_ICONQUESTION)==IDNO)
  1244. {
  1245. return;
  1246. }
  1247. }
  1248. #if 0 // 暂时不使用登陆框 [8/29/2013 hero]
  1249. else
  1250. {
  1251. CLogin dlg;
  1252. dlg.m_bShutdown = true;
  1253. if (dlg.DoModal()!=IDOK)
  1254. {
  1255. m_bShutdown = false;
  1256. return;
  1257. }
  1258. CString sContent;
  1259. sContent.Format("用戶< %s >注销",dlg.m_sUserID );
  1260. CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_LOGOUT,0,"",(char *)(LPCTSTR)sContent );
  1261. }
  1262. #endif
  1263. if (g_bRun )
  1264. {
  1265. }
  1266. if( m_pDlgZuTaiAdd )
  1267. {
  1268. delete m_pDlgZuTaiAdd;
  1269. m_pDlgZuTaiAdd = NULL ;
  1270. }
  1271. int i;
  1272. for( i = 0; i < MAX_VIEW_NUM; i++ )
  1273. {
  1274. if( m_pViewIDE[ i ] )
  1275. {
  1276. ::SendMessage(m_pViewIDE[ i ]->m_hWnd, WM_CLOSE, 0, 0 );
  1277. m_pViewIDE[ i ] = NULL;
  1278. }
  1279. }
  1280. #if USE_NEWTOP
  1281. if( g_bRun && g_nToolbarRun )
  1282. {
  1283. if( m_pToolBar )
  1284. delete m_pToolBar;
  1285. m_pToolBar = NULL ;
  1286. }
  1287. #else
  1288. if( g_bRun && g_nToolbarRun )
  1289. {
  1290. if( m_wndOfTop )
  1291. delete m_wndOfTop;
  1292. m_wndOfTop = NULL ;
  1293. }
  1294. #endif
  1295. CMDIAutoHideFrame::OnClose();
  1296. }
  1297. else
  1298. {
  1299. ShowWindow(SW_HIDE);
  1300. }
  1301. }
  1302. void CMainFrame::OnDestroy()
  1303. {
  1304. if( g_nIsPoll == 1 )
  1305. {
  1306. #if VIEW_USE_THREAD
  1307. if( m_hViewPollThread != NULL )
  1308. {
  1309. MTVERIFY( WaitForSingleObject( m_hViewPollThread, INFINITE ) != WAIT_FAILED );
  1310. MTVERIFY( CloseHandle( m_hViewPollThread ) );
  1311. m_hViewPollThread = NULL;
  1312. }
  1313. #else
  1314. KillTimer(1);
  1315. #endif
  1316. }
  1317. CMDIAutoHideFrame::OnDestroy();
  1318. // TODO: 在此处添加消息处理程序代码
  1319. int i;
  1320. for( i = 0; i < MAX_VIEW_NUM; i++ )
  1321. {
  1322. if( m_pViewIDE[ i ] )
  1323. {
  1324. ::SendMessage(m_pViewIDE[ i ]->m_hWnd, WM_DESTROY, 0, 0 );
  1325. m_pViewIDE[ i ] = NULL;
  1326. }
  1327. }
  1328. }
  1329. BOOL CMainFrame::FindTreeItem(HTREEITEM hSrcItem, HTREEITEM hDestItem)
  1330. {
  1331. HTREEITEM hItem = m_wndTree.GetParentItem( hSrcItem );
  1332. while( hItem != NULL )
  1333. {
  1334. if( hItem == hDestItem ) return TRUE;
  1335. hItem = m_wndTree.GetParentItem( hItem );
  1336. }
  1337. return FALSE;
  1338. }
  1339. int CMainFrame::ShowDevProperty(HTREEITEM hSelectedItem)
  1340. {
  1341. CString strOldUid, strNewUid;
  1342. int i, j;
  1343. int nChannelIndex = -1, nDeviceIndex = -1;
  1344. Invalidate(FALSE);
  1345. return 0;
  1346. }
  1347. bool CMainFrame::ShowView(void)
  1348. {
  1349. HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
  1350. HTREEITEM hItem;
  1351. int i;
  1352. m_hCurrent = hSelectedItem;
  1353. //如果是视图
  1354. char szPicDir[MAX_PATH] = {0};
  1355. CString strTempDir = "", strPicFile;
  1356. strcpy(szPicDir, g_strDirectory);
  1357. strcat(szPicDir, "\\");
  1358. strcat(szPicDir, _PICTUREDIR);
  1359. hItem = m_wndTree.GetParentItem( hSelectedItem );
  1360. while( hItem != NULL )
  1361. {
  1362. if( hItem == m_hMonitor )
  1363. {
  1364. CString strSelect = m_wndTree.GetItemText( hSelectedItem );
  1365. if( !strTempDir.Compare("") )
  1366. {
  1367. strPicFile += strSelect;
  1368. }
  1369. else
  1370. {
  1371. strPicFile += strTempDir;
  1372. //strPicFile += "\\";//chn modify 12.28
  1373. strPicFile += strSelect;
  1374. }
  1375. AddIDEView( strSelect, CString(szPicDir) + strPicFile + ".view" );
  1376. return true;
  1377. }
  1378. else
  1379. {
  1380. CString str = m_wndTree.GetItemText( hItem );
  1381. strTempDir = str + "\\" + strTempDir;
  1382. hItem = m_wndTree.GetParentItem( hItem );
  1383. }
  1384. }
  1385. // 如果是脚本
  1386. for (i = 0; i < MAX_SCRIPT_NUM; i++)
  1387. {
  1388. if (m_hScriptGroup[i] == hSelectedItem)
  1389. {
  1390. CString scriptFile;
  1391. scriptFile = _SCRIPTDIR;
  1392. scriptFile = g_strDirectory + CString("\\") + scriptFile + m_wndTree.GetItemText(hSelectedItem) + ".srp";
  1393. CString strScript;
  1394. strScript.Format("%s\\ScriptEdit.exe", g_strDirectory);
  1395. ShellExecute(NULL,"open", (char *)(LPCTSTR)strScript, scriptFile, NULL, SW_SHOWNORMAL);
  1396. return true;
  1397. }
  1398. }
  1399. // 系统参数
  1400. if (hSelectedItem == m_hSystem)
  1401. {
  1402. SetRunPara();
  1403. }
  1404. // 变量编辑
  1405. else if (m_hAnalog == hSelectedItem)
  1406. {
  1407. }
  1408. else // 设备属性设置xs
  1409. {
  1410. if( g_nIsDemo == 0 )
  1411. {
  1412. int nRet = ShowDevProperty(hSelectedItem);
  1413. if( nRet == 1 )
  1414. {
  1415. if( hSelectedItem )
  1416. {
  1417. // 这里一删除就报异常,只能先注释,待解决 for Jesse 100106
  1418. //m_wndTree.DeleteItem( m_hCurrent );//hSelectedItem
  1419. }
  1420. }
  1421. }
  1422. }
  1423. return true;
  1424. }
  1425. BOOL CMainFrame::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  1426. {
  1427. // TODO: 在此添加专用代码和/或调用基类
  1428. LPNMHDR pNmhdr = (LPNMHDR)lParam;
  1429. int i, j;
  1430. //if( m_bShutdown ) return FALSE; //chn dele
  1431. int idCtrl = LOWORD(wParam);
  1432. if( idCtrl == IDD_TREE_LEFT ) // Is my tree's id?
  1433. {
  1434. CPoint point;
  1435. ::GetCursorPos(&point);
  1436. m_wndTree.ScreenToClient(&point);
  1437. switch( pNmhdr->code )
  1438. {
  1439. case NM_CLICK:
  1440. {
  1441. // Get Click item's
  1442. UINT uFlags;
  1443. HTREEITEM hItem = m_wndTree.HitTest(point, &uFlags);
  1444. if((hItem != NULL) && (TVHT_ONITEM & uFlags))
  1445. {
  1446. m_wndTree.SelectItem(hItem);
  1447. }
  1448. return true;//Already process the notify
  1449. }
  1450. case NM_RCLICK:
  1451. {
  1452. // Get RightClick item's
  1453. if( g_bStartRun ) return true;
  1454. UINT uFlags;
  1455. HTREEITEM hItem = m_wndTree.HitTest(point, &uFlags);
  1456. m_wndTree.SelectItem(hItem);
  1457. if((hItem != NULL) && (TVHT_ONITEM & uFlags))
  1458. {
  1459. GetCursorPos(&m_mousePoint);
  1460. HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
  1461. //新建设备
  1462. if( hSelectedItem == m_hIOGroup )
  1463. {
  1464. CMenu menu;
  1465. menu.LoadMenu(IDR_MENU_ADDDEVICE);
  1466. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
  1467. }
  1468. //删除设备
  1469. int nChannelIndex = -1, nDeviceIndex = -1;
  1470. int nChannelSize = 0;//pDevicesManager->m_channels.GetSize();
  1471. // 串口设备属性设置
  1472. for (i = 0; i < nChannelSize; i++)
  1473. {
  1474. #if 0 // 删除COM时有BUG,待解决 for Jesse 091104
  1475. if( m_hSerialGroup[i] == hSelectedItem )
  1476. {
  1477. CMenu menu;
  1478. menu.LoadMenu(IDR_MENU_DELDEVICE);
  1479. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
  1480. return true;
  1481. }
  1482. #endif
  1483. int nDeviceSize = 0;//pDevicesManager->m_channels[i]->m_Devices.GetSize();
  1484. for( j = 0; j < nDeviceSize; j++)
  1485. {
  1486. if (m_hSerialDev[i][j]==hSelectedItem)
  1487. {
  1488. CMenu menu;
  1489. menu.LoadMenu(IDR_MENU_DELDEVICE);
  1490. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
  1491. return true;
  1492. }
  1493. if( m_hNetworkDev[j] == hSelectedItem )
  1494. {
  1495. CMenu menu;
  1496. menu.LoadMenu(IDR_MENU_DELDEVICE);
  1497. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
  1498. return true;
  1499. }
  1500. }
  1501. }
  1502. //新建或删除监控画面
  1503. if (hSelectedItem == m_hMonitor)
  1504. {
  1505. CMenu menu;
  1506. menu.LoadMenu(IDR_MENU_ADDVIEW);
  1507. menu.GetSubMenu(1)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
  1508. }
  1509. else
  1510. {
  1511. if( FindTreeItem( hSelectedItem, m_hMonitor ) )
  1512. {
  1513. CMenu menu;
  1514. menu.LoadMenu(IDR_MENU_ADDVIEW);
  1515. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
  1516. }
  1517. }
  1518. //设定脚本
  1519. for (i = 0; i < MAX_SCRIPT_NUM; i++)
  1520. {
  1521. if (m_hScriptGroup[i] == hSelectedItem)
  1522. {
  1523. CMenu menu;
  1524. menu.LoadMenu(IDR_MENU_SETSCRIPT);
  1525. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
  1526. }
  1527. }
  1528. //新建脚本
  1529. if (hSelectedItem == m_hScript)
  1530. {
  1531. CMenu menu;
  1532. menu.LoadMenu(IDR_MENU_ADDSCRIPT);
  1533. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this);
  1534. }
  1535. }
  1536. return true;//Already process the notify
  1537. }
  1538. case NM_DBLCLK:
  1539. {
  1540. ShowView();
  1541. return true;
  1542. }
  1543. }
  1544. return false; // no match
  1545. }
  1546. return CMDIAutoHideFrame::OnNotify(wParam, lParam, pResult);
  1547. }
  1548. int CMainFrame::GetFreeSerialTreeItem()
  1549. {
  1550. CString str;
  1551. #if 1
  1552. for( int i = MAX_SERIAL_NUM-1; i >=0 ; i-- )
  1553. {
  1554. //if( m_hSerialGroup[i] == NULL ) break;
  1555. str = m_wndTree.GetItemText(m_hSerialGroup[i]);
  1556. if( str.Compare("") )
  1557. {
  1558. return i+1;
  1559. }
  1560. }
  1561. #else
  1562. for( int i = 0; i < MAX_SERIAL_NUM; i++ )
  1563. {
  1564. //if( m_hSerialGroup[i] == NULL ) break;
  1565. str = m_wndTree.GetItemText(m_hSerialGroup[i]);
  1566. if( !str.Compare("") )
  1567. {
  1568. return i;
  1569. }
  1570. }
  1571. #endif
  1572. return 0;
  1573. }
  1574. int CMainFrame::GetNetworkChannelIndex()
  1575. {
  1576. return -1;
  1577. }
  1578. int CMainFrame::GetFreeNetworkTreeItem()
  1579. {
  1580. CString str;
  1581. for( int i = 0; i < MAX_NETWORK_NUM; i++ )
  1582. {
  1583. //if( m_hNetworkDev[i] == NULL ) break;
  1584. str = m_wndTree.GetItemText(m_hNetworkDev[i]);
  1585. if( !str.Compare("") )
  1586. {
  1587. return i;
  1588. }
  1589. }
  1590. return -1;
  1591. }
  1592. int CMainFrame::GetIndexSerialTreeItem(CString strSrc)
  1593. {
  1594. CString str;
  1595. for( int i = 0; i < MAX_SERIAL_NUM; i++ )
  1596. {
  1597. //if( m_hSerialGroup[i] == NULL ) break;
  1598. str = m_wndTree.GetItemText(m_hSerialGroup[i]);
  1599. if( !str.Compare(strSrc) )
  1600. {
  1601. return i;
  1602. }
  1603. }
  1604. return -1;
  1605. }
  1606. int CMainFrame::GetIndexNetworkTreeItem(CString strSrc)
  1607. {
  1608. CString str;
  1609. for( int i = 0; i < MAX_NETWORK_NUM; i++ )
  1610. {
  1611. //if( m_hNetworkDev[i] == NULL ) break;
  1612. str = m_wndTree.GetItemText(m_hNetworkDev[i]);
  1613. if( !str.Compare(strSrc) )
  1614. {
  1615. return i;
  1616. }
  1617. }
  1618. return -1;
  1619. }
  1620. int CMainFrame::FinishedAddDevice(int nIsDelete, CString strUid)
  1621. {
  1622. return 1;
  1623. }
  1624. void CMainFrame::AddDevice()
  1625. {
  1626. }
  1627. void CMainFrame::OnAdddevoce()
  1628. {
  1629. // TODO: 在此添加命令处理程序代码
  1630. AddDevice();
  1631. }
  1632. void CMainFrame::OnUpdateAdddevoce(CCmdUI *pCmdUI)
  1633. {
  1634. // TODO: 在此添加命令更新用户界面处理程序代码
  1635. }
  1636. void CMainFrame::OnZuTaiAdd()
  1637. {
  1638. if( !m_pDlgZuTaiAdd->m_bIsExistExcel )
  1639. {
  1640. MessageBox( "没有安装Excel软件,组态功能不能用!","提示" );
  1641. return;
  1642. }
  1643. CDlg_Pwd Dlg_Pwd;
  1644. Dlg_Pwd.m_nShowType = 2;
  1645. if( Dlg_Pwd.DoModal()!=IDOK )
  1646. return;
  1647. m_pDlgZuTaiAdd->ReadResource();
  1648. m_pDlgZuTaiAdd->ShowWindow( SW_SHOW );
  1649. }
  1650. void CMainFrame::OnUpdateZuTaiAdd(CCmdUI *pCmdUI)
  1651. {
  1652. }
  1653. void CMainFrame::OnDeleteport()
  1654. {
  1655. // TODO: 在此添加命令处理程序代码
  1656. }
  1657. void CMainFrame::OnUpdateDeleteport(CCmdUI *pCmdUI)
  1658. {
  1659. // TODO: 在此添加命令更新用户界面处理程序代码
  1660. }
  1661. void CMainFrame::OnAddPort()
  1662. {
  1663. // TODO: 在此添加命令处理程序代码
  1664. }
  1665. void CMainFrame::OnUpdateAddPort(CCmdUI *pCmdUI)
  1666. {
  1667. // TODO: 在此添加命令更新用户界面处理程序代码
  1668. }
  1669. void CMainFrame::OnAddScript()
  1670. {
  1671. // TODO: 在此添加命令处理程序代码
  1672. }
  1673. void CMainFrame::OnUpdateAddScript(CCmdUI *pCmdUI)
  1674. {
  1675. // TODO: 在此添加命令更新用户界面处理程序代码
  1676. }
  1677. void CMainFrame::HideRunBar()
  1678. {
  1679. //m_wndRunToolBar.ShowWindow(SW_HIDE);
  1680. }
  1681. void CMainFrame::OnAddview()
  1682. {
  1683. // TODO: 在此添加命令处理程序代码
  1684. CViewNameDlg dlg;
  1685. if (dlg.DoModal() == IDOK)
  1686. {
  1687. if( dlg.m_strViewName.Compare("")==0 )
  1688. {
  1689. MessageBox(g_strMonitorNameIsBlank, g_strTip, MB_ICONINFORMATION);
  1690. return;
  1691. }
  1692. char szPicDir[MAX_PATH] = {0};
  1693. CString strTempDir = "";
  1694. strcpy(szPicDir, g_strDirectory);
  1695. strcat(szPicDir, "\\");
  1696. strcat(szPicDir, _PICTUREDIR);
  1697. int cx=GetSystemMetrics(SM_CXSCREEN)-10;
  1698. int cy=GetSystemMetrics(SM_CYSCREEN)-100;
  1699. CGraph* pic=new CGraph(CSize(cx, cy));
  1700. pic->m_strPicFile = CString(szPicDir);
  1701. HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
  1702. HTREEITEM hItem;
  1703. m_wndTree.InsertItem(dlg.m_strViewName, 1, 1, hSelectedItem);
  1704. if( hSelectedItem == m_hMonitor )
  1705. {
  1706. pic->m_strPicFile = pic->m_strPicFile + dlg.m_strViewName + ".view";
  1707. pic->Store();
  1708. }
  1709. else
  1710. {
  1711. hItem = m_wndTree.GetParentItem( hSelectedItem );
  1712. while( hItem != NULL )
  1713. {
  1714. if( hItem == m_hMonitor )
  1715. {
  1716. CString strSelect = m_wndTree.GetItemText( hSelectedItem );
  1717. if( !strTempDir.Compare("") )
  1718. {
  1719. pic->m_strPicFile += strSelect;
  1720. }
  1721. else
  1722. {
  1723. pic->m_strPicFile += strTempDir;
  1724. pic->m_strPicFile += "\\";
  1725. pic->m_strPicFile += strSelect;
  1726. }
  1727. if( !PathFileExists(pic->m_strPicFile) )
  1728. {
  1729. SECURITY_ATTRIBUTES sa;
  1730. sa.nLength = sizeof(SECURITY_ATTRIBUTES);
  1731. sa.lpSecurityDescriptor = NULL;
  1732. sa.bInheritHandle = 0;
  1733. int nRet = CreateDirectory(pic->m_strPicFile, &sa);
  1734. if( !nRet )
  1735. {
  1736. MessageBox(g_strCannotCreateDirecitory,g_strTip,MB_ICONWARNING);
  1737. delete pic;
  1738. return;
  1739. }
  1740. }
  1741. pic->m_strPicFile = pic->m_strPicFile + "\\" + dlg.m_strViewName + ".view";
  1742. pic->Store();
  1743. delete pic;
  1744. return;
  1745. }
  1746. else
  1747. {
  1748. CString str = m_wndTree.GetItemText( hItem );
  1749. strTempDir = str + "\\" + strTempDir;
  1750. hItem = m_wndTree.GetParentItem( hItem );
  1751. }
  1752. }
  1753. }
  1754. delete pic;
  1755. CString sContent;
  1756. sContent.Format("添加画面< %s >",dlg.m_strViewName.TrimRight() );
  1757. //CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_MONITOR_ADD,0,"",(char *)(LPCTSTR)sContent );
  1758. }
  1759. }
  1760. void CMainFrame::OnAddview2()
  1761. {
  1762. OnAddview();
  1763. }
  1764. void CMainFrame::OnUpdateAddview(CCmdUI *pCmdUI)
  1765. {
  1766. // TODO: 在此添加命令更新用户界面处理程序代码
  1767. }
  1768. void CMainFrame::OnEditSort()
  1769. {
  1770. CDlg_EditView dlg;
  1771. dlg.DoModal();
  1772. }
  1773. void CMainFrame::OnUpdateEditSort(CCmdUI *pCmdUI)
  1774. {
  1775. // TODO: 在此添加命令更新用户界面处理程序代码
  1776. }
  1777. void CMainFrame::OnUpdateAddview2(CCmdUI *pCmdUI)
  1778. {
  1779. // TODO: 在此添加命令更新用户界面处理程序代码
  1780. }
  1781. void CMainFrame::DeleteDev(int nIsHint)
  1782. {
  1783. }
  1784. void CMainFrame::OnDeletedevice()
  1785. {
  1786. // TODO: 在此添加命令处理程序代码
  1787. DeleteDev(1);
  1788. }
  1789. void CMainFrame::OnUpdateDeletedevice(CCmdUI *pCmdUI)
  1790. {
  1791. // TODO: 在此添加命令更新用户界面处理程序代码
  1792. pCmdUI->Enable(TRUE);
  1793. }
  1794. void CMainFrame::OnDeleteview()
  1795. {
  1796. // TODO: 在此添加命令处理程序代码
  1797. //删除文件,同时再数状控件中删除
  1798. CString strPath, strTemp;
  1799. CString strPathFile,strPathFolder;
  1800. HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
  1801. if( m_hMonitor==hSelectedItem )
  1802. {
  1803. MessageBox(g_strMonitorNameCannotDel, g_strTip, MB_ICONINFORMATION);
  1804. return;
  1805. }
  1806. CString strSelect = m_wndTree.GetItemText( hSelectedItem );
  1807. CString strMessage;
  1808. strMessage.Format(g_strDelView,strSelect);
  1809. if (MessageBox(strMessage,g_strConfirm,MB_YESNO|MB_ICONQUESTION) == IDNO)
  1810. return;
  1811. GetPicPathByTree( hSelectedItem,strTemp );
  1812. strPathFile.Format( "%s\\%s%s.view",g_strDirectory,CString(_PICTUREDIR),strTemp.Left( strTemp.GetLength()-1) );
  1813. strPathFolder.Format( "%s\\%s%s\0\0",g_strDirectory,CString(_PICTUREDIR),strTemp.Left( strTemp.GetLength()-1) );
  1814. if( PathFileExists( strPathFile ) )
  1815. {
  1816. DeleteFile( strPathFile );
  1817. m_wndTree.DeleteItem(hSelectedItem);
  1818. hSelectedItem = NULL;
  1819. }
  1820. if( PathFileExists( strPathFolder ) )
  1821. {
  1822. //strPathFolder += "\0\0";
  1823. DeleteDirectory( strPathFolder );
  1824. //_DeleteFile( strPathFolder,FOF_ALLOWUNDO|FOF_NOCONFIRMATION );
  1825. if( hSelectedItem )
  1826. m_wndTree.DeleteItem(hSelectedItem);
  1827. }
  1828. CString sContent;
  1829. sContent.Format("删除画面< %s >",strSelect.TrimRight() );
  1830. //CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_MONITOR_DELETE,0,"",(char *)(LPCTSTR)sContent );
  1831. return;
  1832. //strPath = g_strDirectory + CString("\\") + CString(_PICTUREDIR);
  1833. //ffsco o;
  1834. //o.dirs(1); //查找子目录
  1835. //o.find( LPCSTR(strPath), "*.view" );
  1836. //ffsco::typeT coo;
  1837. //ffsco::typeT::iterator it;
  1838. //HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
  1839. //if( m_hMonitor==hSelectedItem )
  1840. //{
  1841. // MessageBox(g_strMonitorNameCannotDel, g_strTip, MB_ICONINFORMATION);
  1842. // return;
  1843. //}
  1844. //CString strSelect = m_wndTree.GetItemText( hSelectedItem );
  1845. //CString strMessage;
  1846. //strMessage.Format(g_strDelView,strSelect);
  1847. //if (MessageBox(strMessage,g_strConfirm,MB_YESNO|MB_ICONQUESTION) == IDNO)
  1848. // return;
  1849. ////文件
  1850. //coo = o.co_file();
  1851. //for (it = coo.begin(); coo.end() != it; it++)
  1852. //{
  1853. // strTemp = (*it).c_str();
  1854. // strPath = strTemp;
  1855. // strTemp = strTemp.Right( strTemp.GetLength() - strTemp.ReverseFind('\\') - 1 );
  1856. // if( !strTemp.Compare(strSelect + ".view") )
  1857. // {
  1858. // CFile::Remove( strPath );
  1859. // m_wndTree.DeleteItem(hSelectedItem);
  1860. // break;
  1861. // }
  1862. //}
  1863. ////目录
  1864. //coo = o.co_dir();
  1865. //for( it = coo.begin(); coo.end() != it; it++ )
  1866. //{
  1867. // strTemp = (*it).c_str();
  1868. // strPath = strTemp;
  1869. // int nFind = strTemp.ReverseFind('\\');
  1870. // strTemp = strTemp.Left( nFind );
  1871. // strTemp = strTemp.Right( strTemp.GetLength() - strTemp.ReverseFind('\\') - 1 );
  1872. // if( !strTemp.Compare(strSelect) )
  1873. // {
  1874. // DeleteDirectory( strPath );
  1875. // m_wndTree.DeleteItem(hSelectedItem);
  1876. // break;
  1877. // }
  1878. //}
  1879. //CString sContent;
  1880. //sContent.Format("删除画面< %s >",strSelect.TrimRight() );
  1881. //CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_MONITOR_DELETE,0,"",(char *)(LPCTSTR)sContent );
  1882. }
  1883. void CMainFrame::OnUpdateDeleteview(CCmdUI *pCmdUI)
  1884. {
  1885. // TODO: 在此添加命令更新用户界面处理程序代码
  1886. }
  1887. void CMainFrame::OnModifyViewName()
  1888. {
  1889. // TODO: 在此添加命令处理程序代码
  1890. CString strNew, strTemp,sViewName;
  1891. CString strPathFile,strPathFolder;
  1892. HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
  1893. if( m_hMonitor==hSelectedItem )
  1894. {
  1895. return;
  1896. }
  1897. CString strSelect = m_wndTree.GetItemText( hSelectedItem );
  1898. CViewNameDlg dlg;
  1899. dlg.m_strViewName = strSelect;
  1900. if (dlg.DoModal() != IDOK)
  1901. return;
  1902. GetPicPathByTree( hSelectedItem,strTemp );
  1903. strPathFile.Format( "%s\\%s%s.view",g_strDirectory,CString(_PICTUREDIR),strTemp.Left( strTemp.GetLength()-1) );
  1904. strPathFolder.Format( "%s\\%s%s\0\0",g_strDirectory,CString(_PICTUREDIR),strTemp.Left( strTemp.GetLength()-1) );
  1905. if( PathFileExists( strPathFile ) )
  1906. {
  1907. strTemp = strSelect + ".view";
  1908. sViewName = dlg.m_strViewName + ".view";
  1909. strNew = strPathFile;
  1910. strNew.Replace( strTemp,sViewName );
  1911. MoveFile( strPathFile,strNew );
  1912. m_wndTree.SetItemText( hSelectedItem,dlg.m_strViewName );
  1913. hSelectedItem = NULL;
  1914. }
  1915. if( PathFileExists( strPathFolder ) )
  1916. {
  1917. strTemp = "\\" + strSelect;
  1918. sViewName = "\\" + dlg.m_strViewName;
  1919. strNew = strPathFolder;
  1920. strNew.Replace( strTemp,sViewName );
  1921. CopyDirectory( strPathFolder,strNew );
  1922. DeleteDirectory( strPathFolder );
  1923. if( hSelectedItem )
  1924. m_wndTree.DeleteItem(hSelectedItem);
  1925. }
  1926. }
  1927. void CMainFrame::OnUpdateModifyViewName(CCmdUI *pCmdUI)
  1928. {
  1929. // TODO: 在此添加命令更新用户界面处理程序代码
  1930. }
  1931. void CMainFrame::OnDeletescript()
  1932. {
  1933. // TODO: 在此添加命令处理程序代码
  1934. HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
  1935. CFile::Remove( _SCRIPTDIR + m_wndTree.GetItemText(hSelectedItem) + ".srp");
  1936. CFile::Remove( _SCRIPTDIR + m_wndTree.GetItemText(hSelectedItem) + ".con");
  1937. m_wndTree.DeleteItem(hSelectedItem);
  1938. int i = 0, nPos = -1;
  1939. for( i = 0; i < m_nScripts; i++)
  1940. {
  1941. if (hSelectedItem == m_hScriptGroup[i])
  1942. {
  1943. nPos = i;
  1944. }
  1945. }
  1946. for( i = nPos; i < m_nScripts; i++)
  1947. {
  1948. m_hScriptGroup[i] = m_hScriptGroup[i+1];
  1949. }
  1950. }
  1951. void CMainFrame::OnUpdateDeletescript(CCmdUI *pCmdUI)
  1952. {
  1953. // TODO: 在此添加命令更新用户界面处理程序代码
  1954. }
  1955. void CMainFrame::OnSetscript()
  1956. {
  1957. // TODO: 在此添加命令处理程序代码
  1958. HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
  1959. for (int m = 0; m < 32; m++)
  1960. {
  1961. if (m_hScriptGroup[m] == hSelectedItem)
  1962. {
  1963. CString conFile;
  1964. //SetCurrentDirectory(g_CurrentDir);
  1965. conFile = CString(g_strDirectory) + "\\" + _SCRIPTDIR;
  1966. conFile = conFile + m_wndTree.GetItemText(hSelectedItem) + ".con";
  1967. }
  1968. }
  1969. }
  1970. void CMainFrame::OnUpdateSetscript(CCmdUI *pCmdUI)
  1971. {
  1972. // TODO: 在此添加命令更新用户界面处理程序代码
  1973. }
  1974. void CMainFrame::OnEditscript()
  1975. {
  1976. // TODO: 在此添加命令处理程序代码
  1977. HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem();
  1978. for (int m = 0; m < 32; m++)
  1979. {
  1980. if (m_hScriptGroup[m] == hSelectedItem)
  1981. {
  1982. CString scriptFile;
  1983. scriptFile = CString(g_strDirectory) + "\\" + _SCRIPTDIR;
  1984. scriptFile = scriptFile + m_wndTree.GetItemText(hSelectedItem) + ".srp";
  1985. ShellExecute(NULL,"open", "ScriptEdit.exe", scriptFile, NULL, SW_SHOWNORMAL);
  1986. }
  1987. }
  1988. }
  1989. void CMainFrame::OnUpdateEditscript(CCmdUI *pCmdUI)
  1990. {
  1991. // TODO: 在此添加命令更新用户界面处理程序代码
  1992. }
  1993. void CMainFrame::SetRunPara()
  1994. {
  1995. OnSysPara();
  1996. }
  1997. int CMainFrame::GetIDEViewIndex(CString strPath)
  1998. {
  1999. int i;
  2000. for( i = 0; i < MAX_VIEW_NUM; i++ )
  2001. {
  2002. if( !m_pViewIDE[i] ) continue;
  2003. CString str;
  2004. str = m_pViewIDE[i]->m_strPath;
  2005. str.Replace("\\\\", "\\");
  2006. strPath.Replace("\\\\", "\\");
  2007. if( !str.Compare(strPath) )
  2008. {
  2009. return i;
  2010. }
  2011. }
  2012. return -1;
  2013. }
  2014. int CMainFrame::GetIDEViewFreeIndex(CString strPath)
  2015. {
  2016. int i;
  2017. for( i = 0; i < MAX_VIEW_NUM; i++ )
  2018. {
  2019. if( !m_pViewIDE[i] ) return i;
  2020. if( m_pViewIDE[i]->m_bClose ) continue;
  2021. if( !m_pViewIDE[i]->m_strPath.Compare("") )
  2022. {
  2023. return i;
  2024. }
  2025. }
  2026. return -1;
  2027. }
  2028. void CMainFrame::AddIDEView(CString strDesc, CString strPath)
  2029. {
  2030. //如果是当前画面,退出
  2031. if( g_strViewName==strPath )
  2032. return;
  2033. g_sCurrentPageName = strDesc;
  2034. // 打开新的画面,先保存旧的。
  2035. CIDEView *pView = (CIDEView *)m_pActiveView;
  2036. if( pView )
  2037. {
  2038. pView->ChangeView();
  2039. }
  2040. int nIndex = GetIDEViewIndex(strPath);
  2041. if( nIndex == -1 )
  2042. {
  2043. nIndex = GetIDEViewFreeIndex(strPath);
  2044. if( nIndex == -1 ) nIndex = 0;
  2045. CCreateContext context;
  2046. m_pViewIDE[nIndex] = new CChildFrame;
  2047. m_pViewIDE[nIndex]->m_strPath = strPath;
  2048. m_pViewIDE[nIndex]->m_strDesc = strDesc;
  2049. context.m_pCurrentDoc = m_pDoc;
  2050. context.m_pNewDocTemplate = m_pDoc->GetDocTemplate();
  2051. context.m_pNewViewClass = RUNTIME_CLASS( CIDEView );
  2052. context.m_pCurrentFrame = this;
  2053. context.m_pLastView = NULL;
  2054. if( !m_pViewIDE[nIndex]->LoadFrame(IDI_SUMMARY, WS_MAXIMIZE|WS_OVERLAPPEDWINDOW, this, &context) )
  2055. {
  2056. return;
  2057. }
  2058. m_pViewIDE[nIndex]->ShowWindow(SW_SHOWMAXIMIZED);
  2059. m_pViewIDE[nIndex]->InitialUpdateFrame(m_pDoc,true);
  2060. m_pViewIDE[nIndex]->MDIActivate();
  2061. m_nViewCount++;
  2062. }
  2063. else
  2064. {
  2065. m_pActiveView = (CFormView *)m_pViewIDE[nIndex]->GetActiveView();
  2066. m_pViewIDE[nIndex]->MDIActivate();
  2067. }
  2068. m_pViewIDE[ nIndex ]->m_bClose = FALSE;
  2069. m_pActiveView = (CFormView *)m_pViewIDE[nIndex]->GetActiveView();
  2070. g_strViewName = strPath;
  2071. ((CIDEView *)m_pActiveView)->ChangeView();
  2072. //取当前所有的变量到SA中
  2073. GetCurPicVarToSArray( strPath );
  2074. /////////////////////把当前画面名保存到C:\\PageName.txt中,给视频用///////////////////////////////////
  2075. CString sPath = "C:\\PageName.txt";
  2076. DeleteFile( sPath );
  2077. CString strTemp;
  2078. CStdioFile MyFile;
  2079. CFileException e;
  2080. if ( MyFile.Open(sPath,CFile::modeCreate|CFile::modeWrite,&e) )
  2081. {
  2082. strTemp.Format("%s\n",strDesc);
  2083. MyFile.SeekToEnd();
  2084. MyFile.WriteString(strTemp);
  2085. MyFile.Close();
  2086. }
  2087. }
  2088. void CMainFrame::OnUsers()
  2089. {
  2090. }
  2091. void CMainFrame::OnEditPwdTool()
  2092. {
  2093. if( g_nIsDemo == 0 )
  2094. {
  2095. CDlgEditPwd dlg;
  2096. if( dlg.DoModal() == IDOK )
  2097. {
  2098. CString sContent;
  2099. sContent.Format("%s%s",g_strEdit,g_strPwd );
  2100. //CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_PWD_EDIT,0,"",(char *)(LPCTSTR)sContent );
  2101. }
  2102. }
  2103. }
  2104. void CMainFrame::OnSysPara()
  2105. {
  2106. CSystemParaSetDlg dlg;
  2107. dlg.m_bStartRun = g_bStartRun;
  2108. dlg.m_bAlarmVoice = g_bAlarmVoice;
  2109. dlg.m_bEventAlarm = g_bEventAlarm;
  2110. dlg.m_bHideTask = g_bHideTask;
  2111. dlg.m_strStartPic = g_strStartPic;
  2112. dlg.m_strStartPath = g_strStartPath;
  2113. if ( dlg.DoModal() == IDOK )
  2114. {
  2115. #if 0 //程序退出之前不改变状态
  2116. g_bStartRun = dlg.m_bStartRun;
  2117. #endif
  2118. //int nPos = dlg.m_strStartPath.Find("\\\\");
  2119. //if( nPos!=-1 )
  2120. //{
  2121. // dlg.m_strStartPath.Delete( nPos );
  2122. //}
  2123. //
  2124. //int nLen = dlg.m_strStartPath.GetLength();
  2125. //nPos = dlg.m_strStartPath.Find("view");
  2126. //CString sTemp;
  2127. //if( nPos<nLen-7 )
  2128. // sTemp = dlg.m_strStartPath.Right( nLen-nPos-7 );
  2129. //if( sTemp!="" )
  2130. // g_strStartPic = sTemp+"\\"+dlg.m_strStartPic;
  2131. //else
  2132. g_strStartPic = dlg.m_strStartPic;
  2133. g_strStartPath = dlg.m_strStartPath;
  2134. g_bEventAlarm = dlg.m_bEventAlarm;
  2135. g_bAlarmVoice = dlg.m_bAlarmVoice;
  2136. g_bHideTask = dlg.m_bHideTask;
  2137. StoreRunPara(dlg.m_bStartRun);
  2138. }
  2139. }
  2140. void CMainFrame::OnEventmanage()
  2141. {
  2142. }
  2143. void CMainFrame::OnEvent()
  2144. {
  2145. }
  2146. void CMainFrame::OnSystemLog()
  2147. {
  2148. }
  2149. void CMainFrame::OnNoticeRec()
  2150. {
  2151. }
  2152. void CMainFrame::OnUpdateEvent(CCmdUI* pCmdUI)
  2153. {
  2154. // TODO: Add your command update UI handler code here
  2155. pCmdUI->Enable(m_bEvent);
  2156. }
  2157. void CMainFrame::OnUpdateSystemLog(CCmdUI* pCmdUI)
  2158. {
  2159. // TODO: Add your command update UI handler code here
  2160. pCmdUI->Enable(m_bSystemLog);
  2161. }
  2162. void CMainFrame::OnUpdateNoticeRec(CCmdUI* pCmdUI)
  2163. {
  2164. // TODO: Add your command update UI handler code here
  2165. pCmdUI->Enable(m_bNoticeRec);
  2166. }
  2167. void CMainFrame::OnUpdateUsers(CCmdUI* pCmdUI)
  2168. {
  2169. // TODO: Add your command update UI handler code here
  2170. pCmdUI->Enable(m_bUsers);
  2171. }
  2172. void CMainFrame::OnUpdateEditPwd(CCmdUI* pCmdUI)
  2173. {
  2174. // TODO: Add your command update UI handler code here
  2175. pCmdUI->Enable(m_bEditPwd);
  2176. }
  2177. void CMainFrame::OnUpdateSysPare(CCmdUI* pCmdUI)
  2178. {
  2179. // TODO: Add your command update UI handler code here
  2180. pCmdUI->Enable(m_bSysPare);
  2181. }
  2182. void CMainFrame::OnUpdateSingleAnalog(CCmdUI* pCmdUI)
  2183. {
  2184. // TODO: Add your command update UI handler code here
  2185. pCmdUI->Enable(m_bAnalog);
  2186. }
  2187. void CMainFrame::OnUpdatePrint(CCmdUI* pCmdUI)
  2188. {
  2189. // TODO: Add your command update UI handler code here
  2190. pCmdUI->Enable(m_bPrint);
  2191. }
  2192. void CMainFrame::OnSummaryLog()
  2193. {
  2194. if( g_nIsDemo == 0 )
  2195. {
  2196. #if 0
  2197. CDlgQuerySummaryLog dlg;
  2198. if( dlg.DoModal() == IDOK )
  2199. {
  2200. }
  2201. #endif
  2202. CString sIDE,sReport;
  2203. sIDE.Format( "%s",g_strDirectory );
  2204. int nEnd = 0;
  2205. for (int i = sIDE.GetLength()-1; i >= 0; i--)
  2206. {
  2207. if (g_strDirectory[i] == '\\')
  2208. {
  2209. nEnd = i;
  2210. break;
  2211. }
  2212. }
  2213. sReport = sIDE.Left( nEnd ) + "\\report";
  2214. CString strFileName;
  2215. strFileName.Format("%s\\DBMonitorReport.exe", sReport);
  2216. ShellExecute(0, "open", strFileName, NULL, NULL, SW_SHOWNORMAL);
  2217. }
  2218. }
  2219. void CMainFrame::OnUpdateSummaryLog(CCmdUI* pCmdUI)
  2220. {
  2221. // TODO: Add your command update UI handler code here
  2222. pCmdUI->Enable(m_bDeviceLog);
  2223. }
  2224. void CMainFrame::StoreRunPara(BOOL bStartRun)
  2225. {
  2226. char Path[_MAX_PATH] = {0};
  2227. strcat(Path, g_strDirectory);
  2228. strcat(Path,"\\");
  2229. strcat(Path, _PROJECTDIR);
  2230. strcat(Path,"\\");
  2231. strcat(Path, "runpara.ini");
  2232. if ( bStartRun )
  2233. {
  2234. WritePrivateProfileString("RUNPARA", "STARTRUN", "1", Path);
  2235. }
  2236. else
  2237. {
  2238. WritePrivateProfileString("RUNPARA", "STARTRUN", "0", Path);
  2239. }
  2240. if ( g_bEventAlarm )
  2241. {
  2242. WritePrivateProfileString("RUNPARA", "ALARM", "1", Path);
  2243. }
  2244. else
  2245. {
  2246. WritePrivateProfileString("RUNPARA", "ALARM", "0", Path);
  2247. }
  2248. if ( g_bAlarmVoice )
  2249. {
  2250. WritePrivateProfileString("RUNPARA", "VOICE", "1", Path);
  2251. }
  2252. else
  2253. {
  2254. WritePrivateProfileString("RUNPARA", "VOICE", "0", Path);
  2255. }
  2256. if ( g_bHideTask )
  2257. {
  2258. WritePrivateProfileString("RUNPARA", "HIDETASK", "1", Path);
  2259. }
  2260. else
  2261. {
  2262. WritePrivateProfileString("RUNPARA", "HIDETASK", "0", Path);
  2263. }
  2264. if ( g_bFullScreen )
  2265. {
  2266. WritePrivateProfileString("RUNPARA", "FULLSCREEN", "1", Path);
  2267. }
  2268. else
  2269. {
  2270. WritePrivateProfileString("RUNPARA", "FULLSCREEN", "0", Path);
  2271. }
  2272. WritePrivateProfileString("RUNPARA", "STARTPIC", g_strStartPic, Path);
  2273. WritePrivateProfileString("RUNPARA", "STARTPATH", g_strStartPath, Path);
  2274. }
  2275. // 存储事件参数
  2276. void CMainFrame::StoreEventPara()
  2277. {
  2278. char Path[_MAX_PATH] = {0};
  2279. strcat(Path, g_strDirectory);
  2280. strcat(Path,"\\");
  2281. strcat(Path, _PROJECTDIR);
  2282. strcat(Path,"\\");
  2283. strcat(Path, "event.ini");
  2284. if ( g_bControlEvent )
  2285. {
  2286. WritePrivateProfileString("IFALARM", "CONTROL", "1", Path);
  2287. }
  2288. else
  2289. {
  2290. WritePrivateProfileString("IFALARM", "CONTROL", "0", Path);
  2291. }
  2292. if ( g_bLoginEvent )
  2293. {
  2294. WritePrivateProfileString("IFALARM", "LOGIN", "1", Path);
  2295. }
  2296. else
  2297. {
  2298. WritePrivateProfileString("IFALARM", "LOGIN", "0", Path);
  2299. }
  2300. if ( g_bSetEvent )
  2301. {
  2302. WritePrivateProfileString("IFALARM", "SET", "1", Path);
  2303. }
  2304. else
  2305. {
  2306. WritePrivateProfileString("IFALARM", "SET", "0", Path);
  2307. }
  2308. if ( g_bReguEvent )
  2309. {
  2310. WritePrivateProfileString("IFALARM", "REGU", "1", Path);
  2311. }
  2312. else
  2313. {
  2314. WritePrivateProfileString("IFALARM", "REGU", "0", Path);
  2315. }
  2316. if ( g_bYxChangeEve )
  2317. {
  2318. WritePrivateProfileString("IFALARM", "YXCHANGE", "1", Path);
  2319. }
  2320. else
  2321. {
  2322. WritePrivateProfileString("IFALARM", "YXCHANGE", "0", Path);
  2323. }
  2324. if ( g_bYcEvent )
  2325. {
  2326. WritePrivateProfileString("IFALARM", "YCOVERLIMIT", "1", Path);
  2327. }
  2328. else
  2329. {
  2330. WritePrivateProfileString("IFALARM", "YCOVERLIMIT", "0", Path);
  2331. }
  2332. WritePrivateProfileString("WAVEFILE", "CONTROL", g_strYkWave, Path);
  2333. WritePrivateProfileString("WAVEFILE", "LOGIN", g_strLoginWave, Path);
  2334. WritePrivateProfileString("WAVEFILE", "SET", g_strSetWave, Path);
  2335. WritePrivateProfileString("WAVEFILE", "REGU", g_strReguWave, Path);
  2336. WritePrivateProfileString("WAVEFILE", "YXCHANGE", g_strYxChangeWave, Path);
  2337. WritePrivateProfileString("WAVEFILE", "YCOVERLIMIT", g_strYcWave, Path);
  2338. }
  2339. void CMainFrame::OnControldialog()
  2340. {
  2341. CRect rctDlg;
  2342. int screenx = GetSystemMetrics(SM_CXSCREEN);
  2343. int screeny = GetSystemMetrics(SM_CYSCREEN);
  2344. m_dlgControl->GetWindowRect(&rctDlg);
  2345. m_dlgControl->SetWindowPos(&wndTop, screenx - rctDlg.Width(), screeny - rctDlg.Height(),
  2346. rctDlg.Width(), rctDlg.Height(), SWP_NOZORDER);
  2347. m_dlgControl->ShowWindow(SW_SHOW);
  2348. }
  2349. void CMainFrame::OnTimer(UINT nIDEvent)
  2350. {
  2351. // TODO: 在此添加消息处理程序代码和/或调用默认值
  2352. if( nIDEvent == 1 )
  2353. {
  2354. if (g_bStartRun && g_nIsPoll == 1)
  2355. {
  2356. for( int i = 0; i < g_nPollCount; i++ )
  2357. {
  2358. if( g_dwTick == 0 )
  2359. {
  2360. if( g_nPollIndex == i )
  2361. {
  2362. g_dwTick = GetTickCount();
  2363. TRACE("Enter AddIDEView %s, %s\r\n", g_strPollPath, g_strPollDesc);
  2364. AddIDEView(g_strPollDesc[i], g_strPollPath[i]);
  2365. TRACE("Leave AddIDEView\r\n");
  2366. }
  2367. }
  2368. else if( GetTickCount() - g_dwTick > (DWORD)g_nPollInterval * 1000 )
  2369. {
  2370. if( g_nPollIndex == g_nPollCount - 1 )
  2371. {
  2372. g_nPollIndex = 0;
  2373. }
  2374. else
  2375. {
  2376. g_nPollIndex++;
  2377. }
  2378. g_dwTick = 0;
  2379. }
  2380. }
  2381. }
  2382. }
  2383. if( nIDEvent==2 )//定时得到狗信息/定时判断是否过期
  2384. {
  2385. }
  2386. CMDIAutoHideFrame::OnTimer(nIDEvent);
  2387. }
  2388. void CMainFrame::OnUserManager()
  2389. {
  2390. // TODO: 在此添加命令处理程序代码
  2391. }
  2392. void CMainFrame::OnGroupManager()
  2393. {
  2394. // TODO: 在此添加命令处理程序代码
  2395. }
  2396. void CMainFrame::OnEditPwd()
  2397. {
  2398. // TODO: 在此添加命令处理程序代码
  2399. CDlgEditPwd dlg;
  2400. if( dlg.DoModal() == IDOK )
  2401. {
  2402. CString sContent;
  2403. sContent.Format("修改密码");
  2404. //CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_PWD_EDIT,0,"",(char *)(LPCTSTR)sContent );
  2405. }
  2406. }
  2407. void CMainFrame::OnSingleAnalog()
  2408. {
  2409. // TODO: 在此添加命令处理程序代码
  2410. }
  2411. LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  2412. {
  2413. // TODO: 在此添加专用代码和/或调用基类
  2414. switch( message )
  2415. {
  2416. case WM_MY_NEW_ALERT:
  2417. {
  2418. CString sPath;
  2419. CString sVarName = (char *)wParam;
  2420. //LOG4C((LOG_NOTICE, "报警变量:%s", sVarName));
  2421. if( GetPicPathByVarName( sPath,sVarName ) )
  2422. {
  2423. int nPos1=0,nPos2=0;
  2424. for( int i=sPath.GetLength()-1;i>0;i-- )
  2425. {
  2426. if( sPath[i]=='\\' )
  2427. {
  2428. nPos1 = i;
  2429. break;
  2430. }
  2431. }
  2432. for( int i=sPath.GetLength()-1;i>0;i-- )
  2433. {
  2434. if( sPath[i]=='.' )
  2435. {
  2436. nPos2 = i;
  2437. break;
  2438. }
  2439. }
  2440. CString sName = sPath.Mid( nPos1+1,nPos2-nPos1-1 );
  2441. AddIDEView( sName,sPath );
  2442. }
  2443. //LOG4C((LOG_NOTICE, "报警画面:%s", sPath));
  2444. }
  2445. break;
  2446. case WM_MY_SIZECHANGE:
  2447. {
  2448. CString str;
  2449. str.Format( "%d,%d",wParam,lParam );
  2450. }
  2451. break;
  2452. case WM_MY_SIZECHANGE2:
  2453. {
  2454. #if USE_NEWTOP
  2455. CString str;
  2456. str.Format( "%d,%d",wParam,lParam );
  2457. m_pToolBar->SetPos( wParam,lParam );
  2458. #endif
  2459. }
  2460. break;
  2461. }
  2462. return CMDIAutoHideFrame::WindowProc(message, wParam, lParam);
  2463. }
  2464. bool CMainFrame::GetPicIndexByPicPath( int &iIndex,CString sPicPath )
  2465. {
  2466. bool bRet=false;
  2467. for( int i=0;i<VIEW_MAX_NUM;i++ )
  2468. {
  2469. if( m_PIC_VAR[i].sPicPath=="" )
  2470. {
  2471. iIndex=i;
  2472. break;
  2473. }
  2474. if( m_PIC_VAR[i].sPicPath==sPicPath )
  2475. {
  2476. bRet = true;
  2477. break;
  2478. }
  2479. }
  2480. return bRet;
  2481. }
  2482. //通过变量名查找画面
  2483. bool CMainFrame::GetPicPathByVarName( CString &sPicPath,CString sVarName )
  2484. {
  2485. bool bRet=false;
  2486. bool bBreak=false;
  2487. for( int i=0;i<VIEW_MAX_NUM;i++ )
  2488. {
  2489. if( m_PIC_VAR[i].sPicPath=="" )
  2490. break;
  2491. for( int j=0;j<1000;j++ )
  2492. {
  2493. if( m_PIC_VAR[i].sCaption[j]=="" )
  2494. {
  2495. break;
  2496. }
  2497. if( -1 != m_PIC_VAR[i].sCaption[j].Find( sVarName ) )
  2498. {
  2499. sPicPath = m_PIC_VAR[i].sPicPath;
  2500. bRet = true;
  2501. bBreak = true;
  2502. break;
  2503. }
  2504. }
  2505. if( bBreak )
  2506. break;
  2507. }
  2508. return bRet;
  2509. }
  2510. // 判断是有效变量名
  2511. BOOL CMainFrame::IsValidChar(char chr)
  2512. {
  2513. if ( chr >= '0' && chr <= '9')
  2514. return TRUE;
  2515. else if ((chr >= 'A' && chr <= 'Z') || (chr >= 'a' && chr <= 'z') )
  2516. return TRUE;
  2517. else if (chr == '_')
  2518. return TRUE;
  2519. else
  2520. return FALSE;
  2521. }
  2522. //从组合公式中找出变量名加入到画面结构中
  2523. void CMainFrame::GetVarFromGSAddToStruct( int iIndex,CString sGS )
  2524. {
  2525. //LOG4C((LOG_NOTICE, "GetVarFromGSAddToStruct sGS :%s", sGS));
  2526. //sGS = "(HG7053_DI10>=3)OR(HG7053_LinkStatus<=33)";
  2527. //sGS = "((HG7053_DI10>=3))";
  2528. //sGS = "(HG7053_DI10>=3)AND(HG7053_LinkStatus<=33)OR(HG7053_DI15<3)";
  2529. int nLen = sGS.GetLength();
  2530. int nPos1=0,nPos2=0;
  2531. int nPos3=0,nPos4=0;
  2532. CString sTemp,s1,s2,s3;
  2533. CString sGS2[100];
  2534. int nCount=0;
  2535. //OR AND NOT
  2536. for( int i=0;i<nLen;i++ )
  2537. {
  2538. if( sGS.Mid( i,2)=="OR" && !IsValidChar(sGS[i+2]) )
  2539. {
  2540. sGS2[nCount++] = sGS.Mid( nPos1,i-nPos1 );
  2541. nPos1 = i+2;
  2542. }
  2543. if( (sGS.Mid( i,3)=="AND" || sGS.Mid( i,3)=="NOT") && !IsValidChar(sGS[i+3]) )
  2544. {
  2545. sGS2[nCount++] = sGS.Mid( nPos1,i-nPos1 );
  2546. nPos1 = i+3;
  2547. }
  2548. }
  2549. if( nPos1<nLen )
  2550. {
  2551. sGS2[nCount++] = sGS.Mid( nPos1,nLen-nPos1 );
  2552. }
  2553. for( int iGSIndex=0;iGSIndex<nCount;iGSIndex++ )
  2554. {
  2555. nPos3=0;
  2556. nPos4=0;
  2557. nLen = sGS2[iGSIndex].GetLength();
  2558. if( !IsValidChar( sGS2[iGSIndex][0] ) )
  2559. {
  2560. if( IsValidChar( sGS2[iGSIndex][1] ) )
  2561. nPos3 = 1;
  2562. else
  2563. nPos3 = 2;
  2564. for( int i=nPos3;i<nLen;i++ )
  2565. {
  2566. if( !IsValidChar( sGS2[iGSIndex][i] ) )
  2567. {
  2568. nPos4 = i-0;
  2569. break;
  2570. }
  2571. }
  2572. sTemp = sGS2[iGSIndex].Mid( nPos3,nPos4-nPos3 );
  2573. int nInsert=0;
  2574. if( !VarIsExistInPic( iIndex,sTemp,nInsert ) && sTemp!="" )
  2575. m_PIC_VAR[iIndex].sCaption[nInsert] = sTemp;
  2576. }
  2577. else
  2578. {
  2579. for( int i=nPos3;i<nLen;i++ )
  2580. {
  2581. if( !IsValidChar( sGS2[iGSIndex][i] ) )
  2582. {
  2583. nPos4 = i-0;
  2584. break;
  2585. }
  2586. }
  2587. sTemp = sGS2[iGSIndex].Mid( nPos3,nPos4-nPos3 );
  2588. int nInsert=0;
  2589. if( !VarIsExistInPic( iIndex,sTemp,nInsert ) && sTemp!="" )
  2590. m_PIC_VAR[iIndex].sCaption[nInsert] = sTemp;
  2591. }
  2592. }
  2593. }
  2594. //把变量插入到相对应的画面结构
  2595. void CMainFrame::InsertPicPathToStruct( int iIndex,CString sPicPath )
  2596. {
  2597. //LOG4C((LOG_NOTICE, "InsertPicPathToStruct :%s", sPicPath));
  2598. CDrawObjList _ObjList;
  2599. m_PIC_VAR[iIndex].sPicPath = sPicPath;
  2600. BYTE m_Type;
  2601. CSize m_sizePic;
  2602. CSize m_sizeGrid;
  2603. BOOL m_bGrid;
  2604. COLORREF m_clrBack;
  2605. CFile file;
  2606. if(file.Open(sPicPath,CFile::modeRead))
  2607. {
  2608. CArchive ar(&file,CArchive::load);
  2609. ar >> m_Type;
  2610. ar >> m_sizePic;
  2611. ar >> m_sizeGrid;
  2612. ar >> m_bGrid;
  2613. ar >> m_clrBack;
  2614. _ObjList.Serialize(ar);
  2615. if( !_ObjList.IsEmpty() )
  2616. {
  2617. for(POSITION pos = _ObjList.GetHeadPosition();pos!=NULL;)
  2618. {
  2619. POSITION pos1 = pos ;
  2620. CDrawObj *ct = (CDrawObj *)_ObjList.GetNext(pos);
  2621. int nInsert=0;
  2622. if( ct->m_bVariant && ct->m_strCaption!="" && !VarIsExistInPic( iIndex,ct->m_strCaption,nInsert ) )
  2623. m_PIC_VAR[iIndex].sCaption[nInsert] = ct->m_strCaption;
  2624. if( ct->m_strDynShow!="" )
  2625. GetVarFromGSAddToStruct( iIndex,ct->m_strDynShow );
  2626. if( ct->m_strDynForeCon!="" )
  2627. GetVarFromGSAddToStruct( iIndex,ct->m_strDynForeCon );
  2628. if( ct->m_strDynBackCon!="" )
  2629. GetVarFromGSAddToStruct( iIndex,ct->m_strDynBackCon );
  2630. if( ct->m_strDynLineCon!="" )
  2631. GetVarFromGSAddToStruct( iIndex,ct->m_strDynLineCon );
  2632. if( ct->m_strHoriPos!="" )
  2633. GetVarFromGSAddToStruct( iIndex,ct->m_strHoriPos );
  2634. if( ct->m_strHoriSize!="" )
  2635. GetVarFromGSAddToStruct( iIndex,ct->m_strHoriSize );
  2636. if( ct->m_strVertiPos!="" )
  2637. GetVarFromGSAddToStruct( iIndex,ct->m_strVertiPos );
  2638. if( ct->m_strVertiSize!="" )
  2639. GetVarFromGSAddToStruct( iIndex,ct->m_strVertiSize );
  2640. if( ct->m_strCurrentCaption!="" )
  2641. GetVarFromGSAddToStruct( iIndex,ct->m_strCurrentCaption );
  2642. if( ct->IsKindOf( RUNTIME_CLASS(CDrawBitmap) ) )
  2643. {
  2644. if( ((CDrawBitmap *)ct)->m_strDynCondition!="" )
  2645. GetVarFromGSAddToStruct( iIndex,((CDrawBitmap *)ct)->m_strDynCondition );
  2646. }
  2647. if( ct->IsKindOf( RUNTIME_CLASS(CDrawGif) ) )
  2648. {
  2649. if( ((CDrawGif *)ct)->m_strDynCondition!="" )
  2650. GetVarFromGSAddToStruct( iIndex,((CDrawGif *)ct)->m_strDynCondition );
  2651. }
  2652. }
  2653. }
  2654. ///////////////////////////////////////
  2655. ar.Close();
  2656. file.Close();
  2657. }
  2658. if(!_ObjList.IsEmpty())
  2659. {
  2660. for(POSITION pos = _ObjList.GetHeadPosition();pos!=NULL;)
  2661. {
  2662. POSITION pos1 = pos ;
  2663. CDrawObj *ct = (CDrawObj *)_ObjList.GetNext(pos);
  2664. _ObjList.RemoveAt(pos1);
  2665. delete ct;
  2666. }
  2667. _ObjList.RemoveAll();
  2668. ASSERT(_ObjList.IsEmpty());
  2669. }
  2670. }
  2671. //查找这个画面结构里是否已经有这个变量
  2672. bool CMainFrame::VarIsExistInPic( int iIndex,CString sVarName,int &iInsertIndex )
  2673. {
  2674. bool bRet=false;
  2675. for( int j=0;j<1000;j++ )
  2676. {
  2677. if( m_PIC_VAR[iIndex].sCaption[j]=="" )
  2678. {
  2679. iInsertIndex = j;
  2680. break;
  2681. }
  2682. //if( -1 != m_PIC_VAR[iIndex].sCaption[j].Find( sVarName ) )
  2683. if( m_PIC_VAR[iIndex].sCaption[j] == sVarName )
  2684. {
  2685. bRet = true;
  2686. break;
  2687. }
  2688. }
  2689. return bRet;
  2690. }
  2691. void CMainFrame::GetCurPicVarToSArray( CString sPicPath )
  2692. {
  2693. //LOG4C((LOG_NOTICE, "开始获取 当前画面%s 变量", sPicPath));
  2694. for( int i=0;i<VIEW_MAX_NUM;i++ )
  2695. {
  2696. if( m_PIC_VAR[i].sPicPath=="" )
  2697. {
  2698. break;
  2699. }
  2700. if( m_PIC_VAR[i].sPicPath==sPicPath )//是当前画面
  2701. {
  2702. for( int j=0;j<1000;j++ )
  2703. {
  2704. if( m_PIC_VAR[i].sCaption[j]=="" )
  2705. {
  2706. break;
  2707. }
  2708. }
  2709. break;
  2710. }
  2711. }
  2712. //LOG4C((LOG_NOTICE, "结束获取 当前画面%s 变量", sPicPath));
  2713. }
  2714. bool CMainFrame::MakeFolderExist( CString DirectoryName )
  2715. {
  2716. if(DirectoryName[DirectoryName.GetLength()-1]!='\\')
  2717. DirectoryName += "\\";
  2718. int nStart = 3;
  2719. CString sTemp;
  2720. for(int n = nStart;n<DirectoryName.GetLength();n++)
  2721. {
  2722. if(DirectoryName[n]=='\\')
  2723. {
  2724. sTemp = DirectoryName.Left(n);
  2725. bool f = ExistFolder(sTemp);
  2726. if(!ExistFolder(sTemp))
  2727. CreateDirectoryCHN(sTemp);
  2728. }
  2729. }
  2730. return true;
  2731. }
  2732. bool CMainFrame::CreateDirectoryCHN(CString DirectoryName)
  2733. {
  2734. bool re=false;
  2735. ::CreateDirectory(DirectoryName,NULL);
  2736. //DWORD dwAttrs;
  2737. //dwAttrs=GetFileAttributes(DirectoryName);
  2738. //if(!(dwAttrs & FILE_ATTRIBUTE_HIDDEN))
  2739. //{
  2740. // SetFileAttributes(DirectoryName,dwAttrs|FILE_ATTRIBUTE_HIDDEN);
  2741. //}
  2742. return re;
  2743. }
  2744. bool CMainFrame::ExistFolder(CString FilePath)
  2745. {
  2746. return PathFileExists( FilePath );
  2747. }
  2748. void CMainFrame::CopyDirectory( CString sScrPath,CString sDescPath )
  2749. {
  2750. CString StrSourceFolder= sScrPath;
  2751. CString StrDestFolder=sDescPath;
  2752. char SourceFolder[MAX_PATH+1]= " ";
  2753. strcpy(SourceFolder,StrSourceFolder);
  2754. char TargetFolder[MAX_PATH+1]= " ";
  2755. strcpy(TargetFolder,StrDestFolder);
  2756. SHFILEOPSTRUCT lpFile;
  2757. lpFile.hwnd=GetSafeHwnd();
  2758. lpFile.wFunc=FO_COPY;
  2759. lpFile.pFrom=SourceFolder;
  2760. lpFile.pTo=TargetFolder;
  2761. lpFile.fFlags=FOF_ALLOWUNDO;
  2762. lpFile.fAnyOperationsAborted=FALSE;
  2763. lpFile.hNameMappings=NULL;
  2764. lpFile.lpszProgressTitle=NULL;
  2765. int ReturnValue=SHFileOperation(&lpFile);
  2766. if(ReturnValue==0)
  2767. {
  2768. if(lpFile.fAnyOperationsAborted==TRUE)
  2769. ;//MessageBox( "复制文件夹的操作被取消 ", "信息提示 ",MB_OK+MB_ICONWARNING);
  2770. else
  2771. ;//MessageBox( "复制文件夹操作成功 ", "信息提示 ",MB_OK+MB_ICONWARNING);
  2772. }
  2773. else
  2774. ;//MessageBox( "复制文件夹操作失败 ", "信息提示 ",MB_OK+MB_ICONEXCLAMATION);
  2775. }
  2776. void CMainFrame::GetPicPathByTree( HTREEITEM hItemSelect,CString &sPath )
  2777. {
  2778. if( m_hMonitor==hItemSelect )
  2779. {
  2780. return;
  2781. }
  2782. CString strSelect = m_wndTree.GetItemText( hItemSelect );
  2783. sPath = strSelect + "\\" + sPath;
  2784. HTREEITEM hItemParent = m_wndTree.GetParentItem( hItemSelect );
  2785. if( hItemParent )
  2786. GetPicPathByTree( hItemParent,sPath );
  2787. }