DragonNest/Third/XTToolkitPro/Samples/SkinFramework/SkinSDISample/MainFrm.cpp
2024-12-19 09:48:26 +08:00

268 lines
No EOL
6.1 KiB
C++

// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "SkinSDISample.h"
#include "MainFrm.h"
#include "SkinManagerExtResourceFile.h"
#include "SampleView.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)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code !
ON_WM_CREATE()
ON_WM_CLOSE()
//}}AFX_MSG_MAP
ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
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()
{
TCHAR szStylesPath[_MAX_PATH];
VERIFY(::GetModuleFileName(
AfxGetApp()->m_hInstance, szStylesPath, _MAX_PATH));
CString csStylesPath(szStylesPath);
int nIndex = csStylesPath.ReverseFind(_T('\\'));
if (nIndex > 0) {
csStylesPath = csStylesPath.Left(nIndex);
}
else {
csStylesPath.Empty();
}
m_strStylesPath = csStylesPath + _T("\\Styles\\");
XTPSkinManager()->SetApplyOptions(xtpSkinApplyFrame | xtpSkinApplyColors | xtpSkinApplyMetrics);
LoadSkin(0);
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// Create Status bar.
// Important: All control bars including the Status Bar
// must be created before CommandBars....
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
}
// Initialize the command bars
if (!InitCommandBars())
return -1;
XTPPaintManager()->SetTheme(xtpThemeNativeWinXP);
XTPPaintManager()->GetIconsInfo()->bUseFadedIcons = FALSE;
// Get a pointer to the command bars object.
CXTPCommandBars* pCommandBars = GetCommandBars();
if(pCommandBars == NULL)
{
TRACE0("Failed to create command bars object.\n");
return -1; // fail to create
}
// Add the menu bar
CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(
_T("Menu Bar"), IDR_MAINFRAME);
if(pMenuBar == NULL)
{
TRACE0("Failed to create menu bar.\n");
return -1; // fail to create
}
// Create ToolBar
CXTPToolBar* pToolBar = (CXTPToolBar*)
pCommandBars->Add(_T("Standard"), xtpBarTop);
if (!pToolBar || !pToolBar->LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1;
}
pCommandBars->GetShortcutManager()->SetAccelerators(IDR_MAINFRAME);
// Load the previous state for toolbars and menus.
LoadCommandBars(_T("CommandBars"));
PostMessage(WM_SYSCOLORCHANGE);
return 0;
}
void CMainFrame::OnClose()
{
// Save the current state for toolbars and menus.
SaveCommandBars(_T("CommandBars"));
CFrameWnd::OnClose();
}
void CMainFrame::OnCustomize()
{
// Get a pointer to the command bars object.
CXTPCommandBars* pCommandBars = GetCommandBars();
if(pCommandBars != NULL)
{
// Instanciate the customize dialog object.
CXTPCustomizeSheet dlg(pCommandBars);
// Add the keyboard page to the customize dialog.
CXTPCustomizeKeyboardPage pageKeyboard(&dlg);
dlg.AddPage(&pageKeyboard);
pageKeyboard.AddCategories(IDR_MAINFRAME);
// Add the options page to the customize dialog.
CXTPCustomizeOptionsPage pageOptions(&dlg);
dlg.AddPage(&pageOptions);
// Add the commands page to the customize dialog.
CXTPCustomizeCommandsPage* pCommands = dlg.GetCommandsPage();
pCommands->AddCategories(IDR_MAINFRAME);
// Use the command bar manager to initialize the
// customize dialog.
pCommands->InsertAllCommandsCategory();
pCommands->InsertBuiltInMenus(IDR_MAINFRAME);
pCommands->InsertNewMenuCategory();
// Dispaly the dialog.
dlg.DoModal();
}
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
cs.lpszClass = _T("XTPMainFrame");
CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass,
CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
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)
{
m_wndSplitter.CreateStatic(this, 1, 2);
m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CSampleView), CSize(220, 200), NULL);
m_wndSplitter.CreateView(0, 1, pContext->m_pNewViewClass, CSize(0, 0), pContext);
return TRUE;
}
void CMainFrame::OnSkinChanged()
{
XTPPaintManager()->RefreshMetrics();
OnSysColorChange();
RedrawWindow(0, 0, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE|RDW_ALLCHILDREN);
GetCommandBars()->GetPaintManager()->RefreshMetrics();
GetCommandBars()->RedrawCommandBars();
}
void CMainFrame::LoadSkin(int nSkin)
{
switch (nSkin)
{
case 1:
XTPSkinManager()->LoadSkin(m_strStylesPath + _T("iTunes"), _T("Normalitunes.INI"));
break;
case 0:
XTPSkinManager()->LoadSkin(m_strStylesPath + _T("Le5"), _T("NormalBlue.INI"));
break;
default:
XTPSkinManager()->LoadSkin(_T(""), _T(""));
}
if (m_hWnd) OnSkinChanged();
}
void CMainFrame::SetTheme(int nTheme, BOOL bFlat)
{
switch (nTheme)
{
case 0:
CXTPPaintManager::SetTheme(xtpThemeOffice2003);
break;
case 1:
CXTPPaintManager::SetTheme(xtpThemeNativeWinXP);
break;
}
XTPPaintManager()->GetIconsInfo()->bUseFadedIcons = FALSE;
if (bFlat)
{
XTPPaintManager()->m_bFlatMenuBar = TRUE;
XTPPaintManager()->m_bFlatToolBar = TRUE;
}
GetCommandBars()->RedrawCommandBars();
RedrawWindow( NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_ALLCHILDREN);
}