www.pudn.com > MiniFox.rar > MainFrm.cpp
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "MiniFox.h"
#include "MainFrm.h"
#include "MiniFoxDoc.h"
#include "MiniFoxView.h"
#include "AccMgrTreeView.h"
#include "MailListView.h"
#include "MailContentView.h"
#include "Wizard.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern bool CreateAcc( CFile& rAccFile, CWizard::AccInfo& rAccInfo );
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_ACC_NEW, OnAccNew)
ON_COMMAND(ID_OPTIONAL_SETTINGS, OnOptionalSettings)
ON_COMMAND(ID_OPTIONAL_ACCPROPERTY, OnOptionalAccproperty)
//}}AFX_MSG_MAP
// Global help commands
ON_COMMAND(ID_HELP_FINDER, CFrameWnd::OnHelpFinder)
ON_COMMAND(ID_HELP, CFrameWnd::OnHelp)
ON_COMMAND(ID_CONTEXT_HELP, CFrameWnd::OnContextHelp)
ON_COMMAND(ID_DEFAULT_HELP, CFrameWnd::OnHelpFinder)
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
}
CMainFrame::~CMainFrame()
{
// Destroy the bitmap objects if they are loaded successfully
// in OnCreate().
if (m_CheckBitmap1.m_hObject)
m_CheckBitmap1.DeleteObject();
if (m_UnCheckBitmap1.m_hObject)
m_UnCheckBitmap1.DeleteObject();
if (m_CheckBitmap2.m_hObject)
m_CheckBitmap2.DeleteObject();
if (m_UnCheckBitmap2.m_hObject)
m_UnCheckBitmap2.DeleteObject();
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
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
}
// m_wndToolBar.GetToolBarCtrl().SetInsertMarkColor( RGB( 255, 0, 255 ) );
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
}
// Load bitmaps from resource. Both m_CheckBitmap and m_UnCheckBitmap
// are member variables of CMainFrame class of type CBitmap.
ASSERT(m_CheckBitmap1.LoadBitmap(IDB_BITMAP3));
ASSERT(m_UnCheckBitmap1.LoadBitmap(IDB_BITMAP3));
// Associate bitmaps with the "Test" menu item.
CMenu* mmenu = GetMenu();
CMenu* submenu = mmenu->GetSubMenu(0);
ASSERT(submenu->SetMenuItemBitmaps(ID_FILE_SEND, MF_BYCOMMAND,
&m_CheckBitmap1, &m_UnCheckBitmap1));
// Load bitmaps from resource. Both m_CheckBitmap and m_UnCheckBitmap
// are member variables of CMainFrame class of type CBitmap.
ASSERT(m_CheckBitmap2.LoadBitmap(IDB_BITMAP2));
ASSERT(m_UnCheckBitmap2.LoadBitmap(IDB_BITMAP2));
// Associate bitmaps with the "Test" menu item.
ASSERT(submenu->SetMenuItemBitmaps(ID_FILE_RECEIVE, MF_BYCOMMAND,
&m_CheckBitmap2, &m_UnCheckBitmap2));
// 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);
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.style &= ~FWS_ADDTOTITLE; // Remove document name from title bar.
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 );
CRect cr;
GetClientRect( &cr );
CSize panesize1( 1*cr.Width()/5, cr.Height() );
CSize panesize2( 4*cr.Width()/5, 2*cr.Height()/7 );
CSize panesize3( 4*cr.Width()/5, 5*cr.Height()/7 );
if( !m_wndSplitter.CreateView( 0,0,RUNTIME_CLASS( CAccMgrTreeView ),
panesize1,pContext) )
{
TRACE0( "Failed to create the first pane\n" );
return FALSE;
}
if (!m_wndSplitter2.CreateStatic(
&m_wndSplitter, // our parent window is the first splitter
2, 1, // the new splitter is 2 rows, 1 column
WS_CHILD | WS_VISIBLE | WS_BORDER, // style, WS_BORDER is needed
m_wndSplitter.IdFromRowCol(0, 1)
// new splitter is in the first row, 2nd column of first splitter
))
{
TRACE0("Failed to create nested splitter\n");
return FALSE;
}
if( !m_wndSplitter2.CreateView( 0, 0, RUNTIME_CLASS( CMailListView ),
panesize2,pContext) )
{
TRACE0( "Failed to create second pane\n" );
return FALSE;
}
if( !m_wndSplitter2.CreateView( 1, 0, RUNTIME_CLASS( CMailContentView ),
panesize3,pContext) )
{
TRACE0( "Failed to create third pane\n" );
return FALSE;
}
return TRUE;
}
void CMainFrame::OnAccNew()
{
CWizard wizard;
if( IDOK == wizard.DoModal() ) // Finish the creation of an account.
{
CFileException ex;
CFile accFile;
if ( !accFile.Open( ACCCFGFILENAME, CFile::modeReadWrite, &ex ) &&
ex.m_cause == CFileException::fileNotFound )
// The account configure file does not exist. Thus create it and create an account:
{
if( !accFile.Open( ACCCFGFILENAME, CFile::modeCreate |
CFile::modeReadWrite, &ex) ) // Not successfully created.
{
TRACE0( "Cannot create file: Account.cfg" );
return;
}
}
// Since "Account.cfg" file has been successfully created, store some
// data about the new account into this file:
if( !CreateAcc( accFile, wizard.accInfo ) )
{
AfxMessageBox( "The account hasn't been successfully created.",
MB_OK | MB_APPLMODAL | MB_ICONINFORMATION );
}
accFile.Close();
( ( CAccMgrTreeView* )m_wndSplitter.GetPane( 0, 0 ) )->OnInitialUpdate( );
}
}
void CMainFrame::OnOptionalSettings()
{
CSystemProperty m_pSystem("");
m_pSystem.DoModal();
}
void CMainFrame::OnOptionalAccproperty()
{
CAccountInfo m_AccInfo;
m_AccInfo.DoModal();
}