📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "FLADS.h"
#include "editcmd.h"
#include "MainFrm.h"
#include "LogonDlg.h"
#include "UserManger.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CFLADSApp theApp;
extern BOOL BeginPid();
extern BOOL EndPid();
extern BOOL BeginWarn();
extern BOOL EndWarn();
// Array tbSTDButton contains relevant buttons of bitmap IDB_STD_SMALL_COLOR
static TBBUTTON tbButtons[] =
{
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0},
{0, ID_FILE_NEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
{1, ID_FILE_OPEN, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
{2, ID_FILE_SAVE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, -1},
{3, ID_EDIT_CUT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
{4, ID_EDIT_COPY, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
{5, ID_EDIT_PASTE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, -1},
{6, ID_APP_ABOUT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, -1},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0}
};
const int nNumButtons = sizeof(tbButtons)/sizeof(TBBUTTON);
const int nNumImages = 7;
const DWORD dwAdornmentFlags = 0; // exit button
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_TIMER,
ID_INDICATOR_POSITION,
ID_INDICATOR_TYPE,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_COMMAND(ID_APP_EXIT, OnAppExit)
ON_MESSAGE(WM_FLASHPLC, OnFlashPlc)
ON_WM_TIMER()
ON_COMMAND(IDC_LOGON, OnLogon)
ON_COMMAND(IDC_USER_MANGER, OnUserManger)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
pFladsView=NULL;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// Add the buttons and adornments to the CommandBar.
if (!AddAdornments(dwAdornmentFlags))
{
TRACE0("Failed to add toolbar buttons\n");
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 (!InsertButtons(tbButtons, nNumButtons, IDR_MAINFRAME, nNumImages) ||
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
}
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
theApp.InitLoadBitmap();
theApp.comm.InitCom1();
theApp.comm.InitCom2();
if(BeginPid()==false)
{
AfxMessageBox(_T("serial fail"));
}
if(BeginWarn()==false)
{
AfxMessageBox(_T("Warn fail"));
}
theApp.ReadResentFile();//\\DiskC\\Resent.dat
theApp.LoadPWData();
theApp.LoadPara(theApp.pidfilename);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
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::OnDestroy()
{
CFrameWnd::OnDestroy();
// TODO: Add your message handler code here
EndWarn();
EndPid();
theApp.comm.CloseCom1();
theApp.comm.CloseCom2();
}
BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if (wParam == IDCANCEL)
{
return FALSE;
}
if (wParam == IDOK)
{
return FALSE;
}
return CFrameWnd::OnCommand(wParam, lParam);
}
void CMainFrame::OnAppExit()
{
// TODO: Add your command handler code here
if(theApp.m_UserPower.KeepTime>0)
{
if( theApp.m_UserPower.Operators[theApp.m_UserPower.CurOperatorid].exit_enable!=0)
{
PostMessage(WM_CLOSE);
}else
{
AfxMessageBox(_T("无此权限!"));
}
}else
{//请登录
CMainFrame* m_pMainWnd=(CMainFrame*)AfxGetMainWnd();
m_pMainWnd->SendMessage(WM_COMMAND,IDC_LOGON);
}
/*
unsigned int CurOperatorid; //当前正在操作的操作员编码
unsigned short CurOperatorName[20]; //当前正在操作的操作员名
double KeepTime; //密码维持时间(单位:分)
OPERATORS Operators[OPERATORMAX]; //50 个用户
if(theApp.pass_exit==888)
{
PostMessage(WM_CLOSE);
}else
{
CLogonDlg dlg;
theApp.logontype=2;
dlg.DoModal();
}
if(theApp.pass_exit==888)
{
PostMessage(WM_CLOSE);
}
*/
}
void CMainFrame::OnFlashPlc()
{
}
void CMainFrame::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(theApp.flash_plc_flag!=0)
{
if(pFladsView!=NULL)
{
pFladsView->PostMessage(WM_FLASHPLC);
}
theApp.flash_plc_flag=0;
}
CFrameWnd::OnTimer(nIDEvent);
}
void CMainFrame::OnLogon()
{// 请登录
// TODO: Add your command handler code here
CLogonDlg dlg(this);
dlg.DoModal();
}
void CMainFrame::OnUserManger()
{// 用户管理
// TODO: Add your command handler code here
CUserManger dlg(this);
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -