// MainFrm.cpp : CMainFrame 类的实现 // #include "stdafx.h" #include "IDE.h" #include "Dlg_Pwd.h" #include "MainFrm.h" #include ".\mainfrm.h" #include #include #include #include #include #include //#include #include "Shlwapi.h" #include "DrawObj.h" #include "Graph.h" #include "ViewNameDlg.h" #include "Login.h" #include "IDEView.h" #include "SystemParaSetDlg.h" #include "public.h" #include "SysLib.h" #include "ffsco.h" #include "Wizard.h" #include "DlgEditPwd.h" #include "Dlg_EditView.h" #include "FileAndFolderClass.h" using namespace helper_coffs; #pragma warning ( disable: 4800 ) #ifdef _DEBUG #define new DEBUG_NEW #endif #if USE_TRAYICON #define WM_MY_TRAY_NOTIFICATION WM_USER + 1 const UINT WM_TASKBARCREATED = ::RegisterWindowMessage(_T("TaskbarCreated")); #endif // CMainFrame IMPLEMENT_DYNAMIC(CMainFrame, CMDIAutoHideFrame) BEGIN_MESSAGE_MAP(CMainFrame, CMDIAutoHideFrame) ON_WM_CREATE() ON_COMMAND(IP_SUPER_END, OnSuperEnd) ON_COMMAND(ID_TRAY_OPEN, OnTrayOpen) #if USE_TRAYICON ON_MESSAGE(WM_MY_TRAY_NOTIFICATION, OnTrayNotification) ON_REGISTERED_MESSAGE(WM_TASKBARCREATED, OnTaskBarCreated) #endif ON_WM_CLOSE() ON_COMMAND(ID_ADDDEVOCE, OnAdddevoce) ON_UPDATE_COMMAND_UI(ID_ADDDEVOCE, OnUpdateAdddevoce) ON_COMMAND(IDM_MENU_ZUTAIADD, OnZuTaiAdd) ON_UPDATE_COMMAND_UI(IDM_MENU_ZUTAIADD, OnUpdateZuTaiAdd) ON_COMMAND(ID_DELETEPORT, OnDeleteport) ON_UPDATE_COMMAND_UI(ID_DELETEPORT, OnUpdateDeleteport) ON_COMMAND(ID_ADD_PORT, OnAddPort) ON_UPDATE_COMMAND_UI(ID_ADD_PORT, OnUpdateAddPort) ON_COMMAND(ID_ADD_SCRIPT, OnAddScript) ON_UPDATE_COMMAND_UI(ID_ADD_SCRIPT, OnUpdateAddScript) ON_COMMAND(ID_ADDVIEW, OnAddview) ON_UPDATE_COMMAND_UI(ID_ADDVIEW, OnUpdateAddview) ON_COMMAND(ID_ADDVIEW2, OnAddview2) ON_UPDATE_COMMAND_UI(ID_ADDVIEW2, OnUpdateAddview2) ON_COMMAND(ID_ONLYADD_SORT, OnEditSort) ON_UPDATE_COMMAND_UI(ID_ONLYADD_SORT, OnUpdateEditSort) ON_COMMAND(ID_DELETEDEVICE, OnDeletedevice) ON_UPDATE_COMMAND_UI(ID_DELETEDEVICE, OnUpdateDeletedevice) ON_COMMAND(ID_DELETEVIEW, OnDeleteview) ON_UPDATE_COMMAND_UI(ID_DELETEVIEW, OnUpdateDeleteview) ON_COMMAND(ID_MODIFYVIEWNAME, OnModifyViewName) ON_UPDATE_COMMAND_UI(ID_MODIFYVIEWNAME, OnUpdateModifyViewName) ON_COMMAND(ID_DELETESCRIPT, OnDeletescript) ON_UPDATE_COMMAND_UI(ID_DELETESCRIPT, OnUpdateDeletescript) ON_COMMAND(ID_SETSCRIPT, OnSetscript) ON_UPDATE_COMMAND_UI(ID_SETSCRIPT, OnUpdateSetscript) ON_COMMAND(ID_EDITSCRIPT, OnEditscript) ON_UPDATE_COMMAND_UI(ID_EDITSCRIPT, OnUpdateEditscript) ON_COMMAND(ID_USERS, OnUsers) ON_UPDATE_COMMAND_UI(ID_USERS, OnUpdateUsers) ON_COMMAND(ID_EDITPWD, OnEditPwdTool) ON_UPDATE_COMMAND_UI(ID_EDITPWD, OnUpdateEditPwd) ON_COMMAND(ID_SYSPARE, OnSysPara) ON_UPDATE_COMMAND_UI(ID_SYSPARE, OnUpdateSysPare) ON_COMMAND(ID_EVENTMANAGE, OnEventmanage) ON_COMMAND(ID_EVENT, OnEvent) ON_COMMAND(ID_SUMMARY_LOG, OnSummaryLog) ON_UPDATE_COMMAND_UI(ID_EVENT, OnUpdateEvent) ON_UPDATE_COMMAND_UI(ID_SUMMARY_LOG, OnUpdateSummaryLog) ON_COMMAND(ID_CONTROLDIALOG, OnControldialog) ON_WM_DESTROY() ON_WM_TIMER() ON_COMMAND(ID_SYSTEMLOG, OnSystemLog) ON_UPDATE_COMMAND_UI(ID_SYSTEMLOG, OnUpdateSystemLog) ON_COMMAND(ID_NOTICEREC, OnNoticeRec) ON_UPDATE_COMMAND_UI(ID_NOTICEREC, OnUpdateNoticeRec) ON_COMMAND(ID_USER_MANAGER, OnUserManager) ON_COMMAND(ID_EDIT_PWD, OnEditPwd) ON_COMMAND(ID_GROUP_MANAGER, OnGroupManager) ON_COMMAND(ID_SINGLE_ANALOG, OnSingleAnalog) ON_UPDATE_COMMAND_UI(ID_SINGLE_ANALOG, OnUpdateSingleAnalog) ON_UPDATE_COMMAND_UI(ID_FILE_PRINT, OnUpdatePrint) END_MESSAGE_MAP() static UINT indicators[] = { ID_SEPARATOR, // 状态行指示器 ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; HANDLE m_hFreshVarThread; HANDLE m_hReConnectSrvThread; CRITICAL_SECTION g_CSLimit; // CMainFrame 构造/析构 CMainFrame::CMainFrame():m_trayIcon(IDR_TRAYICON) { // TODO: 在此添加成员初始化代码 m_bShowTrayNotifications = TRUE;//zxn m_bShutdown = FALSE;//zxn #if USE_NEWTOP m_pToolBar = NULL; #else m_wndOfTop = NULL; #endif g_bRun=FALSE; g_nElementNo=0; //选择 g_bEdit=TRUE; m_bHideLeft=FALSE; m_mousePoint=CPoint(0,0); // View个数 m_nViewCount = 0; m_nPortNum = 0; m_nScripts = 0; int i, j; //mdi子窗体 for( i = 0; i < MAX_VIEW_NUM; i++ ) { m_pViewIDE[i] = NULL; } m_bEvent = true; m_bPrint = true; m_bUsers = true; m_bSysPare = true; m_bAnalog = true; m_bDeviceLog = true; m_bSystemLog = true; m_bNoticeRec = true; m_bEditPwd = true; m_hCurrent = NULL; for( int i=0;iCreate(IDD_DIALOGCONTROL, this); m_dlgControl->ShowWindow(SW_HIDE); CRect rct1; m_dlgControl->GetWindowRect(&rct1); m_dlgControl->SetWindowPos(&wndTop, screenx-rct1.Width(), screeny-rct1.Height(), rct1.Width(), rct1.Height(), SWP_NOZORDER); } if( !g_bStartRun ) { m_pDlgZuTaiAdd = new CDlg_ZuTaiAdd(); m_pDlgZuTaiAdd->Create(IDD_DLG_ZUTAI_ADD, this); m_pDlgZuTaiAdd->ShowWindow(SW_HIDE); int screenx=GetSystemMetrics(SM_CXSCREEN); int screeny=GetSystemMetrics(SM_CYSCREEN); //系统任务栏的高度 HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL); RECT rc; ::GetWindowRect(hWnd, &rc); int nHeight = rc.bottom-rc.top; CRect rct; m_pDlgZuTaiAdd->GetWindowRect(&rct); m_pDlgZuTaiAdd->SetWindowPos(&wndTop, (screenx-rct.Width())/2, (screeny-rct.Height())/2, rct.Width(), rct.Height(), SWP_NOZORDER); } // 初始化左边树形 InitTreeInfo(); int W=0,H=0; if (g_bStartRun) { if( g_nIsDemo == 0 ) { // 加载脚本信息 //LoadScriptFromFiles(); } OnRun(); } else { //LONG style=::GetWindowLong(m_hWnd,GWL_STYLE); //style&=~WS_CAPTION; //style&=~WS_BORDER; //::SetWindowLong(m_hWnd,GWL_STYLE,style); int screenx=GetSystemMetrics(SM_CXSCREEN); int screeny=GetSystemMetrics(SM_CYSCREEN); // 系统任务栏的高度; HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL); RECT rc; ::GetWindowRect(hWnd, &rc); int nHeight = rc.bottom -rc.top; printf("非全屏下计算任务栏高度:%d\n", nHeight); if( !g_bFullScreen ) { W = screenx; H = screeny - nHeight; // 以屏幕尺寸的3/2来显示 [5/11/2016 IT] W /= 2; H /= 2; printf("W:%d, H:%d\n", W, H); //SetWindowPos(&wndTopMost,0,0,screenx,screeny-nHeight,SWP_NOZORDER); } else { W = screenx; H = screeny; //SetWindowPos(NULL,0,0,screenx,screeny,SWP_NOZORDER);// 全屏 } } #if USE_TRAYICON m_trayIcon.SetNotificationWnd(this, WM_MY_TRAY_NOTIFICATION); m_trayIcon.SetIcon(IDR_MAINFRAME); #endif // Install the tab view here VERIFY(m_MDIClient.SubclassMDIClient(this, &m_wndViewManager)); if( g_nToolbarTop ) { m_wndViewManager.ShowWindow(SW_SHOW); } else { m_wndViewManager.ShowWindow(SW_HIDE); } if( g_strStartPic.Compare("") ) { char picDir[_MAX_PATH] = {0}; strcpy(picDir, g_strDirectory); strcat(picDir, "\\"); strcat(picDir, _PICTUREDIR); strcat(picDir, g_strStartPic); strcat(picDir, ".view"); AddIDEView( g_strStartPic, CString(picDir) ); } if( g_nIsPoll == 1 ) { SetTimer(1, 1000, NULL); } if( g_bStartRun ) { ShowCaptionMenu(FALSE); } //展开树 //m_wndTree.Expand(m_wndTree.GetRootItem(),TVE_EXPAND); //HTREEITEM handleTreeItem = m_wndTree.GetRootItem(); //while(handleTreeItem) //{ // handleTreeItem = m_wndTree.GetChildItem(handleTreeItem); // m_wndTree.Expand(handleTreeItem, TVE_EXPAND); //} MyExpandTree( m_wndTree.GetRootItem() ); m_wndStatusBar.SetPaneText(2, "ver"); m_wndStatusBar.SetPaneText(3, g_strVersion); if( g_bRun ) SetTimer(2, 1000*15*1, NULL);//狗信息定时器 //SetTimer(3, 1000*60*2, NULL);//判断变量在这个时间段时否报警 if( !g_nToolbarLeft && g_bStartRun ) m_hleftDockBar.ShowWindow( SW_HIDE ); //m_wndDockPageBar1.OnStudClick(); //通知列表 if( g_nAlarmModeIsDlg && g_bRun ) { m_hbottomDockBar.ShowWindow(SW_SHOW); CSize sz; sz = m_hbottomDockBar.GetHorSize(); m_hbottomDockBar.OnStudClick(); } else { m_hbottomDockBar.ShowWindow(SW_HIDE); } //工具栏 if( g_bStartRun && g_nToolbarRun ) { #if USE_NEWTOP m_pToolBar = new CDlg_ToolBar(); m_pToolBar->Create(IDD_DLG_TOOLBAR, this); m_pToolBar->ShowWindow( SW_SHOW ); m_htopDockBar.AddPage( m_pToolBar, "工具栏", IDR_MAINFRAME ); m_htopDockBar.ShowWindow(SW_SHOW); CSize sz; sz = m_htopDockBar.GetHorSize(); // 获取顶部工具栏大小; m_pToolBar->SetPos( sz.cx,sz.cy ); #else // 1.获取实际工具栏长宽 [8/29/2013 Z.t] CSize sz; sz = m_htopDockBar.GetHorSize(); printf("x:%d, y:%d \n",sz.cx, sz.cy); // 2.创建工具栏上的对话框 [8/29/2013 Z.t] m_wndOfTop = new CDlgOfTop(); // 3.传递对话框的大小; m_wndOfTop->_ClientSize.cx = sz.cx; m_wndOfTop->_ClientSize.cy = sz.cy; m_wndOfTop->Create(IDD_TOP, this); m_wndOfTop->ShowWindow( SW_SHOW ); m_htopDockBar.AddPage( m_wndOfTop, "工具栏", IDR_MAINFRAME ); m_htopDockBar.ShowWindow(SW_SHOW); //m_wndOfTop->CalcWindowRect(sz); #if 0 // 一直为1 [8/29/2013 Z.t] m_wndOfTop->MoveWindow(0,0,sz.cx,sz.cy); CRect rtOfTop; m_wndOfTop->GetWindowRect(rtOfTop); // sz,得到是运行后工具栏的实际长宽 [7/27/2013 Zero] // sy,得到是创建m_htopDockBar时的原始大小 [7/27/2013 Zero] CSize sy = m_htopDockBar.GetVerSize(); //m_wndOfTop->SetPos( sz.cx,sz.cy ); TRACE("--on--"); #endif #endif } if( !g_bStartRun && g_nIsDemo==0 ) { this->SetFocus(); // 使连接服务器失败的情况下,第一时间显示在桌面; SetWindowPos(NULL,0,0,W,H,SWP_NOZORDER); CenterWindow(); } else if( g_nIsDemo==1 ) { printf("g_nIsDemo = 1\n"); int screenx=GetSystemMetrics(SM_CXSCREEN); int screeny=GetSystemMetrics(SM_CYSCREEN); //系统任务栏的高度 HWND hWnd = ::FindWindow("Shell_TrayWnd", NULL); RECT rc; ::GetWindowRect(hWnd, &rc); int nHeight = rc.bottom-rc.top; SetWindowPos(NULL,0,0,screenx,screeny-nHeight,SWP_NOZORDER); } return 0; } void CMainFrame::MyExpandTree(HTREEITEM hTreeItem) { if(!m_wndTree.ItemHasChildren(hTreeItem)) { return; } HTREEITEM hNextItem = m_wndTree.GetChildItem(hTreeItem); while (hNextItem != NULL) { MyExpandTree(hNextItem); hNextItem = m_wndTree.GetNextItem(hNextItem, TVGN_NEXT); } m_wndTree.Expand(hTreeItem,TVE_EXPAND); } DWORD WINAPI CMainFrame::ViewPollThread( void *pData ) { CMainFrame *pMainFrm = (CMainFrame *)pData; DWORD dwTick = 0; do { if (g_bStartRun && g_nIsPoll == 1) { for( int i = 0; i < g_nPollCount; i++ ) { if( dwTick == 0 ) { if( g_nPollIndex == i ) { dwTick = GetTickCount(); if( pMainFrm ) { //TRACE("Enter AddIDEView %s, %s\r\n", g_strPollPath, g_strPollDesc); //pMainFrm->AddIDEView(g_strPollDesc[i], g_strPollPath[i]); //TRACE("Leave AddIDEView\r\n"); ((CIDEView *)pMainFrm->m_pActiveView)->ChangeView(); int nIndex = pMainFrm->GetIDEViewIndex(g_strPollPath[i]); if( nIndex == -1 ) { nIndex = pMainFrm->GetIDEViewFreeIndex(g_strPollPath[i]); if( nIndex == -1 ) nIndex = 0; CCreateContext context; pMainFrm->m_pViewIDE[nIndex] = new CChildFrame; pMainFrm->m_pViewIDE[nIndex]->m_strPath = g_strPollPath[i]; pMainFrm->m_pViewIDE[nIndex]->m_strDesc = g_strPollDesc[i]; context.m_pCurrentDoc = pMainFrm->m_pDoc; context.m_pNewDocTemplate = pMainFrm->m_pDoc->GetDocTemplate(); context.m_pNewViewClass = RUNTIME_CLASS( CIDEView ); context.m_pCurrentFrame = pMainFrm; context.m_pLastView = NULL; if( !pMainFrm->m_pViewIDE[nIndex]->LoadFrame(IDI_SUMMARY, WS_MAXIMIZE|WS_OVERLAPPEDWINDOW, pMainFrm, &context) ) { } pMainFrm->m_pViewIDE[nIndex]->ShowWindow(SW_SHOWMAXIMIZED); pMainFrm->m_pViewIDE[nIndex]->InitialUpdateFrame(pMainFrm->m_pDoc,true); pMainFrm->m_pViewIDE[nIndex]->MDIActivate(); pMainFrm->m_nViewCount++; } else { pMainFrm->m_pActiveView = (CFormView *)pMainFrm->m_pViewIDE[nIndex]->GetActiveView(); pMainFrm->m_pViewIDE[nIndex]->MDIActivate(); } pMainFrm->m_pViewIDE[ nIndex ]->m_bClose = FALSE; pMainFrm->m_pActiveView = (CFormView *)pMainFrm->m_pViewIDE[nIndex]->GetActiveView(); g_strViewName = g_strPollPath[i]; ((CIDEView *)pMainFrm->m_pActiveView)->ChangeView(); } } } else if( GetTickCount() - dwTick > (DWORD)g_nPollInterval * 1000 ) { if( g_nPollIndex == g_nPollCount - 1 ) { g_nPollIndex = 0; } else { g_nPollIndex++; } dwTick = 0; } } } }while( WaitForSingleObject( g_hRunObject, 125L ) == WAIT_TIMEOUT ); return 0; } void CMainFrame::ShowCaptionMenu(BOOL bShow) { static HMENU hMenu=NULL; if(hMenu == NULL) { hMenu=::GetMenu(this->GetSafeHwnd()); } if(bShow) { ::SetMenu(this->GetSafeHwnd(),hMenu); this->ModifyStyle(0,WS_CAPTION,SWP_FRAMECHANGED); } else { ::SetMenu(this->GetSafeHwnd(),NULL); this->ModifyStyle(WS_CAPTION,0,SWP_FRAMECHANGED); } } void CMainFrame::LoadRunPara() { char Path[_MAX_PATH] = {0}; strcat(Path, g_strDirectory); strcat(Path,"\\"); strcat(Path, _PROJECTDIR); strcat(Path,"\\"); strcat(Path, "runpara.ini"); char RUN[MAX_PATH] = {0}; memset(RUN, 0, sizeof(RUN)); //CString str; if ( GetPrivateProfileString("RUNPARA", "STARTRUN","",RUN, 10, Path) != 0) { g_bStartRun = (RUN[0] == '1' ? true:false); } if ( GetPrivateProfileString("RUNPARA", "STARTPIC","", RUN, sizeof(RUN), Path) != 0) { g_strStartPic = RUN; } if ( GetPrivateProfileString("RUNPARA", "STARTPATH","",RUN, sizeof(RUN), Path) != 0) { g_strStartPath = RUN; } if ( GetPrivateProfileString("RUNPARA", "ALARM","",RUN, 10, Path) != 0) { g_bEventAlarm = RUN[0] == '1' ? true:false; } if ( GetPrivateProfileString("RUNPARA", "VOICE", "",RUN, 10, Path) != 0) { g_bAlarmVoice = RUN[0] == '1' ? true:false; } if ( GetPrivateProfileString("RUNPARA", "HIDETASK","",RUN, 10, Path) != 0) { g_bHideTask = RUN[0] == '1' ? true:false; } } BOOL CMainFrame::DirSearch(CString strPath, CString strFileName) { BOOL bResult = FALSE; long hDir; struct _finddata_t fDir; int nDone; strPath += "*.*"; hDir = _findfirst( (char *)(LPCTSTR)strPath, &fDir ); if( -1L != hDir ) { while( !( nDone = _findnext(hDir, &fDir) ) ) { if( !strcmp(fDir.name, "..") ) continue; if( (_A_SUBDIR == fDir.attrib) ) { CString str = fDir.name; if( !str.Compare(strFileName) ) { bResult = TRUE; } } } } return bResult; } int CMainFrame::GetLevel( CString sContent ) { int nRet=0; for( int i=0;i=0;i-- ) { if( sContent[i]=='\\' ) { sRet = sContent.Left( i ); break; } } return sRet; } CString CMainFrame::GetLastStr( CString sContent ) { CString sRet; for( int i=sContent.GetLength()-1;i>=0;i-- ) { if( sContent[i]=='\\' ) { sRet = sContent.Right( sContent.GetLength()-i-1 ); break; } } return sRet; } void CMainFrame::InsertToCStringArray( CStringArray &SA,int iInsertIndex,CString sContent,CString sPath ) { CString str; if( sContent.Find(".view")!=-1 ) sContent = sContent.Left( sContent.GetLength()-5 ); CString sParent; if( m_sPath!=sPath ) sParent = sPath.Right( sPath.GetLength()-m_sPath.GetLength() ); if( sParent!="" ) { sContent = sParent+sContent; } bool bExist=false; for( int i=0;i=0;i-- ) { str = SA.GetAt( i ); if( str.Find( s1 )==0 ) { nInsert = i+1; break; } } SA.InsertAt( nInsert,sContent ); } } void CMainFrame::FileSearchCHN( CStringArray &SA,CStringArray &SATemp,int iInsertIndex, CString strPath, CString strFileName, int nLayer ) { long hfile; struct _finddata_t fFile; CString strCurr = strPath + strFileName; // + "\\" + CString sIndex,sContent; int nDone=0; int nTime = 0; hfile = _findfirst( (char *)(LPCTSTR)strCurr, &fFile ); if( -1L != hfile ) { while( !( nDone = _findnext(hfile, &fFile) ) ) { if( !strcmp(fFile.name,"..") ) continue; if( (_A_SUBDIR == fFile.attrib) ) { strCurr = strPath + "\\" + fFile.name + "\\"; int nPos = strCurr.Find("\\\\"); if( nPos!=-1 ) { strCurr.Delete( nPos ); } CString str = fFile.name; sContent = str; InsertToCStringArray( SA,iInsertIndex,sContent,strPath ); //////////////////////////////////////////////////////////// if( sContent.Find(".view")!=-1 ) sContent = sContent.Left( sContent.GetLength()-5 ); CString sParent; if( m_sPath!=strPath ) sParent = strPath.Right( strPath.GetLength()-m_sPath.GetLength() ); if( sParent!="" ) { sContent = sParent+sContent; } SATemp.Add( sContent ); //////////////////////////////////////////////////////////// iInsertIndex++; FileSearchCHN( SA,SATemp,iInsertIndex, strCurr, "*.*", nLayer + 1); if( g_bStartRun ) { CString sPath = strCurr; int nPos = sPath.Find("*"); if( nPos!=-1 ) { sPath = sPath.Left( sPath.GetLength()-3 ); } sPath = sPath+".view"; nPos = sPath.Find("\\."); if( nPos!=-1 ) { sPath.Delete( nPos ); } } } else { CString str = fFile.name; if( str.Right(4).Compare("view") ) continue; CString strTemp = str.Left(str.GetLength()-5); if( !DirSearch(strPath + "\\", strTemp ) ) { sContent = str; InsertToCStringArray( SA,iInsertIndex,sContent,strPath ); iInsertIndex++; //////////////////////////////////////////////////////////// CString str; if( sContent.Find(".view")!=-1 ) sContent = sContent.Left( sContent.GetLength()-5 ); CString sParent; if( m_sPath!=strPath ) sParent = strPath.Right( strPath.GetLength()-m_sPath.GetLength() ); if( sParent!="" ) { sContent = sParent+sContent; } SATemp.Add( sContent ); //////////////////////////////////////////////////////////// } } } _findclose(hfile); } } //交换机 //服务器 //服务器\1号服务器 //服务器\1号服务器\1号服务器 //服务器\1号服务器\2号服务器 //服务器\1号服务器\3号服务器 //服务器\2号服务器 //服务器\2号服务器\1号服务器 //服务器\2号服务器\2号服务器 //a void CMainFrame::AddViewToTree( HTREEITEM hItem, CStringArray &SA ) { HTREEITEM hRoot; HTREEITEM hTemp[10]; HTREEITEM hItemInsert=hItem; hRoot = hItem; hTemp[0] = hItem; int nSize = SA.GetCount(); int nLevel1=0,nLevel2=0; CString sView,sPath,sTemp; for( int i=0;i0 ) sView = GetLastStr( sView ); hItem = m_wndTree.InsertItem(sView, 1, 1, hItemInsert); hTemp[nLevel2] = hItem; if( nLevel1!=nLevel2 ) nLevel1 = nLevel2; sPath = m_sPath + sTemp+".view"; int nInsertIndex=0; if( !GetPicIndexByPicPath( nInsertIndex,sPath ) ) { InsertPicPathToStruct( nInsertIndex,sPath ); //LOG4C((LOG_NOTICE, "画面%d:%s", nInsertIndex,sPath)); } } } void CMainFrame::FileSearch(HTREEITEM hItem, CString strPath, CString strFileName, int nLayer) { long hfile; struct _finddata_t fFile; CString strCurr = strPath + strFileName; // + "\\" + HTREEITEM hTemp = hItem; int nDone=0; int nTime = 0; hfile = _findfirst( (char *)(LPCTSTR)strCurr, &fFile ); if( -1L != hfile ) { while( !( nDone = _findnext(hfile, &fFile) ) ) { if( !strcmp(fFile.name,"..") ) continue; if( (_A_SUBDIR == fFile.attrib) ) { strCurr = strPath + "\\" + fFile.name + "\\"; int nPos = strCurr.Find("\\\\"); if( nPos!=-1 ) { strCurr.Delete( nPos ); } CString str = fFile.name; HTREEITEM hReturn = hItem; hItem = m_wndTree.InsertItem(str, 1, 1, hItem); FileSearch(hItem, strCurr, "*.*", nLayer + 1); hItem = hReturn; if( g_bStartRun ) { CString sPath = strCurr; int nPos = sPath.Find("*"); if( nPos!=-1 ) { sPath = sPath.Left( sPath.GetLength()-3 ); } sPath = sPath+".view"; nPos = sPath.Find("\\."); if( nPos!=-1 ) { sPath.Delete( nPos ); } int nInsertIndex=0; if( !GetPicIndexByPicPath( nInsertIndex,sPath ) ) { InsertPicPathToStruct( nInsertIndex,sPath ); //LOG4C((LOG_NOTICE, "画面%d:%s", nInsertIndex,sPath)); } } } else { CString str = fFile.name; if( str.Right(4).Compare("view") ) continue; CString strTemp = str.Left(str.GetLength()-5); if( !DirSearch(strPath + "\\", strTemp ) ) { m_wndTree.InsertItem(strTemp, 1, 1, hTemp); } //m_wndTree.SortChildren( hItem ); if( g_bStartRun ) { CString sPath = strPath; int nPos = sPath.Find("*"); if( nPos!=-1 ) { sPath = sPath.Left( sPath.GetLength()-3 ); } sPath = sPath+strTemp+".view"; int nInsertIndex=0; if( !GetPicIndexByPicPath( nInsertIndex,sPath ) ) { InsertPicPathToStruct( nInsertIndex,sPath ); //LOG4C((LOG_NOTICE, "画面%d:%s", nInsertIndex,sPath)); } } } } _findclose(hfile); } } // 删除目录 void CMainFrame::DeleteDirectory(CString strDir) { if(strDir.IsEmpty()) { RemoveDirectory(strDir); return; } // 首先删除文件及子文件夹 CFileFind ff; BOOL bFound = ff.FindFile(strDir+"\\*", 0); while(bFound) { bFound = ff.FindNextFile(); if(ff.GetFileName()=="."||ff.GetFileName()=="..") continue; // 去掉文件(夹)只读等属性 SetFileAttributes(ff.GetFilePath(), FILE_ATTRIBUTE_NORMAL); if(ff.IsDirectory()) { // 递归删除子文件夹 DeleteDirectory(ff.GetFilePath()); RemoveDirectory(ff.GetFilePath()); } else { DeleteFile(ff.GetFilePath()); // 删除文件 } } ff.Close(); // 然后删除该文件夹 if (!RemoveDirectory(strDir)) { //ff.Close(); //Sleep( 1000 ); RemoveDirectory(strDir); } } void CMainFrame::InitTreeInfo(void) { m_wndTree.SetItemHeight(20); m_wndImageList.DeleteImageList(); m_wndImageList.Create(IDB_LEFT, 16, 1, RGB(255, 0, 255)); m_wndTree.SetImageList(&m_wndImageList, LVSIL_NORMAL); m_wndTree.SetBkColor( RGB(230,241,249) ); m_wndTree.DeleteAllItems(); m_hMonitor = m_wndTree.InsertItem(g_strMoniterSite,0,0); //显示画面 CString strFindPicFile = "*.view"; char szPicDir[MAX_PATH] = {0}; strcpy(szPicDir, g_strDirectory); strcat(szPicDir, "\\"); strcat(szPicDir, _PICTUREDIR); m_sPath.Format( "%s",szPicDir ); //FileSearch(m_hMonitor, szPicDir, "*.*", 0); /////////////////////// strcpy(szPicDir, g_strDirectory); strcat(szPicDir, "\\"); strcat(szPicDir, _PICTUREDIR); strcat(szPicDir, "sort.txt"); CStringArray SA,SATemp; if( PathFileExists( szPicDir ) ) { CString sTemp,strTemp1,strTemp2,sTemp2; CStdioFile File; if(!File.Open(szPicDir,CFile::modeRead)) File.Open(szPicDir,CFile::modeCreate|CFile::modeRead); while(File.ReadString(sTemp)) { SA.Add( sTemp ); } File.Close(); } strcpy(szPicDir, g_strDirectory); strcat(szPicDir, "\\"); strcat(szPicDir, _PICTUREDIR); FileSearchCHN( SA,SATemp,0, szPicDir, "*.*", 0); CString sShow,s; for( int i=0;i=0;i-- ) { str1 = SA.GetAt(i); for( int j=0;j注销",dlg.m_sUserID ); CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_LOGOUT,0,"",(char *)(LPCTSTR)sContent ); } #endif if (g_bRun ) { } if( m_pDlgZuTaiAdd ) { delete m_pDlgZuTaiAdd; m_pDlgZuTaiAdd = NULL ; } int i; for( i = 0; i < MAX_VIEW_NUM; i++ ) { if( m_pViewIDE[ i ] ) { ::SendMessage(m_pViewIDE[ i ]->m_hWnd, WM_CLOSE, 0, 0 ); m_pViewIDE[ i ] = NULL; } } #if USE_NEWTOP if( g_bRun && g_nToolbarRun ) { if( m_pToolBar ) delete m_pToolBar; m_pToolBar = NULL ; } #else if( g_bRun && g_nToolbarRun ) { if( m_wndOfTop ) delete m_wndOfTop; m_wndOfTop = NULL ; } #endif CMDIAutoHideFrame::OnClose(); } else { ShowWindow(SW_HIDE); } } void CMainFrame::OnDestroy() { if( g_nIsPoll == 1 ) { #if VIEW_USE_THREAD if( m_hViewPollThread != NULL ) { MTVERIFY( WaitForSingleObject( m_hViewPollThread, INFINITE ) != WAIT_FAILED ); MTVERIFY( CloseHandle( m_hViewPollThread ) ); m_hViewPollThread = NULL; } #else KillTimer(1); #endif } CMDIAutoHideFrame::OnDestroy(); // TODO: 在此处添加消息处理程序代码 int i; for( i = 0; i < MAX_VIEW_NUM; i++ ) { if( m_pViewIDE[ i ] ) { ::SendMessage(m_pViewIDE[ i ]->m_hWnd, WM_DESTROY, 0, 0 ); m_pViewIDE[ i ] = NULL; } } } BOOL CMainFrame::FindTreeItem(HTREEITEM hSrcItem, HTREEITEM hDestItem) { HTREEITEM hItem = m_wndTree.GetParentItem( hSrcItem ); while( hItem != NULL ) { if( hItem == hDestItem ) return TRUE; hItem = m_wndTree.GetParentItem( hItem ); } return FALSE; } int CMainFrame::ShowDevProperty(HTREEITEM hSelectedItem) { CString strOldUid, strNewUid; int i, j; int nChannelIndex = -1, nDeviceIndex = -1; Invalidate(FALSE); return 0; } bool CMainFrame::ShowView(void) { HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem(); HTREEITEM hItem; int i; m_hCurrent = hSelectedItem; //如果是视图 char szPicDir[MAX_PATH] = {0}; CString strTempDir = "", strPicFile; strcpy(szPicDir, g_strDirectory); strcat(szPicDir, "\\"); strcat(szPicDir, _PICTUREDIR); hItem = m_wndTree.GetParentItem( hSelectedItem ); while( hItem != NULL ) { if( hItem == m_hMonitor ) { CString strSelect = m_wndTree.GetItemText( hSelectedItem ); if( !strTempDir.Compare("") ) { strPicFile += strSelect; } else { strPicFile += strTempDir; //strPicFile += "\\";//chn modify 12.28 strPicFile += strSelect; } AddIDEView( strSelect, CString(szPicDir) + strPicFile + ".view" ); return true; } else { CString str = m_wndTree.GetItemText( hItem ); strTempDir = str + "\\" + strTempDir; hItem = m_wndTree.GetParentItem( hItem ); } } // 如果是脚本 for (i = 0; i < MAX_SCRIPT_NUM; i++) { if (m_hScriptGroup[i] == hSelectedItem) { CString scriptFile; scriptFile = _SCRIPTDIR; scriptFile = g_strDirectory + CString("\\") + scriptFile + m_wndTree.GetItemText(hSelectedItem) + ".srp"; CString strScript; strScript.Format("%s\\ScriptEdit.exe", g_strDirectory); ShellExecute(NULL,"open", (char *)(LPCTSTR)strScript, scriptFile, NULL, SW_SHOWNORMAL); return true; } } // 系统参数 if (hSelectedItem == m_hSystem) { SetRunPara(); } // 变量编辑 else if (m_hAnalog == hSelectedItem) { } else // 设备属性设置xs { if( g_nIsDemo == 0 ) { int nRet = ShowDevProperty(hSelectedItem); if( nRet == 1 ) { if( hSelectedItem ) { // 这里一删除就报异常,只能先注释,待解决 for Jesse 100106 //m_wndTree.DeleteItem( m_hCurrent );//hSelectedItem } } } } return true; } BOOL CMainFrame::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) { // TODO: 在此添加专用代码和/或调用基类 LPNMHDR pNmhdr = (LPNMHDR)lParam; int i, j; //if( m_bShutdown ) return FALSE; //chn dele int idCtrl = LOWORD(wParam); if( idCtrl == IDD_TREE_LEFT ) // Is my tree's id? { CPoint point; ::GetCursorPos(&point); m_wndTree.ScreenToClient(&point); switch( pNmhdr->code ) { case NM_CLICK: { // Get Click item's UINT uFlags; HTREEITEM hItem = m_wndTree.HitTest(point, &uFlags); if((hItem != NULL) && (TVHT_ONITEM & uFlags)) { m_wndTree.SelectItem(hItem); } return true;//Already process the notify } case NM_RCLICK: { // Get RightClick item's if( g_bStartRun ) return true; UINT uFlags; HTREEITEM hItem = m_wndTree.HitTest(point, &uFlags); m_wndTree.SelectItem(hItem); if((hItem != NULL) && (TVHT_ONITEM & uFlags)) { GetCursorPos(&m_mousePoint); HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem(); //新建设备 if( hSelectedItem == m_hIOGroup ) { CMenu menu; menu.LoadMenu(IDR_MENU_ADDDEVICE); menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this); } //删除设备 int nChannelIndex = -1, nDeviceIndex = -1; int nChannelSize = 0;//pDevicesManager->m_channels.GetSize(); // 串口设备属性设置 for (i = 0; i < nChannelSize; i++) { #if 0 // 删除COM时有BUG,待解决 for Jesse 091104 if( m_hSerialGroup[i] == hSelectedItem ) { CMenu menu; menu.LoadMenu(IDR_MENU_DELDEVICE); menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this); return true; } #endif int nDeviceSize = 0;//pDevicesManager->m_channels[i]->m_Devices.GetSize(); for( j = 0; j < nDeviceSize; j++) { if (m_hSerialDev[i][j]==hSelectedItem) { CMenu menu; menu.LoadMenu(IDR_MENU_DELDEVICE); menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this); return true; } if( m_hNetworkDev[j] == hSelectedItem ) { CMenu menu; menu.LoadMenu(IDR_MENU_DELDEVICE); menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this); return true; } } } //新建或删除监控画面 if (hSelectedItem == m_hMonitor) { CMenu menu; menu.LoadMenu(IDR_MENU_ADDVIEW); menu.GetSubMenu(1)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this); } else { if( FindTreeItem( hSelectedItem, m_hMonitor ) ) { CMenu menu; menu.LoadMenu(IDR_MENU_ADDVIEW); menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this); } } //设定脚本 for (i = 0; i < MAX_SCRIPT_NUM; i++) { if (m_hScriptGroup[i] == hSelectedItem) { CMenu menu; menu.LoadMenu(IDR_MENU_SETSCRIPT); menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this); } } //新建脚本 if (hSelectedItem == m_hScript) { CMenu menu; menu.LoadMenu(IDR_MENU_ADDSCRIPT); menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,m_mousePoint.x,m_mousePoint.y,this); } } return true;//Already process the notify } case NM_DBLCLK: { ShowView(); return true; } } return false; // no match } return CMDIAutoHideFrame::OnNotify(wParam, lParam, pResult); } int CMainFrame::GetFreeSerialTreeItem() { CString str; #if 1 for( int i = MAX_SERIAL_NUM-1; i >=0 ; i-- ) { //if( m_hSerialGroup[i] == NULL ) break; str = m_wndTree.GetItemText(m_hSerialGroup[i]); if( str.Compare("") ) { return i+1; } } #else for( int i = 0; i < MAX_SERIAL_NUM; i++ ) { //if( m_hSerialGroup[i] == NULL ) break; str = m_wndTree.GetItemText(m_hSerialGroup[i]); if( !str.Compare("") ) { return i; } } #endif return 0; } int CMainFrame::GetNetworkChannelIndex() { return -1; } int CMainFrame::GetFreeNetworkTreeItem() { CString str; for( int i = 0; i < MAX_NETWORK_NUM; i++ ) { //if( m_hNetworkDev[i] == NULL ) break; str = m_wndTree.GetItemText(m_hNetworkDev[i]); if( !str.Compare("") ) { return i; } } return -1; } int CMainFrame::GetIndexSerialTreeItem(CString strSrc) { CString str; for( int i = 0; i < MAX_SERIAL_NUM; i++ ) { //if( m_hSerialGroup[i] == NULL ) break; str = m_wndTree.GetItemText(m_hSerialGroup[i]); if( !str.Compare(strSrc) ) { return i; } } return -1; } int CMainFrame::GetIndexNetworkTreeItem(CString strSrc) { CString str; for( int i = 0; i < MAX_NETWORK_NUM; i++ ) { //if( m_hNetworkDev[i] == NULL ) break; str = m_wndTree.GetItemText(m_hNetworkDev[i]); if( !str.Compare(strSrc) ) { return i; } } return -1; } int CMainFrame::FinishedAddDevice(int nIsDelete, CString strUid) { return 1; } void CMainFrame::AddDevice() { } void CMainFrame::OnAdddevoce() { // TODO: 在此添加命令处理程序代码 AddDevice(); } void CMainFrame::OnUpdateAdddevoce(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 } void CMainFrame::OnZuTaiAdd() { if( !m_pDlgZuTaiAdd->m_bIsExistExcel ) { MessageBox( "没有安装Excel软件,组态功能不能用!","提示" ); return; } CDlg_Pwd Dlg_Pwd; Dlg_Pwd.m_nShowType = 2; if( Dlg_Pwd.DoModal()!=IDOK ) return; m_pDlgZuTaiAdd->ReadResource(); m_pDlgZuTaiAdd->ShowWindow( SW_SHOW ); } void CMainFrame::OnUpdateZuTaiAdd(CCmdUI *pCmdUI) { } void CMainFrame::OnDeleteport() { // TODO: 在此添加命令处理程序代码 } void CMainFrame::OnUpdateDeleteport(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 } void CMainFrame::OnAddPort() { // TODO: 在此添加命令处理程序代码 } void CMainFrame::OnUpdateAddPort(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 } void CMainFrame::OnAddScript() { // TODO: 在此添加命令处理程序代码 } void CMainFrame::OnUpdateAddScript(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 } void CMainFrame::HideRunBar() { //m_wndRunToolBar.ShowWindow(SW_HIDE); } void CMainFrame::OnAddview() { // TODO: 在此添加命令处理程序代码 CViewNameDlg dlg; if (dlg.DoModal() == IDOK) { if( dlg.m_strViewName.Compare("")==0 ) { MessageBox(g_strMonitorNameIsBlank, g_strTip, MB_ICONINFORMATION); return; } char szPicDir[MAX_PATH] = {0}; CString strTempDir = ""; strcpy(szPicDir, g_strDirectory); strcat(szPicDir, "\\"); strcat(szPicDir, _PICTUREDIR); int cx=GetSystemMetrics(SM_CXSCREEN)-10; int cy=GetSystemMetrics(SM_CYSCREEN)-100; CGraph* pic=new CGraph(CSize(cx, cy)); pic->m_strPicFile = CString(szPicDir); HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem(); HTREEITEM hItem; m_wndTree.InsertItem(dlg.m_strViewName, 1, 1, hSelectedItem); if( hSelectedItem == m_hMonitor ) { pic->m_strPicFile = pic->m_strPicFile + dlg.m_strViewName + ".view"; pic->Store(); } else { hItem = m_wndTree.GetParentItem( hSelectedItem ); while( hItem != NULL ) { if( hItem == m_hMonitor ) { CString strSelect = m_wndTree.GetItemText( hSelectedItem ); if( !strTempDir.Compare("") ) { pic->m_strPicFile += strSelect; } else { pic->m_strPicFile += strTempDir; pic->m_strPicFile += "\\"; pic->m_strPicFile += strSelect; } if( !PathFileExists(pic->m_strPicFile) ) { SECURITY_ATTRIBUTES sa; sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = 0; int nRet = CreateDirectory(pic->m_strPicFile, &sa); if( !nRet ) { MessageBox(g_strCannotCreateDirecitory,g_strTip,MB_ICONWARNING); delete pic; return; } } pic->m_strPicFile = pic->m_strPicFile + "\\" + dlg.m_strViewName + ".view"; pic->Store(); delete pic; return; } else { CString str = m_wndTree.GetItemText( hItem ); strTempDir = str + "\\" + strTempDir; hItem = m_wndTree.GetParentItem( hItem ); } } } delete pic; CString sContent; sContent.Format("添加画面< %s >",dlg.m_strViewName.TrimRight() ); //CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_MONITOR_ADD,0,"",(char *)(LPCTSTR)sContent ); } } void CMainFrame::OnAddview2() { OnAddview(); } void CMainFrame::OnUpdateAddview(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 } void CMainFrame::OnEditSort() { CDlg_EditView dlg; dlg.DoModal(); } void CMainFrame::OnUpdateEditSort(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 } void CMainFrame::OnUpdateAddview2(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 } void CMainFrame::DeleteDev(int nIsHint) { } void CMainFrame::OnDeletedevice() { // TODO: 在此添加命令处理程序代码 DeleteDev(1); } void CMainFrame::OnUpdateDeletedevice(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 pCmdUI->Enable(TRUE); } void CMainFrame::OnDeleteview() { // TODO: 在此添加命令处理程序代码 //删除文件,同时再数状控件中删除 CString strPath, strTemp; CString strPathFile,strPathFolder; HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem(); if( m_hMonitor==hSelectedItem ) { MessageBox(g_strMonitorNameCannotDel, g_strTip, MB_ICONINFORMATION); return; } CString strSelect = m_wndTree.GetItemText( hSelectedItem ); CString strMessage; strMessage.Format(g_strDelView,strSelect); if (MessageBox(strMessage,g_strConfirm,MB_YESNO|MB_ICONQUESTION) == IDNO) return; GetPicPathByTree( hSelectedItem,strTemp ); strPathFile.Format( "%s\\%s%s.view",g_strDirectory,CString(_PICTUREDIR),strTemp.Left( strTemp.GetLength()-1) ); strPathFolder.Format( "%s\\%s%s\0\0",g_strDirectory,CString(_PICTUREDIR),strTemp.Left( strTemp.GetLength()-1) ); if( PathFileExists( strPathFile ) ) { DeleteFile( strPathFile ); m_wndTree.DeleteItem(hSelectedItem); hSelectedItem = NULL; } if( PathFileExists( strPathFolder ) ) { //strPathFolder += "\0\0"; DeleteDirectory( strPathFolder ); //_DeleteFile( strPathFolder,FOF_ALLOWUNDO|FOF_NOCONFIRMATION ); if( hSelectedItem ) m_wndTree.DeleteItem(hSelectedItem); } CString sContent; sContent.Format("删除画面< %s >",strSelect.TrimRight() ); //CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_MONITOR_DELETE,0,"",(char *)(LPCTSTR)sContent ); return; //strPath = g_strDirectory + CString("\\") + CString(_PICTUREDIR); //ffsco o; //o.dirs(1); //查找子目录 //o.find( LPCSTR(strPath), "*.view" ); //ffsco::typeT coo; //ffsco::typeT::iterator it; //HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem(); //if( m_hMonitor==hSelectedItem ) //{ // MessageBox(g_strMonitorNameCannotDel, g_strTip, MB_ICONINFORMATION); // return; //} //CString strSelect = m_wndTree.GetItemText( hSelectedItem ); //CString strMessage; //strMessage.Format(g_strDelView,strSelect); //if (MessageBox(strMessage,g_strConfirm,MB_YESNO|MB_ICONQUESTION) == IDNO) // return; ////文件 //coo = o.co_file(); //for (it = coo.begin(); coo.end() != it; it++) //{ // strTemp = (*it).c_str(); // strPath = strTemp; // strTemp = strTemp.Right( strTemp.GetLength() - strTemp.ReverseFind('\\') - 1 ); // if( !strTemp.Compare(strSelect + ".view") ) // { // CFile::Remove( strPath ); // m_wndTree.DeleteItem(hSelectedItem); // break; // } //} ////目录 //coo = o.co_dir(); //for( it = coo.begin(); coo.end() != it; it++ ) //{ // strTemp = (*it).c_str(); // strPath = strTemp; // int nFind = strTemp.ReverseFind('\\'); // strTemp = strTemp.Left( nFind ); // strTemp = strTemp.Right( strTemp.GetLength() - strTemp.ReverseFind('\\') - 1 ); // if( !strTemp.Compare(strSelect) ) // { // DeleteDirectory( strPath ); // m_wndTree.DeleteItem(hSelectedItem); // break; // } //} //CString sContent; //sContent.Format("删除画面< %s >",strSelect.TrimRight() ); //CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_MONITOR_DELETE,0,"",(char *)(LPCTSTR)sContent ); } void CMainFrame::OnUpdateDeleteview(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 } void CMainFrame::OnModifyViewName() { // TODO: 在此添加命令处理程序代码 CString strNew, strTemp,sViewName; CString strPathFile,strPathFolder; HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem(); if( m_hMonitor==hSelectedItem ) { return; } CString strSelect = m_wndTree.GetItemText( hSelectedItem ); CViewNameDlg dlg; dlg.m_strViewName = strSelect; if (dlg.DoModal() != IDOK) return; GetPicPathByTree( hSelectedItem,strTemp ); strPathFile.Format( "%s\\%s%s.view",g_strDirectory,CString(_PICTUREDIR),strTemp.Left( strTemp.GetLength()-1) ); strPathFolder.Format( "%s\\%s%s\0\0",g_strDirectory,CString(_PICTUREDIR),strTemp.Left( strTemp.GetLength()-1) ); if( PathFileExists( strPathFile ) ) { strTemp = strSelect + ".view"; sViewName = dlg.m_strViewName + ".view"; strNew = strPathFile; strNew.Replace( strTemp,sViewName ); MoveFile( strPathFile,strNew ); m_wndTree.SetItemText( hSelectedItem,dlg.m_strViewName ); hSelectedItem = NULL; } if( PathFileExists( strPathFolder ) ) { strTemp = "\\" + strSelect; sViewName = "\\" + dlg.m_strViewName; strNew = strPathFolder; strNew.Replace( strTemp,sViewName ); CopyDirectory( strPathFolder,strNew ); DeleteDirectory( strPathFolder ); if( hSelectedItem ) m_wndTree.DeleteItem(hSelectedItem); } } void CMainFrame::OnUpdateModifyViewName(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 } void CMainFrame::OnDeletescript() { // TODO: 在此添加命令处理程序代码 HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem(); CFile::Remove( _SCRIPTDIR + m_wndTree.GetItemText(hSelectedItem) + ".srp"); CFile::Remove( _SCRIPTDIR + m_wndTree.GetItemText(hSelectedItem) + ".con"); m_wndTree.DeleteItem(hSelectedItem); int i = 0, nPos = -1; for( i = 0; i < m_nScripts; i++) { if (hSelectedItem == m_hScriptGroup[i]) { nPos = i; } } for( i = nPos; i < m_nScripts; i++) { m_hScriptGroup[i] = m_hScriptGroup[i+1]; } } void CMainFrame::OnUpdateDeletescript(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 } void CMainFrame::OnSetscript() { // TODO: 在此添加命令处理程序代码 HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem(); for (int m = 0; m < 32; m++) { if (m_hScriptGroup[m] == hSelectedItem) { CString conFile; //SetCurrentDirectory(g_CurrentDir); conFile = CString(g_strDirectory) + "\\" + _SCRIPTDIR; conFile = conFile + m_wndTree.GetItemText(hSelectedItem) + ".con"; } } } void CMainFrame::OnUpdateSetscript(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 } void CMainFrame::OnEditscript() { // TODO: 在此添加命令处理程序代码 HTREEITEM hSelectedItem = m_wndTree.GetSelectedItem(); for (int m = 0; m < 32; m++) { if (m_hScriptGroup[m] == hSelectedItem) { CString scriptFile; scriptFile = CString(g_strDirectory) + "\\" + _SCRIPTDIR; scriptFile = scriptFile + m_wndTree.GetItemText(hSelectedItem) + ".srp"; ShellExecute(NULL,"open", "ScriptEdit.exe", scriptFile, NULL, SW_SHOWNORMAL); } } } void CMainFrame::OnUpdateEditscript(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 } void CMainFrame::SetRunPara() { OnSysPara(); } int CMainFrame::GetIDEViewIndex(CString strPath) { int i; for( i = 0; i < MAX_VIEW_NUM; i++ ) { if( !m_pViewIDE[i] ) continue; CString str; str = m_pViewIDE[i]->m_strPath; str.Replace("\\\\", "\\"); strPath.Replace("\\\\", "\\"); if( !str.Compare(strPath) ) { return i; } } return -1; } int CMainFrame::GetIDEViewFreeIndex(CString strPath) { int i; for( i = 0; i < MAX_VIEW_NUM; i++ ) { if( !m_pViewIDE[i] ) return i; if( m_pViewIDE[i]->m_bClose ) continue; if( !m_pViewIDE[i]->m_strPath.Compare("") ) { return i; } } return -1; } void CMainFrame::AddIDEView(CString strDesc, CString strPath) { //如果是当前画面,退出 if( g_strViewName==strPath ) return; g_sCurrentPageName = strDesc; // 打开新的画面,先保存旧的。 CIDEView *pView = (CIDEView *)m_pActiveView; if( pView ) { pView->ChangeView(); } int nIndex = GetIDEViewIndex(strPath); if( nIndex == -1 ) { nIndex = GetIDEViewFreeIndex(strPath); if( nIndex == -1 ) nIndex = 0; CCreateContext context; m_pViewIDE[nIndex] = new CChildFrame; m_pViewIDE[nIndex]->m_strPath = strPath; m_pViewIDE[nIndex]->m_strDesc = strDesc; context.m_pCurrentDoc = m_pDoc; context.m_pNewDocTemplate = m_pDoc->GetDocTemplate(); context.m_pNewViewClass = RUNTIME_CLASS( CIDEView ); context.m_pCurrentFrame = this; context.m_pLastView = NULL; if( !m_pViewIDE[nIndex]->LoadFrame(IDI_SUMMARY, WS_MAXIMIZE|WS_OVERLAPPEDWINDOW, this, &context) ) { return; } m_pViewIDE[nIndex]->ShowWindow(SW_SHOWMAXIMIZED); m_pViewIDE[nIndex]->InitialUpdateFrame(m_pDoc,true); m_pViewIDE[nIndex]->MDIActivate(); m_nViewCount++; } else { m_pActiveView = (CFormView *)m_pViewIDE[nIndex]->GetActiveView(); m_pViewIDE[nIndex]->MDIActivate(); } m_pViewIDE[ nIndex ]->m_bClose = FALSE; m_pActiveView = (CFormView *)m_pViewIDE[nIndex]->GetActiveView(); g_strViewName = strPath; ((CIDEView *)m_pActiveView)->ChangeView(); //取当前所有的变量到SA中 GetCurPicVarToSArray( strPath ); /////////////////////把当前画面名保存到C:\\PageName.txt中,给视频用/////////////////////////////////// CString sPath = "C:\\PageName.txt"; DeleteFile( sPath ); CString strTemp; CStdioFile MyFile; CFileException e; if ( MyFile.Open(sPath,CFile::modeCreate|CFile::modeWrite,&e) ) { strTemp.Format("%s\n",strDesc); MyFile.SeekToEnd(); MyFile.WriteString(strTemp); MyFile.Close(); } } void CMainFrame::OnUsers() { } void CMainFrame::OnEditPwdTool() { if( g_nIsDemo == 0 ) { CDlgEditPwd dlg; if( dlg.DoModal() == IDOK ) { CString sContent; sContent.Format("%s%s",g_strEdit,g_strPwd ); //CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_PWD_EDIT,0,"",(char *)(LPCTSTR)sContent ); } } } void CMainFrame::OnSysPara() { CSystemParaSetDlg dlg; dlg.m_bStartRun = g_bStartRun; dlg.m_bAlarmVoice = g_bAlarmVoice; dlg.m_bEventAlarm = g_bEventAlarm; dlg.m_bHideTask = g_bHideTask; dlg.m_strStartPic = g_strStartPic; dlg.m_strStartPath = g_strStartPath; if ( dlg.DoModal() == IDOK ) { #if 0 //程序退出之前不改变状态 g_bStartRun = dlg.m_bStartRun; #endif //int nPos = dlg.m_strStartPath.Find("\\\\"); //if( nPos!=-1 ) //{ // dlg.m_strStartPath.Delete( nPos ); //} // //int nLen = dlg.m_strStartPath.GetLength(); //nPos = dlg.m_strStartPath.Find("view"); //CString sTemp; //if( nPosEnable(m_bEvent); } void CMainFrame::OnUpdateSystemLog(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->Enable(m_bSystemLog); } void CMainFrame::OnUpdateNoticeRec(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->Enable(m_bNoticeRec); } void CMainFrame::OnUpdateUsers(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->Enable(m_bUsers); } void CMainFrame::OnUpdateEditPwd(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->Enable(m_bEditPwd); } void CMainFrame::OnUpdateSysPare(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->Enable(m_bSysPare); } void CMainFrame::OnUpdateSingleAnalog(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->Enable(m_bAnalog); } void CMainFrame::OnUpdatePrint(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->Enable(m_bPrint); } void CMainFrame::OnSummaryLog() { if( g_nIsDemo == 0 ) { #if 0 CDlgQuerySummaryLog dlg; if( dlg.DoModal() == IDOK ) { } #endif CString sIDE,sReport; sIDE.Format( "%s",g_strDirectory ); int nEnd = 0; for (int i = sIDE.GetLength()-1; i >= 0; i--) { if (g_strDirectory[i] == '\\') { nEnd = i; break; } } sReport = sIDE.Left( nEnd ) + "\\report"; CString strFileName; strFileName.Format("%s\\DBMonitorReport.exe", sReport); ShellExecute(0, "open", strFileName, NULL, NULL, SW_SHOWNORMAL); } } void CMainFrame::OnUpdateSummaryLog(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->Enable(m_bDeviceLog); } void CMainFrame::StoreRunPara(BOOL bStartRun) { char Path[_MAX_PATH] = {0}; strcat(Path, g_strDirectory); strcat(Path,"\\"); strcat(Path, _PROJECTDIR); strcat(Path,"\\"); strcat(Path, "runpara.ini"); if ( bStartRun ) { WritePrivateProfileString("RUNPARA", "STARTRUN", "1", Path); } else { WritePrivateProfileString("RUNPARA", "STARTRUN", "0", Path); } if ( g_bEventAlarm ) { WritePrivateProfileString("RUNPARA", "ALARM", "1", Path); } else { WritePrivateProfileString("RUNPARA", "ALARM", "0", Path); } if ( g_bAlarmVoice ) { WritePrivateProfileString("RUNPARA", "VOICE", "1", Path); } else { WritePrivateProfileString("RUNPARA", "VOICE", "0", Path); } if ( g_bHideTask ) { WritePrivateProfileString("RUNPARA", "HIDETASK", "1", Path); } else { WritePrivateProfileString("RUNPARA", "HIDETASK", "0", Path); } if ( g_bFullScreen ) { WritePrivateProfileString("RUNPARA", "FULLSCREEN", "1", Path); } else { WritePrivateProfileString("RUNPARA", "FULLSCREEN", "0", Path); } WritePrivateProfileString("RUNPARA", "STARTPIC", g_strStartPic, Path); WritePrivateProfileString("RUNPARA", "STARTPATH", g_strStartPath, Path); } // 存储事件参数 void CMainFrame::StoreEventPara() { char Path[_MAX_PATH] = {0}; strcat(Path, g_strDirectory); strcat(Path,"\\"); strcat(Path, _PROJECTDIR); strcat(Path,"\\"); strcat(Path, "event.ini"); if ( g_bControlEvent ) { WritePrivateProfileString("IFALARM", "CONTROL", "1", Path); } else { WritePrivateProfileString("IFALARM", "CONTROL", "0", Path); } if ( g_bLoginEvent ) { WritePrivateProfileString("IFALARM", "LOGIN", "1", Path); } else { WritePrivateProfileString("IFALARM", "LOGIN", "0", Path); } if ( g_bSetEvent ) { WritePrivateProfileString("IFALARM", "SET", "1", Path); } else { WritePrivateProfileString("IFALARM", "SET", "0", Path); } if ( g_bReguEvent ) { WritePrivateProfileString("IFALARM", "REGU", "1", Path); } else { WritePrivateProfileString("IFALARM", "REGU", "0", Path); } if ( g_bYxChangeEve ) { WritePrivateProfileString("IFALARM", "YXCHANGE", "1", Path); } else { WritePrivateProfileString("IFALARM", "YXCHANGE", "0", Path); } if ( g_bYcEvent ) { WritePrivateProfileString("IFALARM", "YCOVERLIMIT", "1", Path); } else { WritePrivateProfileString("IFALARM", "YCOVERLIMIT", "0", Path); } WritePrivateProfileString("WAVEFILE", "CONTROL", g_strYkWave, Path); WritePrivateProfileString("WAVEFILE", "LOGIN", g_strLoginWave, Path); WritePrivateProfileString("WAVEFILE", "SET", g_strSetWave, Path); WritePrivateProfileString("WAVEFILE", "REGU", g_strReguWave, Path); WritePrivateProfileString("WAVEFILE", "YXCHANGE", g_strYxChangeWave, Path); WritePrivateProfileString("WAVEFILE", "YCOVERLIMIT", g_strYcWave, Path); } void CMainFrame::OnControldialog() { CRect rctDlg; int screenx = GetSystemMetrics(SM_CXSCREEN); int screeny = GetSystemMetrics(SM_CYSCREEN); m_dlgControl->GetWindowRect(&rctDlg); m_dlgControl->SetWindowPos(&wndTop, screenx - rctDlg.Width(), screeny - rctDlg.Height(), rctDlg.Width(), rctDlg.Height(), SWP_NOZORDER); m_dlgControl->ShowWindow(SW_SHOW); } void CMainFrame::OnTimer(UINT nIDEvent) { // TODO: 在此添加消息处理程序代码和/或调用默认值 if( nIDEvent == 1 ) { if (g_bStartRun && g_nIsPoll == 1) { for( int i = 0; i < g_nPollCount; i++ ) { if( g_dwTick == 0 ) { if( g_nPollIndex == i ) { g_dwTick = GetTickCount(); TRACE("Enter AddIDEView %s, %s\r\n", g_strPollPath, g_strPollDesc); AddIDEView(g_strPollDesc[i], g_strPollPath[i]); TRACE("Leave AddIDEView\r\n"); } } else if( GetTickCount() - g_dwTick > (DWORD)g_nPollInterval * 1000 ) { if( g_nPollIndex == g_nPollCount - 1 ) { g_nPollIndex = 0; } else { g_nPollIndex++; } g_dwTick = 0; } } } } if( nIDEvent==2 )//定时得到狗信息/定时判断是否过期 { } CMDIAutoHideFrame::OnTimer(nIDEvent); } void CMainFrame::OnUserManager() { // TODO: 在此添加命令处理程序代码 } void CMainFrame::OnGroupManager() { // TODO: 在此添加命令处理程序代码 } void CMainFrame::OnEditPwd() { // TODO: 在此添加命令处理程序代码 CDlgEditPwd dlg; if( dlg.DoModal() == IDOK ) { CString sContent; sContent.Format("修改密码"); //CDBInterface::GetInstancePtr()->InsertLogRecord( LOG_PWD_EDIT,0,"",(char *)(LPCTSTR)sContent ); } } void CMainFrame::OnSingleAnalog() { // TODO: 在此添加命令处理程序代码 } LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { // TODO: 在此添加专用代码和/或调用基类 switch( message ) { case WM_MY_NEW_ALERT: { CString sPath; CString sVarName = (char *)wParam; //LOG4C((LOG_NOTICE, "报警变量:%s", sVarName)); if( GetPicPathByVarName( sPath,sVarName ) ) { int nPos1=0,nPos2=0; for( int i=sPath.GetLength()-1;i>0;i-- ) { if( sPath[i]=='\\' ) { nPos1 = i; break; } } for( int i=sPath.GetLength()-1;i>0;i-- ) { if( sPath[i]=='.' ) { nPos2 = i; break; } } CString sName = sPath.Mid( nPos1+1,nPos2-nPos1-1 ); AddIDEView( sName,sPath ); } //LOG4C((LOG_NOTICE, "报警画面:%s", sPath)); } break; case WM_MY_SIZECHANGE: { CString str; str.Format( "%d,%d",wParam,lParam ); } break; case WM_MY_SIZECHANGE2: { #if USE_NEWTOP CString str; str.Format( "%d,%d",wParam,lParam ); m_pToolBar->SetPos( wParam,lParam ); #endif } break; } return CMDIAutoHideFrame::WindowProc(message, wParam, lParam); } bool CMainFrame::GetPicIndexByPicPath( int &iIndex,CString sPicPath ) { bool bRet=false; for( int i=0;i= '0' && chr <= '9') return TRUE; else if ((chr >= 'A' && chr <= 'Z') || (chr >= 'a' && chr <= 'z') ) return TRUE; else if (chr == '_') return TRUE; else return FALSE; } //从组合公式中找出变量名加入到画面结构中 void CMainFrame::GetVarFromGSAddToStruct( int iIndex,CString sGS ) { //LOG4C((LOG_NOTICE, "GetVarFromGSAddToStruct sGS :%s", sGS)); //sGS = "(HG7053_DI10>=3)OR(HG7053_LinkStatus<=33)"; //sGS = "((HG7053_DI10>=3))"; //sGS = "(HG7053_DI10>=3)AND(HG7053_LinkStatus<=33)OR(HG7053_DI15<3)"; int nLen = sGS.GetLength(); int nPos1=0,nPos2=0; int nPos3=0,nPos4=0; CString sTemp,s1,s2,s3; CString sGS2[100]; int nCount=0; //OR AND NOT for( int i=0;i> m_Type; ar >> m_sizePic; ar >> m_sizeGrid; ar >> m_bGrid; ar >> m_clrBack; _ObjList.Serialize(ar); if( !_ObjList.IsEmpty() ) { for(POSITION pos = _ObjList.GetHeadPosition();pos!=NULL;) { POSITION pos1 = pos ; CDrawObj *ct = (CDrawObj *)_ObjList.GetNext(pos); int nInsert=0; if( ct->m_bVariant && ct->m_strCaption!="" && !VarIsExistInPic( iIndex,ct->m_strCaption,nInsert ) ) m_PIC_VAR[iIndex].sCaption[nInsert] = ct->m_strCaption; if( ct->m_strDynShow!="" ) GetVarFromGSAddToStruct( iIndex,ct->m_strDynShow ); if( ct->m_strDynForeCon!="" ) GetVarFromGSAddToStruct( iIndex,ct->m_strDynForeCon ); if( ct->m_strDynBackCon!="" ) GetVarFromGSAddToStruct( iIndex,ct->m_strDynBackCon ); if( ct->m_strDynLineCon!="" ) GetVarFromGSAddToStruct( iIndex,ct->m_strDynLineCon ); if( ct->m_strHoriPos!="" ) GetVarFromGSAddToStruct( iIndex,ct->m_strHoriPos ); if( ct->m_strHoriSize!="" ) GetVarFromGSAddToStruct( iIndex,ct->m_strHoriSize ); if( ct->m_strVertiPos!="" ) GetVarFromGSAddToStruct( iIndex,ct->m_strVertiPos ); if( ct->m_strVertiSize!="" ) GetVarFromGSAddToStruct( iIndex,ct->m_strVertiSize ); if( ct->m_strCurrentCaption!="" ) GetVarFromGSAddToStruct( iIndex,ct->m_strCurrentCaption ); if( ct->IsKindOf( RUNTIME_CLASS(CDrawBitmap) ) ) { if( ((CDrawBitmap *)ct)->m_strDynCondition!="" ) GetVarFromGSAddToStruct( iIndex,((CDrawBitmap *)ct)->m_strDynCondition ); } if( ct->IsKindOf( RUNTIME_CLASS(CDrawGif) ) ) { if( ((CDrawGif *)ct)->m_strDynCondition!="" ) GetVarFromGSAddToStruct( iIndex,((CDrawGif *)ct)->m_strDynCondition ); } } } /////////////////////////////////////// ar.Close(); file.Close(); } if(!_ObjList.IsEmpty()) { for(POSITION pos = _ObjList.GetHeadPosition();pos!=NULL;) { POSITION pos1 = pos ; CDrawObj *ct = (CDrawObj *)_ObjList.GetNext(pos); _ObjList.RemoveAt(pos1); delete ct; } _ObjList.RemoveAll(); ASSERT(_ObjList.IsEmpty()); } } //查找这个画面结构里是否已经有这个变量 bool CMainFrame::VarIsExistInPic( int iIndex,CString sVarName,int &iInsertIndex ) { bool bRet=false; for( int j=0;j<1000;j++ ) { if( m_PIC_VAR[iIndex].sCaption[j]=="" ) { iInsertIndex = j; break; } //if( -1 != m_PIC_VAR[iIndex].sCaption[j].Find( sVarName ) ) if( m_PIC_VAR[iIndex].sCaption[j] == sVarName ) { bRet = true; break; } } return bRet; } void CMainFrame::GetCurPicVarToSArray( CString sPicPath ) { //LOG4C((LOG_NOTICE, "开始获取 当前画面%s 变量", sPicPath)); for( int i=0;i