?? mainfrm.cpp
字號:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "ResourceEditor.h"
#include "MainFrm.h"
#include "HtmlHelp.h"
#include "CoolBar.h"
#include "ModuleView.h"
#include "PrjFactory.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_UPDATE_COMMAND_UI(ID_FILE_NEW, OnUpdateFileNew)
ON_UPDATE_COMMAND_UI(ID_FILE_OPEN, OnUpdateFileOpen)
ON_UPDATE_COMMAND_UI(ID_VIEW_IMG, OnUpdateViewImg)
ON_UPDATE_COMMAND_UI(ID_VIEW_RING, OnUpdateViewRing)
ON_UPDATE_COMMAND_UI(ID_VIEW_TEXT, OnUpdateViewText)
ON_UPDATE_COMMAND_UI(ID_VIEW_FONT, OnUpdateViewFont)
ON_UPDATE_COMMAND_UI(ID_PROJECT_CLOSE, OnUpdateProjectClose)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnUpdateFileSaveAs)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_IMAGE, OnUpdateFileSaveImage)
ON_UPDATE_COMMAND_UI(ID_VIEW_ANIM, OnUpdateViewAnim)
ON_UPDATE_COMMAND_UI(ID_ADD_TO_MODULE_LIST, OnUpdateAddToModuleList)
ON_COMMAND(ID_ADD_TO_MODULE_LIST, OnAddToModuleList)
ON_WM_CLOSE()
ON_WM_HELPINFO()
ON_COMMAND(ID_APP_HELP, OnAppHelp)
ON_COMMAND(ID_SAVE_RESOURCE, OnSaveResource)
ON_UPDATE_COMMAND_UI(ID_SAVE_RESOURCE, OnUpdateSaveResource)
ON_COMMAND(ID_VIEW_MODULE_LIST, OnViewModuleList)
ON_UPDATE_COMMAND_UI(ID_VIEW_MODULE_LIST, OnUpdateViewModuleList)
ON_COMMAND(ID_OPEN_RESOURCE, OnOpenResource)
ON_UPDATE_COMMAND_UI(ID_OPEN_RESOURCE, OnUpdateOpenResource)
ON_UPDATE_COMMAND_UI(ID_OPTION_ANIM_TRANS, OnUpdateOptionAnimTrans)
ON_UPDATE_COMMAND_UI(ID_OPTION_REPORT, OnUpdateOptionReport)
//}}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_module_list = NULL;
m_pBinFactory = NULL;
m_pPrjFactory = NULL;
}
CMainFrame::~CMainFrame()
{
delete(m_pBinFactory);
delete(m_pPrjFactory);
}
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
CRuntimeClass * prtc = RUNTIME_CLASS( CCoolBar );
m_pOutBar = ( CCoolBar * )prtc->CreateObject();
if( NULL == m_pOutBar )
{
TRACE0("Failed to create categorybar object\n");
return -1;
}
int nWidth = 200;//lpCreateStruct->cx / 2;
m_pOutBar->m_bAutoDelete = TRUE;
if (!m_pOutBar->Create(_T("Module Name"), this, CSize(nWidth, 120), 0, TRUE))
{
TRACE0("Failed to create category bar\n");
return -1;
}
HINSTANCE hInstance = AfxGetApp()->m_hInstance;
HCURSOR hHorz = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_CUR_HORZ));
HCURSOR hVert = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_CUR_VERT));
m_pOutBar->SetStretchCursor( hHorz, hVert );
// LPMDICREATESTRUCT lpmcs = (LPMDICREATESTRUCT)(lpCreateStruct);
CCreateContext * pContext = (CCreateContext*)(lpCreateStruct->lpCreateParams);
if( !m_pOutBar->AddPage(RUNTIME_CLASS(CModuleView), pContext) )
{
TRACE0("Failed to create category view\n");
return -1;
}
m_pOutBar->SetBarStyle( CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC );
m_pOutBar->EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
m_module_list=(CModuleView*)m_pOutBar->GetWnd();
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
DockControlBar(m_pOutBar, AFX_IDW_DOCKBAR_LEFT);
ShowControlBar(m_pOutBar, TRUE, TRUE);
// create the background wnd
if( !m_wndBG.SubclassWindow(m_hWndMDIClient) )
{
TRACE0("Failed to create background wnd\n");
return -1; // fail to create
}
if( !g_theApp.IsSuperUser() )
{
CMenu * pMenu = GetMenu();
_ASSERTE( pMenu != NULL );
pMenu->DeleteMenu(ID_FILE_NEW, MF_BYCOMMAND);
pMenu->DeleteMenu(ID_OPTION_FILE_SETTING, MF_BYCOMMAND);
CToolBarCtrl &tbc = m_wndToolBar.GetToolBarCtrl();
tbc.DeleteButton( tbc.CommandToIndex(ID_FILE_NEW) );
}
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style |= WS_MAXIMIZE;
if( !CMDIFrameWnd::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
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnUpdateFileNew(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( g_theApp.m_bState);
}
void CMainFrame::OnUpdateFileOpen(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( g_theApp.m_bState);
}
void CMainFrame::OnUpdateViewImg(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( g_theApp.IsCanShowView() );
pCmdUI->SetCheck(g_theApp.IsCanCheck(MMI_RT_IMAGE));
}
void CMainFrame::OnUpdateViewAnim(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( g_theApp.IsCanShowView() );
pCmdUI->SetCheck(g_theApp.IsCanCheck(MMI_RT_ANIM));
}
void CMainFrame::OnUpdateViewRing(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( g_theApp.IsCanShowView() );
pCmdUI->SetCheck(g_theApp.IsCanCheck(MMI_RT_RING));
}
void CMainFrame::OnUpdateViewText(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( g_theApp.IsCanShowView() );
pCmdUI->SetCheck(g_theApp.IsCanCheck(MMI_RT_TEXT));
}
void CMainFrame::OnUpdateViewFont(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( g_theApp.IsCanShowView() );
pCmdUI->SetCheck(g_theApp.IsCanCheck(MMI_RT_FONT));
}
void CMainFrame::OnUpdateProjectClose(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( g_theApp.IsCanShowView() );
}
void CMainFrame::OnUpdateFileSave(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( g_theApp.IsCanShowView() );
}
void CMainFrame::OnUpdateFileSaveAs(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( g_theApp.IsCanShowView() );
}
void CMainFrame::OnUpdateFileSaveImage(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( g_theApp.IsCanShowView() );
}
void CMainFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
if( g_theApp.IsModified() )
{
if( g_theApp.PromptSaveFile() == IDCANCEL )
return;
}
g_theApp.DisableShowView();
CMDIFrameWnd::OnClose();
}
BOOL CMainFrame::OnHelpInfo(HELPINFO* pHelpInfo)
{
// TODO: Add your message handler code here and/or call default
_TCHAR szHelpFile[ _MAX_PATH ];
::GetModuleFileName(NULL, szHelpFile, _MAX_PATH );
LPTSTR pExt = _tcsrchr(szHelpFile, _T('.'));
if( NULL == pExt )
return FALSE;
_tcscpy(pExt, _T(".chm"));
HtmlHelp( this->m_hWnd, szHelpFile, HH_DISPLAY_TOPIC, NULL );
return CMDIFrameWnd::OnHelpInfo(pHelpInfo);
}
void CMainFrame::OnAppHelp()
{
// TODO: Add your command handler code here
OnHelpInfo(NULL);
}
void CMainFrame::OnAddToModuleList()
{
// TODO: Add your command handler code here
CString str;
/* if( m_pBinFactory == NULL )
{
m_pBinFactory = new CBinFileFactory;
if( NULL == m_pBinFactory )
return ;
}
str=m_pBinFactory->GetBinFileName();
m_module_list->AddModuleToList(str);*/
//delete(m_pPrjFactory);
if( m_pPrjFactory == NULL )
{
m_pPrjFactory = new CPrjFactory;
if( NULL == m_pPrjFactory )
return ;
}
str=m_pPrjFactory->GetPrjFileName();
if (!str.IsEmpty())
{
int nCount = g_theApp.m_prjarray.GetSize();
for(int i = 0; i < nCount; i++)
{
if(str == g_theApp.m_prjarray.GetAt(i))
{
AfxMessageBox(_T("The project has been included!"));
return;
}
}
g_theApp.m_prjarray.Add(str);
m_module_list->AddModuleToList(str);
}
}
void CMainFrame::OnUpdateAddToModuleList(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( g_theApp.m_bState);
}
void CMainFrame::OnSaveResource()
{
// TODO: Add your command handler code here
CString filename;
if( m_pBinFactory == NULL )
{
m_pBinFactory = new CBinFileFactory;
if( NULL == m_pBinFactory )
return ;
}
if( g_theApp.IsModified() )
{
g_theApp.PromptSaveFile();
}
filename=m_pBinFactory->GetBinFileName(FALSE);
int nleft= filename.ReverseFind(_T('\\'));
g_theApp.m_resBasePath=filename.Left(nleft);
if(""==filename)
{
//MessageBox("The file name can't empty!");
return;
}
m_module_list->SaveResourceFile((LPCTSTR)filename);
}
void CMainFrame::OnUpdateSaveResource(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( g_theApp.IsCanShowView()&&m_module_list->IsModuleListEmpty() );
}
void CMainFrame::OnViewModuleList()
{
// TODO: Add your command handler code here
ShowControlBar(m_pOutBar, !(m_pOutBar->GetStyle() & WS_VISIBLE), TRUE);
}
void CMainFrame::OnUpdateViewModuleList(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_pOutBar->GetStyle() & WS_VISIBLE);
}
void CMainFrame::OnOpenResource()
{
// TODO: Add your command handler code here
CString filename;
//g_theApp.OnFileClose(); //@Hongliang Xin,2006-5-30
if( g_theApp.m_bCanShowView )
{
if( g_theApp.IsModified() )
{
if(IDCANCEL == g_theApp.PromptSaveFile())
return;
}
}
BOOL bShowView = g_theApp.m_bCanShowView;
g_theApp.m_bCanShowView = FALSE;
filename=m_module_list->GetResFileName(TRUE);
int nleft= filename.ReverseFind(_T('\\'));
g_theApp.m_resBasePath=filename.Left(nleft);
if(""==filename)
{
//MessageBox("The file name can't empty!");
g_theApp.m_bCanShowView = bShowView;
return;
}
g_theApp.OnProjectClose(); //@Hongliang Xin,2006-5-30
g_theApp.m_strPrjFileName=filename;
g_theApp.m_isopenres=TRUE;
g_theApp.OnFileOpen();
}
void CMainFrame::OnUpdateOpenResource(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( g_theApp.m_bState);
}
void CMainFrame::OnUpdateOptionAnimTrans(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( g_theApp.IsCanShowView() );
}
void CMainFrame::OnUpdateOptionReport(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable( g_theApp.IsCanShowView() );
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -