?? mainfrm.cpp
字號:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "PITC.h"
#include "MainFrm.h"
#include "CessDlg.h"
#include "AreaDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CString cessFlag;
extern CString areaFlag;
extern BOOL modified;
extern CString pathname;
extern CString filename;
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_COMPUT, OnComput)
ON_COMMAND(ID_CESS_ADD, OnCessAdd)
ON_COMMAND(ID_CESS_INSERT, OnCessInsert)
ON_COMMAND(ID_CESS_EDIT, OnCessEdit)
ON_COMMAND(ID_CESS_DELETE, OnCessDelete)
ON_COMMAND(ID_CESS_CLEAR, OnCessClear)
ON_WM_DESTROY()
ON_COMMAND(ID_CONFIG_SAVE, OnConfigSave)
ON_COMMAND(ID_CONFIG_LOAD, OnConfigLoad)
ON_UPDATE_COMMAND_UI(ID_CESS_DELETE, OnUpdateCessDelete)
ON_UPDATE_COMMAND_UI(ID_CESS_EDIT, OnUpdateCessEdit)
ON_COMMAND(ID_AREA_ADD, OnAreaAdd)
ON_COMMAND(ID_AREA_CLEAR, OnAreaClear)
ON_COMMAND(ID_AREA_DELETE, OnAreaDelete)
ON_UPDATE_COMMAND_UI(ID_AREA_DELETE, OnUpdateAreaDelete)
ON_COMMAND(ID_AREA_EDIT, OnAreaEdit)
ON_UPDATE_COMMAND_UI(ID_AREA_EDIT, OnUpdateAreaEdit)
ON_COMMAND(IDR_KROMO, OnKromo)
ON_UPDATE_COMMAND_UI(IDR_KROMO, OnUpdateKromo)
ON_COMMAND(IDR_DEVIOR, OnDevior)
ON_UPDATE_COMMAND_UI(IDR_DEVIOR, OnUpdateDevior)
ON_COMMAND(IDR_CORONA, OnCorona)
ON_UPDATE_COMMAND_UI(IDR_CORONA, OnUpdateCorona)
ON_COMMAND(ID_CALC, OnCalc)
ON_WM_CLOSE()
ON_COMMAND(ID_CONFIG_NEW, OnConfigNew)
ON_COMMAND(ID_CONFIG_SAVEAS, OnConfigSaveas)
ON_COMMAND(ID_COMPUTVIEW_RESET, OnComputviewReset)
//}}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_bCreatedOK=FALSE;
m_bCessEdit=FALSE;
m_bCessDelete=FALSE;
m_bAreaEdit=FALSE;
m_bAreaDelete=FALSE;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
//AfxMessageBox("OnCreate!");
/////////
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);
SetLayout();
CString str;
str.LoadString(AFX_IDS_APP_TITLE);
SetWindowText(str);
CenterWindow();
CMenu *pSystemMenu=GetSystemMenu(FALSE);
pSystemMenu->AppendMenu(MF_SEPARATOR);
pSystemMenu->AppendMenu(MF_STRING,ID_APP_ABOUT,_T("關于程序(&A)...")); //SK modified for Unicode
////
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
cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
// cs.style &= ~WS_MAXIMIZEBOX; //禁止窗口最大化
// cs.style &= ~WS_MINIMIZEBOX; //禁止窗口最小化
// cs.style &= ~WS_SYSMENU; //取消Title上的按鈕
// cs.style &= ~WS_THICKFRAME;//使窗口不能用鼠標改變大小
cs.lpszClass = AfxRegisterWndClass(0);
cs.style &= ~FWS_ADDTOTITLE;//去掉"無標題"
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
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
//AfxMessageBox("OnCreateClient!");
/////////
/////////
m_VSplitter.CreateStatic(this, 1, 2);
m_VSplitter.CreateView(0, 1, RUNTIME_CLASS( CComputView ), CSize(0, 0), pContext);
m_HSplitter.CreateStatic(&m_VSplitter, 2, 1,WS_CHILD | WS_VISIBLE, m_VSplitter.IdFromRowCol(0, 0));
m_HSplitter.CreateView(0, 0, RUNTIME_CLASS( CConfigViewCess ), CSize(300, 0), pContext);
m_HSplitter.CreateView(1, 0, RUNTIME_CLASS( CConfigViewArea ), CSize(300, 0), pContext);
//m_VSplitter.CreateView(0, 2, RUNTIME_CLASS( CPITCView ), CSize(0, 0), pContext);
CWnd *pView;
pView=this->m_HSplitter.GetPane(0,0);
ASSERT(pView->IsKindOf(RUNTIME_CLASS(CConfigViewCess)));
m_pConfigViewCess=(CConfigViewCess*)pView;
pView=this->m_HSplitter.GetPane(1,0);
ASSERT(pView->IsKindOf(RUNTIME_CLASS(CConfigViewArea)));
m_pConfigViewArea=(CConfigViewArea*)pView;
pView=this->m_VSplitter.GetPane(0,1);
ASSERT(pView->IsKindOf(RUNTIME_CLASS(CComputView)));
m_pComputView=(CComputView*)pView;
m_pConfigDoc=new CConfigDoc;
POSITION pos=m_pConfigDoc->GetFirstViewPosition();
CDocument *pDoc;
CRuntimeClass *prt;
pDoc=m_pConfigViewCess->GetDocument();
prt=pDoc->GetRuntimeClass();
//AfxMessageBox(prt->m_lpszClassName);
pDoc->RemoveView(m_pConfigViewCess);
pDoc->RemoveView(m_pConfigViewArea);
while(pos!=NULL)
{
pView=m_pConfigDoc->GetNextView(pos);
prt=pView->GetRuntimeClass();
AfxMessageBox(prt->m_lpszClassName);
}
m_pConfigDoc->AddView(this->m_pConfigViewCess);
m_pConfigDoc->AddView(this->m_pConfigViewArea);
///////
/////
m_bCreatedOK=TRUE;
////
return TRUE;
//return CFrameWnd::OnCreateClient(lpcs, pContext);
}
void CMainFrame::SetLayout()//初始化子框架中各切分子窗口的大小
{
if(m_bCreatedOK)
{
if(m_VSplitter.m_hWnd)
{
int cx0, cx1, cxmin, cx;
m_VSplitter.GetColumnInfo(0, cx0, cxmin);
m_VSplitter.GetColumnInfo(1, cx1, cxmin);
cx = cx0 + cx1;
int minCx0 = (int)(cx * 0.81);
if(cx0 != minCx0)
{
cx0 = minCx0;
m_VSplitter.SetColumnInfo(0, cx0 , cxmin);
}
m_VSplitter.RecalcLayout();
}
////
if(m_HSplitter.m_hWnd)
{
int cy0, cy1, cymin, cy;
m_HSplitter.GetRowInfo(0, cy0, cymin);
m_HSplitter.GetRowInfo(1, cy1, cymin);
cy = cy0 + cy1;
int minCy0 = (int)(cy * 0.6);
if(cy0 != minCy0)
{
cy0 = minCy0;
m_HSplitter.SetRowInfo(0, cy0 , cymin);
}
m_HSplitter.RecalcLayout();
}
///
}
}
void CMainFrame::OnComput()
{
// TODO: Add your command handler code here
this->m_pComputView->Comput();
}
void CMainFrame::OnCessAdd()
{
// TODO: Add your command handler code here
cessFlag="ADD";
CCessDlg dlg;
dlg.DoModal();
}
void CMainFrame::OnCessInsert()
{
// TODO: Add your command handler code here
cessFlag="INSERT";
CCessDlg dlg;
dlg.DoModal();
}
void CMainFrame::OnCessEdit()
{
// TODO: Add your command handler code here
CListCtrlCess *pListCtrl;
pListCtrl=(CListCtrlCess *)(&(this->m_pConfigViewCess->m_wndListCtrlCess));
int count=pListCtrl->GetSelectedCount();
if(0==count)
{
AfxMessageBox("請在稅率表中選中一行要編輯的數據!");
return ;
}
///////
cessFlag="EDIT";
CCessDlg dlg;
dlg.DoModal();
this->m_pComputView->UpdateDisplay();
}
void CMainFrame::OnCessDelete()
{
// TODO: Add your command handler code here
CListCtrlCess *pListCtrl;
pListCtrl=(CListCtrlCess *)(&(this->m_pConfigViewCess->m_wndListCtrlCess));
int count=pListCtrl->GetSelectedCount();
if(0==count)
{
AfxMessageBox("請在稅率表中選中一行要刪除的數據!");
return ;
}
POSITION pos = pListCtrl->GetFirstSelectedItemPosition();
int m=pListCtrl->GetNextSelectedItem(pos);
CString str;
str.Format("確認要刪除稅率表第%d行數據嗎?",m+1);
if (MessageBox(str,"用戶信息",MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2)==IDNO)
return;
pListCtrl->DeleteItem(m);
modified=TRUE;
pListCtrl->UpdateNum();//更新級別序號
}
void CMainFrame::OnCessClear()
{
// TODO: Add your command handler code here
CString str;
str="確認要刪除稅率表中所有的數據嗎?";
if (MessageBox(str,"用戶信息",MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2)==IDNO)
return;
CListCtrl *pListCtrl;
pListCtrl=&(this->m_pConfigViewCess->m_wndListCtrlCess);
if(pListCtrl->GetItemCount()>0)
{
pListCtrl->DeleteAllItems();
modified=TRUE;
}
}
void CMainFrame::OnDestroy()
{
CFrameWnd::OnDestroy();
// TODO: Add your message handler code here
if(m_pConfigDoc)
{
delete m_pConfigDoc;
m_pConfigDoc=NULL;
}
}
void CMainFrame::OnConfigSave()
{
// TODO: Add your command handler code here
if(pathname!="")
{
if(m_pConfigDoc->OnSaveDocument(pathname))
{
modified=FALSE;
}
}
else
{
//::SendMessage(this->GetSafeHwnd(),WM_COMMAND,ID_CONFIG_SAVEAS,NULL);
if(DoFileSave(FALSE)==TRUE)
{
}
}
}
void CMainFrame::OnUpdateCessDelete(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -