www.pudn.com > fractal.rar > MainFrm.cpp


//贵州省安顺市第二高级中学 高二一班 蒋伟	 
//2002.7.1 
//请勿修改版权信息 谢谢 
//Neil 
// 
// MainFrm.cpp : implementation of the CMainFrame class 
// 
 
#include "stdafx.h" 
#include "Fractal.h" 
 
#include "adjustfractal.h" 
#include "mainfrm.h" 
#include "fractaldoc.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) 
	ON_WM_CREATE() 
	ON_WM_GETMINMAXINFO() 
	ON_COMMAND(ID_VIEW_ADJUST_BAR, OnViewAdjustBar) 
	ON_UPDATE_COMMAND_UI(ID_VIEW_ADJUST_BAR, OnUpdateViewAdjustBar) 
	ON_WM_SHOWWINDOW() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
static UINT indicators[] = 
{ 
	ID_SEPARATOR,           // status line indicator 
	ID_SEPARATOR, 
	ID_SEPARATOR, 
}; 
 
///////////////////////////////////////////////////////////////////////////// 
// CMainFrame construction/destruction 
 
CMainFrame::CMainFrame() 
{ 
	// TODO: add member initialization code here 
	 
} 
 
CMainFrame::~CMainFrame() 
{ 
} 
 
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{ 
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1) 
		return -1; 
	 
	if (!m_wndToolBar.CreateEx(this,TBSTYLE_FLAT|TBSTYLE_TRANSPARENT, WS_CHILD | WS_VISIBLE | CBRS_LEFT 
		| 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.SetWindowText("常用工具栏"); 
 
	m_pAdjustBox=new CAdjustFractal; 
	if (!m_pAdjustBox->Create(IDD_ADJUST_BOX,this)) 
	{ 
		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 
	} 
	m_wndStatusBar.SetPaneInfo(1,0,0,70); 
	m_wndStatusBar.SetPaneStyle(1,SBPS_POPOUT); 
	m_wndStatusBar.SetPaneInfo(2,0,0,80); 
 
	// 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); 
 
	CRect rectWnd; 
	GetWindowRect(&rectWnd); 
 
	FloatControlBar(&m_wndToolBar,CPoint(rectWnd.left+10,rectWnd.top+50)); 
	m_pAdjustBox->SetWindowPos(this,rectWnd.right,rectWnd.top,0,0,SWP_NOSIZE|SWP_SHOWWINDOW); 
 
	return 0; 
} 
 
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	if( !CFrameWnd::PreCreateWindow(cs) ) 
		return FALSE; 
 
	cs.cx=420; 
 
	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 
 
 
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)  
{ 
	// TODO: Add your message handler code here and/or call default 
	lpMMI->ptMinTrackSize.x=400; 
	lpMMI->ptMinTrackSize.y=400; 
 
	CFrameWnd::OnGetMinMaxInfo(lpMMI); 
} 
 
void CMainFrame::PostNcDestroy()  
{ 
	delete m_pAdjustBox; 
 
	CFrameWnd::PostNcDestroy(); 
} 
 
void CMainFrame::OnViewAdjustBar()  
{ 
	CRect rectWnd; 
	::GetWindowRect(m_hWnd,&rectWnd); 
 
	m_pAdjustBox->SetWindowPos(this,rectWnd.right,rectWnd.top, 
		0,0,::IsWindowVisible(m_pAdjustBox->m_hWnd)? 
		SWP_NOSIZE|SWP_HIDEWINDOW:SWP_NOSIZE|SWP_SHOWWINDOW); 
} 
 
void CMainFrame::OnUpdateViewAdjustBar(CCmdUI* pCmdUI)  
{ 
	pCmdUI->SetCheck(::IsWindowVisible(m_pAdjustBox->m_hWnd)); 
} 
 
void CMainFrame::SetAdjustBoxData() 
{ 
	CFractalDoc *pDoc=(CFractalDoc*)GetActiveDocument(); 
	ASSERT(pDoc); 
 
	m_pAdjustBox->m_iBranchLength=pDoc->m_branch_length; 
	m_pAdjustBox->m_iBranchNum=pDoc->m_branch_num; 
	m_pAdjustBox->m_dblCutRate=pDoc->m_cut_rate; 
	m_pAdjustBox->m_iLastBranchLength=pDoc->m_last_branch_length; 
	m_pAdjustBox->m_iLeftAngle=pDoc->m_left_branch_angle; 
	m_pAdjustBox->m_iRightAngle=pDoc->m_right_branch_angle; 
	m_pAdjustBox->m_iLineWidth=pDoc->m_linewidth; 
	m_pAdjustBox->m_bDrawPixel=pDoc->m_bDrawPixel; 
	m_pAdjustBox->m_Color=pDoc->m_color; 
 
	m_pAdjustBox->UpdateData(FALSE); 
} 
 
void CMainFrame::OnShowWindow(BOOL bShow, UINT nStatus)  
{ 
	CFrameWnd::OnShowWindow(bShow, nStatus); 
 
	SetAdjustBoxData();	 
}