📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "Commucation.h"
#include "Passwd.h"
#include "MainFrm.h"
#include "Splash.h"
#include "Login.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_CLOSE()
ON_WM_SHOWWINDOW()
ON_COMMAND(ID_CHANGE_USER, OnChangeUser)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_SEPARATOR,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
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_wndStatusBar.SetPaneInfo(1,IDC_STATUSBAR,SBPS_NOBORDERS,300);
// 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;
// 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::OnClose()
{
// TODO: Add your message handler code here and/or call default
CPasswd m_Dlg;
if(m_Dlg.DoModal()==IDOK)
{
if(m_Dlg.m_password!="123456")
{
AfxMessageBox("口令错误");
return;
}
else
{
CFrameWnd::OnClose();
}
}
else
{
return;
}
}
void CMainFrame::OnShowWindow(BOOL bShow, UINT nStatus)
{
CFrameWnd::OnShowWindow(bShow, nStatus);
// TODO: Add your message handler code here
CStdioFile file;
CString filename,str,duty;
int pos;
filename="C:\\WINDOWS\\SYSTEM\\user.txt";
if(file.Open(filename,CFile::modeReadWrite|CFile::typeText)==0)
{
AfxMessageBox("failure");
}
file.SeekToBegin();
file.ReadString(str);
str.TrimRight("-");
sscanf(str,"%d",&pos);
file.Seek((pos-1)*23,CFile::begin);
file.ReadString(str);
duty=str.Left(3);
str=str.Mid(13,8);
str.TrimRight("-");
str="当班人姓名:"+str;
file.Close();
CMainFrame *MFrame=(CMainFrame *)AfxGetMainWnd();
MFrame->m_wndStatusBar.SetPaneText(1,str);
}
void CMainFrame::OnChangeUser()
{
// TODO: Add your command handler code here
CLogin m_Dlg;
CString str,userid,password,tmpid,tmppasswd,tmpname;
BOOL flag=false;
if(m_Dlg.DoModal()==IDOK)
{
CStdioFile file;
CString filename;
int pos;
filename="C:\\WINDOWS\\SYSTEM\\user.txt";
if(file.Open(filename,CFile::modeReadWrite|CFile::typeText)==0)
{
AfxMessageBox("failure");
}
file.ReadString(str);
file.ReadString(str);
pos=1;
userid=m_Dlg.m_Userid;
password=m_Dlg.m_Password;
tmpid=str.Left(3);
while (tmpid!="end")
{
pos+=1;
tmppasswd=str.Mid(3,10);
tmppasswd.TrimRight("-");
tmpname=str.Mid(13,8);
tmpname.TrimRight("-");
if(tmpid==userid)
{
if(tmppasswd==password)
{
flag=true;
file.SeekToBegin();
CString ttt;
ttt.Format("%d",pos);
int len;
len=ttt.GetLength();
for(int i=0;i<21-len;i++)
ttt=ttt+"-";
file.Write(ttt,21);
file.Close();
filename="Phone.txt";
if(file.Open(filename,CFile::modeReadWrite|CFile::typeText)==0)
{
AfxMessageBox("failure");
}
file.Seek(402,CFile::begin);
file.Write(userid,3);
file.Close();
tmpname="当班人姓名:"+tmpname;
CMainFrame *MFrame=(CMainFrame *)AfxGetMainWnd();
MFrame->m_wndStatusBar.SetPaneText(1,tmpname);
break;
}
}
file.ReadString(str);
tmpid=str.Left(3);
}
if(flag)
AfxMessageBox("交接班操作已经完成。");
else
{
file.Close();
AfxMessageBox("用户名或口令错误,交接班操作被取消。");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -