📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "DataSvr.h"
#include "MainFrm.h"
#include "Splash.h"
#include "glovar.h"
#include "DataSvrDoc.h"
#include "DataSvrView.h"
#include "ParaModeFormView.h"
#include "RtlLeftTopView.h"
#include "RtlRightView.h"
#include "ruler.h"
#include "batchmodidlg.h"
#include "OptionSheet.h"
#include "historyform.h"
#include "rwsock.h"
#include "lsock.h"
//#include "service.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define WM_TRAYICON ( WM_USER + 100 )
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_MESSAGE(WM_TRAYICON, OnTrayIconNotify)
ON_WM_INITMENUPOPUP()
ON_MESSAGE(WM_SYSCOMMAND, OnSysCommand)
ON_MESSAGE(CLT_CLOSE,OnClientClose)
ON_WM_MENUSELECT()
ON_UPDATE_COMMAND_UI(ID_INDICATOR_TIME, OnUpdateTime)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_QUERYENDSESSION()
ON_WM_ENDSESSION()
ON_WM_DESTROY()
ON_WM_SIZE()
ON_COMMAND(ID_TRAYICON_ACTIVE, OnTrayiconActive)
ON_UPDATE_COMMAND_UI(ID_TRAYICON_ACTIVE, OnUpdateTrayiconActive)
ON_COMMAND(IDM_TEST, OnTest)
ON_COMMAND(ID_VIEW_BRINGTOTOP, OnViewBringtotop)
ON_UPDATE_COMMAND_UI(ID_VIEW_BRINGTOTOP, OnUpdateViewBringtotop)
ON_COMMAND(IDM_YB, OnYb)
ON_COMMAND(IDM_CD, OnCd)
ON_COMMAND(IDM_CS, OnCs)
ON_COMMAND(IDM_RT, OnRt)
ON_WM_TIMER()
ON_COMMAND(IDM_CSRW, OnCsrw)
ON_COMMAND(ID_VIEW_OPTION, OnViewOption)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// CG: The following block was inserted by 'Status Bar' component.
{
m_nStatusPane1Width = -1;
m_bMenuSelect = FALSE;
}
m_bSplitterCreated=FALSE;
m_bTopMost=FALSE;
m_bOptionSheetActive=FALSE;
}
CMainFrame::~CMainFrame()
{
}
extern CLSock * m_LSock;
void CMainFrame::OnClientClose(WPARAM wParam, LPARAM lParam)
{
CRWSock *psock;
psock=(CRWSock*)wParam;
m_LSock->CloseSocket(psock);
return ;
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
// CG: The following block was inserted by 'Status Bar' component.
{
// Find out the size of the static variable 'indicators' defined
// by AppWizard and copy it
int nOrigSize = sizeof(indicators) / sizeof(UINT);
UINT* pIndicators = new UINT[nOrigSize + 2];
memcpy(pIndicators, indicators, sizeof(indicators));
// Call the Status Bar Component's status bar creation function
if (!InitStatusBar(pIndicators, nOrigSize, 60))
{
TRACE0("Failed to initialize Status Bar\n");
return -1;
}
delete[] pIndicators;
}
m_TrayIcon.Create( this, WM_TRAYICON, "BaoSight_DataSvr", NULL, IDR_TRAYICON_MENU );
m_TrayIcon.SetIcon( IDI_TRAYICON_NORMAL );
// CG: The following line was added by the Splash Screen component. CSplashWnd::ShowSplashScreen(this);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
WNDCLASS wndcls; memset( &wndcls, 0, sizeof( wndcls ) );
HINSTANCE hInst = AfxGetInstanceHandle();
//
// 注册类名为 "BaoSight_DataSvr" 的窗口类
//
if( !::GetClassInfo(hInst, gcszWindowClass, &wndcls) ) {
::GetClassInfo(hInst, cs.lpszClass, &wndcls);
wndcls.style &= ~(CS_HREDRAW|CS_VREDRAW);
wndcls.lpszClassName = gcszWindowClass;
wndcls.hIcon = ::LoadIcon(hInst, MAKEINTRESOURCE(IDR_MAINFRAME));
ASSERT( wndcls.hIcon != NULL );
if( !AfxRegisterClass(&wndcls ) )
AfxThrowResourceException();
}
cs.dwExStyle &= ~( WS_EX_CLIENTEDGE | WS_EX_STATICEDGE );
// 恢复注册表中保存的 TOPMOST 状态
// if( m_bTopMost )
// cs.dwExStyle |= WS_EX_TOPMOST;
cs.lpszName = gcszWindowName;
cs.lpszClass = gcszWindowClass;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
{
CFrameWnd::OnMenuSelect(nItemID, nFlags, hSysMenu);
// CG: The following block was inserted by 'Status Bar' component.
{
// Restore first pane of the statusbar?
if (nFlags == 0xFFFF && hSysMenu == 0 && m_nStatusPane1Width != -1)
{
m_bMenuSelect = FALSE;
m_wndStatusBar.SetPaneInfo(0,
m_nStatusPane1ID, m_nStatusPane1Style, m_nStatusPane1Width);
m_nStatusPane1Width = -1; // Set it to illegal value
}
else
{
m_bMenuSelect = TRUE;
}
}
}
void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
{
CFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
// CG: The following block was inserted by 'Status Bar' component.
{
// store width of first pane and its style
if (m_nStatusPane1Width == -1 && m_bMenuSelect)
{
m_wndStatusBar.GetPaneInfo(0, m_nStatusPane1ID,
m_nStatusPane1Style, m_nStatusPane1Width);
m_wndStatusBar.SetPaneInfo(0, m_nStatusPane1ID,
SBPS_NOBORDERS|SBPS_STRETCH, 16384);
}
}
}
void CMainFrame::OnUpdateTime(CCmdUI* pCmdUI)
{
// CG: This function was inserted by 'Status Bar' component.
// Get current date and format it
CTime time = CTime::GetCurrentTime();
CString strTime = time.Format(_T("%X"));
// BLOCK: compute the width of the date string
CSize size;
{
HGDIOBJ hOldFont = NULL;
HFONT hFont = (HFONT)m_wndStatusBar.SendMessage(WM_GETFONT);
CClientDC dc(NULL);
if (hFont != NULL)
hOldFont = dc.SelectObject(hFont);
size = dc.GetTextExtent(strTime);
if (hOldFont != NULL)
dc.SelectObject(hOldFont);
}
// Update the pane to reflect the current time
UINT nID, nStyle;
int nWidth;
m_wndStatusBar.GetPaneInfo(m_nTimePaneNo, nID, nStyle, nWidth);
m_wndStatusBar.SetPaneInfo(m_nTimePaneNo, nID, nStyle, size.cx);
pCmdUI->SetText(strTime);
pCmdUI->Enable(TRUE);
}
BOOL CMainFrame::InitStatusBar(UINT *pIndicators, int nSize, int nSeconds)
{
// CG: This function was inserted by 'Status Bar' component.
// Create an index for the TIME pane
m_nTimePaneNo = nSize++;
nSeconds = 1;
pIndicators[m_nTimePaneNo] = ID_INDICATOR_TIME;
// TODO: Select an appropriate time interval for updating
// the status bar when idling.
m_wndStatusBar.SetTimer(0x1000, nSeconds * 1000, NULL);
return m_wndStatusBar.SetIndicators(pIndicators, nSize);
}
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
TVisualObject *pMainTabWnd = new TVisualObject(10,"",pContext,RUNTIME_CLASS(TTabWnd),TVisualObject::TOS_TABTOP);
TVisualObject *pRealTimeSpliter = new TVisualObject(2,"实时数据",1,2,pContext);
TVisualObject *pHistoryView = new TVisualObject(3,"历史数据", pContext, RUNTIME_CLASS(CHistoryForm));
// TVisualObject *pWarningView = new TVisualObject(4,"报警信号", pContext, RUNTIME_CLASS(CDataSvrView));
// TVisualObject *pYBView = new TVisualObject(5,"仪表维护", pContext, RUNTIME_CLASS(CParaModeFormView));//CParaModeFormView
// TVisualObject *pCDView = new TVisualObject(6,"测点维护", pContext, RUNTIME_CLASS(CParaModeFormView));
// TVisualObject *pSJCJView = new TVisualObject(7,"数据采集配置", pContext, RUNTIME_CLASS(CParaModeFormView));
// TVisualObject *pYBCSMCView = new TVisualObject(8,"仪表参数名称维护", pContext, RUNTIME_CLASS(CParaModeFormView));
//实时数据采集画面
TVisualObject *pRTLeftView = new TVisualObject(9,0,0,2,1,pContext);
TVisualObject *pRTRightView = new TVisualObject(11,0,1,2,1,pContext);
TVisualObject *pRTLeftTopView = new TVisualObject(12,0,0,pContext,RUNTIME_CLASS(CRtlLeftTopView),CSize(0,0));
TVisualObject *pRTLeftBottonView = new TVisualObject(13,1,0,pContext,RUNTIME_CLASS(CDataSvrView),CSize(0,0));
TVisualObject *pRTRightTopView = new TVisualObject(14,0,0,pContext,RUNTIME_CLASS(CRulerView),CSize(0,0));
TVisualObject *pRTRightBottonView = new TVisualObject(1,1,0,pContext,RUNTIME_CLASS(CRtlRightView),CSize(0,0));
m_Framework.Add(pMainTabWnd);
m_Framework.Add(pMainTabWnd,pRealTimeSpliter);
m_Framework.Add(pMainTabWnd,pHistoryView);
// m_Framework.Add(pMainTabWnd,pWarningView);
// m_Framework.Add(pMainTabWnd,pYBView);
// m_Framework.Add(pMainTabWnd,pCDView);
// m_Framework.Add(pMainTabWnd,pSJCJView);
// m_Framework.Add(pMainTabWnd,pYBCSMCView);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -