📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
//###############################################
//注意:1)窗口ID必需进行手工修改
// 请打开Resourch.h文档
// 修改后请重新编译
// #####跳过1) 过时######
// 2)因为窗口名称与菜单项名称相同
// 所以不能使用相同的菜单名称
// 3)菜单格式——我是菜单(N)
// 菜单项必需包含(左括号
// 4)菜单ID必需大于IDD_MENU_BEGIN小于IDD_MENU_END
// 例: 2xxyy
// 2 限定取值范围
// xx表示第几级菜单
// yy表示菜单中的第几项
// #####跳过4) 过时#######
//###############################################
#include "stdafx.h"
#include "Kvip.h"
#include "MainFrm.h"
////////////////////////////////////////////////
//MDI子窗口引用
#include "ViewUser.H"
#include "ViewModifyPassword.H"
#include "DlgLogin.H"
#include "DlgWkInput.H"
#include "DlgKQProject.H"
#include "DlgKQInput.H"
#include "DlgKQConfirm.H"
#include "DlgPrWorker.H" //报表
#include "DlgPr0001Log.H" //报表
#include "DlgPr0002Salary.H" //报表
#include "DlgPr0003Day.H" //报表
////////////////////////////////////////////////
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_CLOSE()
//}}AFX_MSG_MAP
ON_UPDATE_COMMAND_UI_RANGE(0, IDD_MENU_END, OnUpdateMenu)
ON_COMMAND_RANGE(0, IDD_MENU_END, OnCommandMenu)
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()
{
m_bAutoMenuEnable = FALSE;
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::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);
COLORREF cl = RGB(205,205,205);
COLORREF bk = RGB(100,0,0);
//#ifndef _DEBUG
if(!m_wndReBar.CreateEx(this,IDR_MAINFRAME,
IDR_MAINFRAME, cl, bk))
{
TRACE0("Failed to create rebar\n");
return -1; // fail to create
}
//#endif
return 0;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
///////////////////////////////////////////////////////
//设置菜单是否用效
void CMainFrame::OnUpdateMenu(CCmdUI* pCmdUI)
///////////////////////////////////////////////////////
{
// TODO: Add your command update UI handler code here
CKvipApp *pApp = (CKvipApp *)AfxGetApp();
if (!pApp->m_bManager)
{
pCmdUI->Enable(false); //黙认为禁止
for (int i = 0; i < pApp->m_caFunction.GetSize(); i++)
{
UINT nID = pApp->m_caFunction.GetAt(i);
if (pCmdUI->m_nID == nID)
pCmdUI->Enable(true); //允许菜单
}
}
}
///////////////////////////////////////////////////////
//减少代码
#define OPEN_MENU(x) m_Mdi.Append(pName, RUNTIME_CLASS(x), IDR_MAINFRAME, this, nID)
//响应菜单命令
void CMainFrame::OnCommandMenu(UINT nID)
///////////////////////////////////////////////////////
{
CString strName = GetMenuName(nID);
LPSTR pName = (LPSTR)(LPCSTR)strName;
CDlgLogin *pDlg;
//打开窗口
switch(nID)
{
case IDD_PR0001_LOG:
OPEN_MENU(CDlgPr0001Log);
break;
case IDD_PR0002_SALARY:
OPEN_MENU(CDlgPr0002Salary);
break;
case IDD_PR0003_Day:
OPEN_MENU(CDlgPr0003Day);
break;
case IDD_PR_WORKER:
OPEN_MENU(CDlgPrWorker);
break;
case IDD_KQ_CONFIRM:
OPEN_MENU(CDlgKqConfirm);
break;
case IDD_KQ_INPUT:
OPEN_MENU(CDlgKqInput);
break;
case IDD_KQ_PROJECT:
OPEN_MENU(CDlgKqProject);
break;
case IDD_WK_INPUT:
OPEN_MENU(CDlgWkInput);
break;
case IDD_US_USER:
OPEN_MENU(CViewUser);
break;
case IDD_US_MODIFY_PASSWORD:
OPEN_MENU(CViewModifyPassword);
break;
case IDD_US_UNLOG:
if (m_Mdi.GetCount() > 0)
{
MessageBox("注意:重新登陆前请先关闭所有窗口!",
"系统提示", MB_OK|MB_ICONEXCLAMATION);
return ;
}
pDlg = new CDlgLogin;
if (pDlg == NULL) return ;
pDlg->DoModal();
delete pDlg;
break;
}
}
#undef OPEN_MENU
//减少代码
//////////////////////////////////////////////////////////
///////////////////////////////////////////////////
//取菜单项名称作为窗口名称
//注意:**菜单项名称不能重复**
CString CMainFrame::GetMenuName(UINT nID)
///////////////////////////////////////////////////
{
CString strName;
CMenu *pMenu = GetMenuEx();
if (pMenu == NULL) return _T("");
pMenu->GetMenuString(nID, strName, MF_BYCOMMAND);
int i = strName.Find('(');
if (i > 0) strName = strName.Left(i);
return strName;
}
void CMainFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
if(m_Mdi.MainClose())
CMDIFrameWnd::OnClose();
}
BOOL CMainFrame::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
m_Mdi.DeleteAll();
return CMDIFrameWnd::DestroyWindow();
}
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
//#ifndef _DEBUG
if(!m_wndReBar.PreMenuMessage(pMsg))
return 0;
//#endif
return CMDIFrameWnd::PreTranslateMessage(pMsg);
}
//取当前菜单
CMenu * CMainFrame::GetMenuEx()
{
//#ifndef _DEBUG
return m_wndReBar.m_wndMenuBar.GetMenu();
//#else
// return GetMenu();
//#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -