www.pudn.com > DEM_TDS.rar > MainFrm.cpp, change:2007-07-04,size:14703b


// MainFrm.cpp : implementation of the CMainFrame class 
// 
 
#include "stdafx.h" 
#include "DEM.h" 
#include "MainFrm.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_COMMAND(ID_SHOWEDITTOOLBAR, OnShowedittoolbar) 
	ON_UPDATE_COMMAND_UI(ID_SHOWEDITTOOLBAR, OnUpdateShowedittoolbar) 
	ON_COMMAND(ID_SHOWSHOWTOOLBAR, OnShowshowtoolbar) 
	ON_UPDATE_COMMAND_UI(ID_SHOWSHOWTOOLBAR, OnUpdateShowshowtoolbar) 
	ON_COMMAND(ID_SHOWSTATUSCOOLBAR, OnShowstatuscoolbar) 
	ON_UPDATE_COMMAND_UI(ID_SHOWSTATUSCOOLBAR, OnUpdateShowstatuscoolbar) 
	ON_COMMAND(ID_SHOWDRAWTOOLBAR, OnShowdrawtoolbar) 
	ON_UPDATE_COMMAND_UI(ID_SHOWDRAWTOOLBAR, OnUpdateShowdrawtoolbar) 
	ON_COMMAND(ID_SHOWTREECOOLBAR, OnShowtreecoolbar) 
	ON_UPDATE_COMMAND_UI(ID_SHOWTREECOOLBAR, OnUpdateShowtreecoolbar) 
	ON_WM_TIMER() 
	ON_CBN_SELCHANGE(IDC_SHOWSCALE,OnSelchangeShowscale) 
	ON_CBN_SELCHANGE(IDC_MAPCOLOR,OnSelchangeMapcolor) 
	ON_CBN_EDITCHANGE(IDC_SHOWSCALE,OnEditchangeShowscale) 
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen) 
	ON_WM_SHOWWINDOW() 
	ON_UPDATE_COMMAND_UI(IDC_SHOWSCALE, OnUpdateShowscale) 
	ON_UPDATE_COMMAND_UI(IDC_MAPCOLOR, OnUpdateMapcolor) 
	ON_WM_GETMINMAXINFO() 
	ON_COMMAND(ID_FULLSCREEM, OnFullscreem) 
	ON_UPDATE_COMMAND_UI(ID_FULLSCREEM, OnUpdateFullscreem) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
static UINT indicators[] = 
{ 
	ID_SEPARATOR,           // status line indicator 
	ID_INDICATOR_COORLABLE, 
	ID_INDICATOR_GISCOOR, 
	ID_INDICATOR_XY, 
	ID_INDICATOR_MOUSE, 
	ID_INDICATOR_OPERATE, 
	ID_INDICATOR_TIME, 
}; 
///////////////////////////////////////////////////////////////////////////// 
// CMainFrame construction/destruction 
 
CMainFrame::CMainFrame() 
{ 
	// TODO: add member initialization code here 
	 m_bFullScreen=FALSE;	 
} 
 
CMainFrame::~CMainFrame() 
{ 
} 
 
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 
	} 
	if (!edittoolbar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_LEFT 
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || 
		!edittoolbar.LoadToolBar(IDR_EDITTOOL)) 
	{ 
		TRACE0("Failed to create toolbar\n"); 
		return -1;      // fail to create 
	} 
	if (!drawtoolbar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP 
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || 
		!drawtoolbar.LoadToolBar(IDR_SCALETOOLBAR)) 
	{ 
		TRACE0("Failed to create toolbar\n"); 
		return -1;      // fail to create 
	} 
 
	EnableDocking(CBRS_ALIGN_ANY); 
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); 
	edittoolbar.EnableDocking(CBRS_ALIGN_ANY); 
 
	drawtoolbar.EnableDocking(CBRS_ALIGN_ANY); 
	DockControlBar(&m_wndToolBar); 
	DockControlBar(&edittoolbar); 
	DockControlBar(&drawtoolbar); 
	RecalcLayout(); 
	CRect rect; 
 
if(!treecoolbar.Create(_T("地图数据结构树"),this,CSize(190,300),TRUE,124,WS_CHILD  | WS_VISIBLE | CBRS_RIGHT)) 
	{  
	 TRACE0("Failed to create treecoolbar\n");  
	 return -1;  
	}  
if(!statuscoolbar.Create(_T("选中物件属性状态栏"),this,CSize(150,70),TRUE,124,WS_CHILD | WS_VISIBLE | CBRS_BOTTOM)) 
	{ 
	TRACE0("Failed to create statuscoolbar\n"); 
	return -1;  
	} 
 
pointattrib.Create(IDD_POINTATTRIB,&statuscoolbar); 
////////////////////////////////////////////// 
 
treecoolbar.SetBarStyle(treecoolbar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);  
statuscoolbar.SetBarStyle(statuscoolbar.GetBarStyle() | CBRS_TOOLTIPS| CBRS_FLYBY | CBRS_SIZE_DYNAMIC); 
treecoolbar.EnableDocking(CBRS_ALIGN_ANY); 
statuscoolbar.EnableDocking(CBRS_ALIGN_ANY); 
DockControlBar(&treecoolbar, AFX_IDW_DOCKBAR_RIGHT); 
DockControlBar(&statuscoolbar, AFX_IDW_DOCKBAR_BOTTOM); 
 
////////////////////////////////////////////// 
 
m_wndStatusBar.SetPaneInfo(0,0,SBPS_STRETCH,400); 
m_wndStatusBar.SetPaneInfo(1,ID_INDICATOR_COORLABLE,SBPS_NORMAL,45); 
m_wndStatusBar.SetPaneInfo(2,ID_INDICATOR_GISCOOR,SBPS_NORMAL,153); 
m_wndStatusBar.SetPaneInfo(3,ID_INDICATOR_XY,SBPS_NORMAL,45); 
m_wndStatusBar.SetPaneInfo(4,ID_INDICATOR_MOUSE,SBPS_NORMAL,70); 
m_wndStatusBar.SetPaneInfo(5,ID_INDICATOR_OPERATE,SBPS_NORMAL,20); 
m_wndStatusBar.SetPaneInfo(6,ID_INDICATOR_TIME,SBPS_NORMAL,70); 
 
SetTimer(1,1000,NULL); 
 
drawtoolbar.SetButtonInfo(drawtoolbar.CommandToIndex(IDC_SHOWSCALE),IDC_SHOWSCALE,TBBS_SEPARATOR,160); 
drawtoolbar.GetItemRect(drawtoolbar.CommandToIndex(IDC_SHOWSCALE),&rect); 
rect.bottom+=100; 
if(!drawtoolbar.showscalecombox.Create (CBS_DROPDOWN|WS_VISIBLE|WS_TABSTOP|CBS_AUTOHSCROLL 
   ,rect, &drawtoolbar, IDC_SHOWSCALE)) return -1;  
 
drawtoolbar.showscalecombox.AddString("25%"); 
drawtoolbar.showscalecombox.AddString("50%"); 
drawtoolbar.showscalecombox.AddString("100%"); 
drawtoolbar.showscalecombox.AddString("200%"); 
drawtoolbar.showscalecombox.AddString("400%"); 
drawtoolbar.showscalecombox.AddString("800%"); 
 
drawtoolbar.SetButtonInfo(drawtoolbar.CommandToIndex(IDC_MAPCOLOR),IDC_MAPCOLOR,TBBS_SEPARATOR,160); 
drawtoolbar.GetItemRect(drawtoolbar.CommandToIndex(IDC_MAPCOLOR),&rect); 
rect.bottom+=120; 
if(!drawtoolbar.mapcolorcombox.Create (CBS_DROPDOWN|WS_VISIBLE|WS_TABSTOP|CBS_AUTOHSCROLL 
   ,rect, &drawtoolbar, IDC_MAPCOLOR)) return -1;  
 
drawtoolbar.mapcolorcombox.AddString("linescolor"); 
drawtoolbar.mapcolorcombox.AddString("spring"); 
drawtoolbar.mapcolorcombox.AddString("summer"); 
drawtoolbar.mapcolorcombox.AddString("fall"); 
drawtoolbar.mapcolorcombox.AddString("winter"); 
drawtoolbar.mapcolorcombox.AddString("blackwhite"); 
drawtoolbar.mapcolorcombox.AddString("gradualcolor"); 
 
drawtoolbar.mapcolorcombox.SetWindowText("linescolor"); 
 
drawtoolbar.GetItemRect(drawtoolbar.CommandToIndex(ID_COLOR1),&rect); 
if(!drawtoolbar.colorstart.Create ("S",WS_VISIBLE|WS_TABSTOP|BS_OWNERDRAW,rect, &drawtoolbar, ID_COLOR1)) return -1;  
 
drawtoolbar.GetItemRect(drawtoolbar.CommandToIndex(ID_COLOR2),&rect); 
if(!drawtoolbar.colorend.Create ("E",WS_VISIBLE|WS_TABSTOP|BS_OWNERDRAW,rect, &drawtoolbar, ID_COLOR2)) return -1;  
 
pagetabctrl.Create(WS_CHILD|WS_VISIBLE|TCS_DOWN|TCS_ANIMATE,CRect(0,0,100,100),&treecoolbar,125); 
//dataattribbar.Create(WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_WANTRETURN,CRect(0,0,0,0),&pagetabctrl,101); 
showtoolbar.CreateEx(&pagetabctrl, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP 
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ; 
showtoolbar.LoadToolBar(IDR_SHOWTOOL); 
 
pagetabctrl.AddPage(&showtoolbar,"图例",100); 
 
pagetabctrl.UpdateWindow();  
 
 
return 0; 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CMainFrame diagnostics 
 
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	if( !CMDIFrameWnd::PreCreateWindow(cs) ) 
		return FALSE; 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return TRUE; 
} 
 
#ifdef _DEBUG 
void CMainFrame::AssertValid() const 
{ 
	CMDIFrameWnd::AssertValid(); 
} 
 
void CMainFrame::Dump(CDumpContext& dc) const 
{ 
	CMDIFrameWnd::Dump(dc); 
} 
 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CMainFrame message handlers 
 
void CMainFrame::OnShowedittoolbar()  
{ 
	// TODO: Add your command handler code here 
 
	if(edittoolbar.IsVisible()) 
		edittoolbar.ShowWindow(SW_HIDE) ; 
	else edittoolbar.ShowWindow(SW_SHOW) ; 
	RecalcLayout(); 
} 
 
void CMainFrame::OnUpdateShowedittoolbar(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	pCmdUI->SetCheck(edittoolbar.IsVisible()); 
} 
 
void CMainFrame::OnShowshowtoolbar()  
{ 
	// TODO: Add your command handler code here 
	if(showtoolbar.IsVisible()) 
		showtoolbar.ShowWindow(SW_HIDE) ; 
	else showtoolbar.ShowWindow(SW_SHOW) ; 
	RecalcLayout(); 
} 
 
void CMainFrame::OnUpdateShowshowtoolbar(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	pCmdUI->SetCheck(showtoolbar.IsVisible()); 
} 
 
void CMainFrame::OnShowdrawtoolbar()  
{ 
	// TODO: Add your command handler code here 
		if(drawtoolbar.IsVisible()) 
		drawtoolbar.ShowWindow(SW_HIDE) ; 
	else drawtoolbar.ShowWindow(SW_SHOW) ; 
		RecalcLayout(); 
} 
 
void CMainFrame::OnUpdateShowdrawtoolbar(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
		pCmdUI->SetCheck(drawtoolbar.IsVisible()); 
} 
 
void CMainFrame::OnShowstatuscoolbar()  
{ 
	// TODO: Add your command handler code here 
 
	if(statuscoolbar.IsVisible()) 
		statuscoolbar.ShowWindow(SW_HIDE) ; 
	else statuscoolbar.ShowWindow(SW_SHOW) ; 
		RecalcLayout(); 
 
} 
 
void CMainFrame::OnUpdateShowstatuscoolbar(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	pCmdUI->SetCheck(statuscoolbar.IsVisible());	 
} 
 
 
void CMainFrame::OnShowtreecoolbar()  
{ 
	// TODO: Add your command handler code here 
	if(treecoolbar.IsVisible()) 
		treecoolbar.ShowWindow(SW_HIDE) ; 
	else treecoolbar.ShowWindow(SW_SHOW) ; 
		RecalcLayout(); 
	 
} 
 
void CMainFrame::OnUpdateShowtreecoolbar(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	pCmdUI->SetCheck(treecoolbar.IsVisible());	 
} 
 
void CMainFrame::OnTimer(UINT nIDEvent)  
{ 
	CMDIChildWnd *pChild =MDIGetActive(); 
	if(pChild) 
	{ 
	CDEMView *pView=(CDEMView*)pChild->GetActiveView(); 
	if(pView->maploadok&pView->drawlengend){pView->DrawLengend();pView->drawlengend=false;} 
	} 
	// TODO: Add your message handler code here and/or call default 
	CTime tmCurr; 
	CString strTime; 
	tmCurr=CTime::GetCurrentTime(); 
	strTime=tmCurr.Format("%H:%M:%S"); 
	m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_TIME),strTime); 
	 
	CFrameWnd::OnTimer(nIDEvent); 
	CMDIFrameWnd::OnTimer(nIDEvent); 
} 
 
void CMainFrame::OnSelchangeShowscale() 
{ 
	CString cs;  
	drawtoolbar.showscalecombox.GetLBText(drawtoolbar.showscalecombox.GetCurSel(),cs);  
	UpdateData(0);  
	float scale;char c; 
	sscanf(cs,"%f%c",&scale,&c); 
	scale/=100; 
	CMDIChildWnd *pChild =MDIGetActive(); 
	CDEMView *pView=(CDEMView*)pChild->GetActiveView(); 
 
	CPoint point(pView->mapview.GetViewExt().x/2,pView->mapview.GetViewExt().y/2); 
	pView->Getmapview().SetShowScale(scale/pView->Getmapview().scale,point); 
	pView->Invalidate(); 
} 
 
 
void CMainFrame::OnEditchangeShowscale() 
{ 
 
} 
 
 
void CMainFrame::OnFileOpen()  
{ 
	// TODO: Add your command handler code here 
	SendMessage(WM_COMMAND,ID_FILE_NEW); 
	CMDIChildWnd *pChild =MDIGetActive(); 
	pChild->ShowWindow(SW_SHOWMAXIMIZED); 
	SendMessage(WM_COMMAND,ID_FILE_OPEN); 
} 
 
void CMainFrame::OnShowWindow(BOOL bShow, UINT nStatus)  
{ 
	CMDIFrameWnd::OnShowWindow(bShow, nStatus); 
	 
	// TODO: Add your message handler code here 
 
} 
 
void CMainFrame::OnSelchangeMapcolor() 
{ 
	CString cs;  
	drawtoolbar.mapcolorcombox.GetLBText(drawtoolbar.mapcolorcombox.GetCurSel(),cs);  
	UpdateData(0);  
	CMDIChildWnd *pChild =MDIGetActive(); 
	CDEMView *pView=(CDEMView*)pChild->GetActiveView(); 
	pView->demdata->mapcolor=cs; 
	pView->demdata->matchcolor(); 
	pView->UpDataDemDraw(); 
	pView->Invalidate(); 
	pView->DrawLengend(); 
	pView->drawlengend=false; 
} 
 
void CMainFrame::OnUpdateShowscale(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	CMDIChildWnd *pChild =MDIGetActive(); 
	if(!pChild)pCmdUI->Enable(false);	 
} 
 
void CMainFrame::OnUpdateMapcolor(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	CMDIChildWnd *pChild =MDIGetActive(); 
	if(!pChild)pCmdUI->Enable(false);		 
} 
 
 
////////////////////////////////////////////////////////////////////// 
//全屏显示 
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)  
{ 
	// TODO: Add your message handler code here and/or call default 
	if (m_bFullScreen) 
    { 
        lpMMI->ptMaxSize.y =m_FullScreenWindowRect.Height(); 
	    lpMMI->ptMaxTrackSize.y =m_FullScreenWindowRect.Height(); 
	    lpMMI->ptMaxSize.x =m_FullScreenWindowRect.Width(); 
	    lpMMI->ptMaxTrackSize.x =m_FullScreenWindowRect.Width(); 
    }	 
	CMDIFrameWnd::OnGetMinMaxInfo(lpMMI); 
} 
 
void CMainFrame::OnFullscreem()  
{ 
	// TODO: Add your command handler code here 
 
    if (!m_bFullScreen)	FullScreen(); 
    else ExitFullScreen(); 
} 
 
void CMainFrame::OnUpdateFullscreem(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	pCmdUI->SetCheck(m_bFullScreen);	 
} 
 
void CMainFrame::FullScreen() 
{ 
		RECT rectDesktop; 
		WINDOWPLACEMENT wpNew; 
        // need to hide all status bars 
 
		edittoolbar.ShowWindow(SW_HIDE) ; 
		statuscoolbar.ShowWindow(SW_HIDE) ; 
		treecoolbar.ShowWindow(SW_HIDE) ; 
		m_wndStatusBar.ShowWindow(SW_HIDE); 
	    m_wndToolBar.ShowWindow(SW_HIDE); 
 
	    // We'll need these to restore the original state. 
	    GetWindowPlacement (&m_wpPrev); 
 
	    m_wpPrev.length = sizeof m_wpPrev; 
 
        //Adjust RECT to new size of window 
	    ::GetWindowRect ( ::GetDesktopWindow(), &rectDesktop ); 
	    ::AdjustWindowRectEx(&rectDesktop, GetStyle(), TRUE, GetExStyle()); 
 
	    // Remember this for OnGetMinMaxInfo() 
	    m_FullScreenWindowRect = rectDesktop; 
         
        wpNew = m_wpPrev; 
        wpNew.showCmd =  SW_SHOWNORMAL; 
	    wpNew.rcNormalPosition = rectDesktop; 
		m_bFullScreen=TRUE; 
		SetWindowPlacement ( &wpNew ); 
} 
 
void CMainFrame::ExitFullScreen() 
{ 
        m_bFullScreen=FALSE; 
 
		edittoolbar.ShowWindow(SW_SHOWNORMAL) ; 
		statuscoolbar.ShowWindow(SW_SHOWNORMAL) ; 
		treecoolbar.ShowWindow(SW_SHOWNORMAL) ; 
 
		m_wndStatusBar.ShowWindow(SW_SHOWNORMAL); 
	     m_wndToolBar.ShowWindow(SW_SHOWNORMAL); 
        SetWindowPlacement ( &m_wpPrev); 
} 
 
 
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)  
{ 
	// TODO: Add your specialized code here and/or call the base class 
       if (pMsg->message == WM_KEYDOWN) 
       { 
              switch (pMsg->wParam) 
              { 
             case 27://发送通知消息 
				ExitFullScreen(); 
				  break; 
			  } 
		}	 
	return CMDIFrameWnd::PreTranslateMessage(pMsg); 
}