MainFrm.cpp 61 KB

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