📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "clientMain.h"
#include "MainFrm.h"
#include "clientFinanceView.h"
#include "clientMainView.h"
#include "clientSellView.h"
#include "BuyMaterialView.h"
#include "SellMaterialView.h"
#include "ManageUserView.h"
#include "UserDlg.h"
#include <string>
#include "Splash.h"
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//User_Type g_tUserType;
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_UPDATE_COMMAND_UI(ID_VIEW_COOL_BAR, OnUpdateViewCoolBar)
ON_COMMAND(ID_VIEW_COOL_BAR, OnViewCoolBar)
ON_NOTIFY(TVN_SELCHANGED, ID_Tree_View, OnTreeClick)
ON_COMMAND(ID_OPERATE_SELL, OnOperateSell)
ON_COMMAND(ID_OPERATE_FINANCE, OnOperateFinance)
ON_COMMAND(ID_OPERATE_MATERIAL, OnOperateMaterial)
ON_WM_GETMINMAXINFO()
ON_COMMAND(IDW_CLOSE_NOW, OnCloseNow)
ON_UPDATE_COMMAND_UI(IDW_CLOSE_NOW, OnUpdateCloseNow)
ON_COMMAND(IDW_CLOSE_ALL, OnCloseAll)
ON_UPDATE_COMMAND_UI(IDW_CLOSE_ALL, OnUpdateCloseAll)
ON_COMMAND(ID_OPERATE_MBUY, OnOperateMbuy)
ON_COMMAND(ID_OPERATE_MSELL, OnOperateMsell)
ON_COMMAND(IDS_USER_MODIFY, OnUserModify)
ON_COMMAND(IDS_PSW_MODIFY, OnPswModify)
//}}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()
{
// TODO: add member initialization code here
//m_pDoc = new CClientMainDoc();
m_strBar[0] = "材料管理";
m_strBar[1] = "材料信息管理";
m_strBar[2] = "材料采购管理";
m_strBar[3] = "材料出库管理";
m_strBar[4] = "销售管理";
m_strBar[5] = "财务管理";
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
//用来设置背景颜色或位图,子类化新建的多文档窗体
if (!m_wndNewClient.SubclassWindow(m_hWndMDIClient))
{
TRACE("Failed to subclass MDI client window\n");
return -1; // fail to create
}
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
}
if (!m_wndCoolBar.Create(_T("命令导航栏"), this, 123))
{
TRACE0("Failed to create mybar\n");
return -1; // fail to create
}
//创建树状控件
if (!m_wndTree.Create(WS_CHILD|WS_VISIBLE|
TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT,
CRect(0, 0, 0, 0), &m_wndCoolBar, ID_Tree_View))
{
TRACE0("Failed to create instant bar child\n");
return -1;
}
m_wndTree.ModifyStyleEx(0, WS_EX_CLIENTEDGE);
m_imgList.Create(IDB_BMP_TREE, 16, 1, RGB(0,255,0));
m_imgList.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
m_imgList.Add(AfxGetApp()->LoadIcon(IDI_ICON2));
m_wndTree.SetImageList(&m_imgList, TVSIL_NORMAL);
//为树状控件添加条目
HTREEITEM hti = m_wndTree.InsertItem(_T("物资管理系统"));
HTREEITEM htiChild; // child item
HTREEITEM htiThree;
//m_wndTree.InsertItem(_T("友情链接"));
//htiChild = m_wndTree.InsertItem(_T("兴趣爱好"), 0, 1, hti, TVI_LAST);
//htiChild = m_wndTree.InsertItem(_T("个人特长"), 0, 1, hti, TVI_LAST);
int i;
if(g_tUserType == Adm_All)
{
for(i = 0; i < (int)g_tUserType; i++)
{
if(i == 0)
{
htiChild = m_wndTree.InsertItem(m_strBar[i], 0, 1, hti, TVI_LAST);
htiThree = m_wndTree.InsertItem(m_strBar[1], 0, 1, htiChild, TVI_LAST);
htiThree = m_wndTree.InsertItem(m_strBar[2], 0, 1, htiChild, TVI_LAST);
htiThree = m_wndTree.InsertItem(m_strBar[3], 0, 1, htiChild, TVI_LAST);
}
else
{
htiChild = m_wndTree.InsertItem(m_strBar[i+3], 0, 1, hti, TVI_LAST);
}
}
}
else
{
if(int(g_tUserType) == 0)
{
htiChild = m_wndTree.InsertItem(m_strBar[(int)g_tUserType], 0, 1, hti, TVI_LAST);
htiThree = m_wndTree.InsertItem(m_strBar[1], 0, 1, htiChild, TVI_LAST);
htiThree = m_wndTree.InsertItem(m_strBar[2], 0, 1, htiChild, TVI_LAST);
htiThree = m_wndTree.InsertItem(m_strBar[3], 0, 1, htiChild, TVI_LAST);
}
else
{
htiChild = m_wndTree.InsertItem(m_strBar[(int)g_tUserType], 0, 1, hti, TVI_LAST);
}
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndCoolBar.SetBarStyle(m_wndCoolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndCoolBar.EnableDocking(CBRS_ALIGN_ANY);
//改变停靠风格,
#ifdef _SCB_REPLACE_MINIFRAME
m_pFloatingFrameClass = RUNTIME_CLASS(CSCBMiniDockFrameWnd);
#endif
DockControlBar(&m_wndToolBar);
DockControlBar(&m_wndCoolBar, AFX_IDW_DOCKBAR_LEFT);
// CG: The following line was added by the Splash Screen component.// CSplashWnd::ShowSplashScreen(this);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
// 为了能正常设置窗体的标题
cs.style&=~FWS_ADDTOTITLE;
cs.style&=~FWS_PREFIXTITLE;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// 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::OnUpdateViewCoolBar(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable();
pCmdUI->SetCheck(m_wndCoolBar.IsVisible());
}
void CMainFrame::OnViewCoolBar()
{
// TODO: Add your command handler code here
ShowControlBar(&m_wndCoolBar, !m_wndCoolBar.IsVisible(), FALSE);
}
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
return CMDIFrameWnd::PreTranslateMessage(pMsg);
}
void CMainFrame::OnTreeClick(NMHDR* pNMHDR, LRESULT* pResult)
{
HTREEITEM trvItem = m_wndTree.GetSelectedItem();
CString strTrvText;
strTrvText = m_wndTree.GetItemText(trvItem);
if (trvItem==NULL)
{
return;
}
else
{
if (m_wndTree.GetParentItem(trvItem) != NULL)
{
//AfxMessageBox(strTrvText.c_str());
//m_wndTree.
if(m_strBar[1] == strTrvText)//.c_str)
{
OnOperateMaterial();
}
if(m_strBar[2] == strTrvText)//.c_str)
{
OnOperateMbuy();
}
if(m_strBar[3] == strTrvText)//.c_str)
{
OnOperateMsell();
}
if(m_strBar[4] == strTrvText)//.c_str )
{
OnOperateSell();
}
if(m_strBar[5] == strTrvText)//.c_str)
{
OnOperateFinance();
}
}
}
*pResult = 0;
}
void CMainFrame::OnOperateSell()
{
// TODO: Add your command handler code here
CClientSellView *pFindView = NULL;
EkNewOrOpenWnd<CClientSellView>(theApp.m_pSTemplate, m_pDoc,
m_pFrame, pFindView, "CClientSellView");
delete pFindView;
}
void CMainFrame::OnOperateFinance()
{
// TODO: Add your command handler code here
CClientFinanceView *pFindView = NULL;
EkNewOrOpenWnd<CClientFinanceView>(theApp.m_pFTemplate, m_pDoc,
m_pFrame, pFindView, "CClientFinanceView");
delete pFindView;
}
void CMainFrame::OnOperateMaterial()
{
// TODO: Add your command handler code here
CClientMainView *pFindView = NULL;
EkNewOrOpenWnd<CClientMainView>(theApp.m_pMTemplate, m_pDoc,
m_pFrame, pFindView, "CClientMainView");
delete pFindView;
}
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
// TODO: Add your message handler code here and/or call default
CMDIFrameWnd::OnGetMinMaxInfo(lpMMI);
CRect rectClient;
GetClientRect(&rectClient);
CRect rectWindow;
GetWindowRect(&rectWindow);
int nWidthOverhead = rectWindow.Width() - rectClient.Width();
int nHeightOverhead = rectWindow.Height() - rectClient.Height();
lpMMI->ptMinTrackSize.x = 1000 + nWidthOverhead;
lpMMI->ptMinTrackSize.y = 600 + nHeightOverhead;
}
void CMainFrame::OnCloseNow()
{
// TODO: Add your command handler code here
CMDIFrameWnd *pFrame =
(CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild =
(CMDIChildWnd *) pFrame->GetActiveFrame();
CView *pView;
pView = pChild->GetActiveView();
if(pView !=NULL)
{
pView->GetParentFrame()->DestroyWindow();
}
}
void CMainFrame::OnUpdateCloseNow(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
BOOL bVisible;
CMDIFrameWnd *pFrame =
(CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
if(pFrame != NULL)
{
CMDIChildWnd *pChild =
(CMDIChildWnd *)pFrame->GetActiveFrame();
CView *pView = pChild->GetActiveView();
if(pView ==NULL)
{
bVisible = FALSE;
}
else
{
bVisible = TRUE;
}
}
else
{
bVisible = FALSE;
}
pCmdUI->Enable(bVisible);
pCmdUI->SetCheck(bVisible);
}
void CMainFrame::OnCloseAll()
{
// TODO: Add your command handler code here
CMDIFrameWnd *pFrame =
(CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild =
(CMDIChildWnd *)pFrame->GetActiveFrame();
CView *pView = NULL;
CDocument *pDocument = pChild->GetActiveDocument();
if(pDocument != NULL)
{
POSITION pos = pDocument->GetFirstViewPosition();
while(pos != NULL)
{
pView= pDocument->GetNextView(pos);
if(pView != NULL)
{
pView->GetParentFrame()->DestroyWindow();
}
}
}
}
void CMainFrame::OnUpdateCloseAll(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
OnUpdateCloseNow(pCmdUI);
}
void CMainFrame::OnOperateMbuy()
{
// TODO: Add your command handler code here
CBuyMaterialView *pFindView = NULL;
EkNewOrOpenWnd<CBuyMaterialView>(theApp.m_pMBuyTemplate, m_pDoc,
m_pFrame, pFindView, "CBuyMaterialView");
delete pFindView;
}
void CMainFrame::OnOperateMsell()
{
// TODO: Add your command handler code here
CSellMaterialView *pFindView = NULL;
EkNewOrOpenWnd<CSellMaterialView>(theApp.m_pMSellTemplate, m_pDoc,
m_pFrame, pFindView, "CSellMaterialView");
delete pFindView;
}
void CMainFrame::OnUserModify()
{
// TODO: Add your command handler code here
CManageUserView *pFindView = NULL;
EkNewOrOpenWnd<CManageUserView>(theApp.m_pUserTemplate, m_pDoc,
m_pFrame, pFindView, "CManageUserView");
delete pFindView;
}
void CMainFrame::OnPswModify()
{
// TODO: Add your command handler code here
//int nRet;
CUserDlg userDlg;
userDlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -