www.pudn.com > DEM.zip > MainFrm.cpp, change:2007-01-23,size:4741b


// MainFrm.cpp : implementation of the CMainFrame class 
// 
 
#include "stdafx.h" 
#include "DEM.h" 
#include "MainFrm.h" 
#include "Splash.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() 
	//}}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 
	 
} 
 
CMainFrame::~CMainFrame() 
{ 
} 
 
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{ 
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1) 
		return -1; 
 
	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(CreateExToolBar()==-1) 
	{ 
		MessageBox("失败"); 
	} 
	// TODO: Delete these three lines if you don't want the toolbar to 
	//  be dockable 
 
	// CG: The following line was added by the Splash Screen component.
	CSplashWnd::ShowSplashScreen(this); 
	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 
	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::CreateExToolBar() 
{ 
	CImageList img; 
	CString str; 
	if (!m_myToolBar.CreateEx(this)) 
	{ 
		return -1;		 
	} 
	m_myToolBar.GetToolBarCtrl().SetButtonWidth(40, 100); 
	//改变属性 
	m_myToolBar.ModifyStyle(0, TBSTYLE_FLAT |CBRS_TOOLTIPS |  
							TBSTYLE_TRANSPARENT|TBBS_CHECKBOX ); 
	//设置按钮数为6 
	m_myToolBar.SetButtons(NULL,7);	 
		// 2. 添加图像 
	//设置"热/hot"状态的的位图 
	img.Create(28, 28, ILC_COLOR8|ILC_MASK,2,2); 
	img.SetBkColor(RGB(0, 0, 102)); 
	//顺序增添按键的图标 
	img.Add(AfxGetApp()->LoadIcon(IDR_FILE_OPEN)); 
	img.Add(AfxGetApp()->LoadIcon(IDR_ZOOM)); 
	img.Add(AfxGetApp()->LoadIcon(IDR_SHORTEN)); 
	img.Add(AfxGetApp()->LoadIcon(IDR_LEFT)); 
	img.Add(AfxGetApp()->LoadIcon(IDR_RIGHT)); 
	img.Add(AfxGetApp()->LoadIcon(IDR_NORMAL)); 
	img.Add(AfxGetApp()->LoadIcon(IDR_HELP)); 
 
	m_myToolBar.GetToolBarCtrl().SetHotImageList(&img); 
	img.Detach();	 
	//设置"冷/cold"状态的位图 
	img.Create(26, 26, ILC_COLOR8|ILC_MASK, 2,2); 
	img.SetBkColor(::GetSysColor(COLOR_BTNFACE)); 
	img.Add(AfxGetApp()->LoadIcon(IDR_FILE_OPEN)); 
	img.Add(AfxGetApp()->LoadIcon(IDR_ZOOM)); 
	img.Add(AfxGetApp()->LoadIcon(IDR_SHORTEN)); 
	img.Add(AfxGetApp()->LoadIcon(IDR_LEFT)); 
	img.Add(AfxGetApp()->LoadIcon(IDR_RIGHT)); 
	img.Add(AfxGetApp()->LoadIcon(IDR_NORMAL)); 
	img.Add(AfxGetApp()->LoadIcon(IDR_HELP)); 
 
	m_myToolBar.GetToolBarCtrl().SetImageList(&img); 
	img.Detach(); 
 
	m_myToolBar.SetButtonInfo(0, ID_FILE_OPEN, TBSTYLE_BUTTON, 0); 
	m_myToolBar.SetButtonText(0, "打开DEM文件"); 
	 
	m_myToolBar.SetButtonInfo(1, ID_VIEW_ZOOM, TBSTYLE_BUTTON, 1); 
	m_myToolBar.SetButtonText(1, "放大"); 
	 
	m_myToolBar.SetButtonInfo(2, ID_VIEW_SHORTEN, TBSTYLE_BUTTON, 2); 
	m_myToolBar.SetButtonText(2, "缩小"); 
 
	m_myToolBar.SetButtonInfo(3, ID_VIEW_LEFT, TBSTYLE_BUTTON, 3); 
	m_myToolBar.SetButtonText(3, "左移"); 
 
	m_myToolBar.SetButtonInfo(4, ID_VIEW_RIGHT, TBSTYLE_BUTTON, 4); 
	m_myToolBar.SetButtonText(4, "右移"); 
 
 
	m_myToolBar.SetButtonInfo(5, ID_VIEW_STOP, TBSTYLE_BUTTON, 5); 
	m_myToolBar.SetButtonText(5, "停止漫游"); 
 
	m_myToolBar.SetButtonInfo(6, ID_VIEW_HELP, TBSTYLE_BUTTON, 6); 
	m_myToolBar.SetButtonText(6, "帮助"); 
 
	CRect rectToolBar; 
	//得到按钮的大小 
	m_myToolBar.GetItemRect(0, &rectToolBar); 
	//设置按钮的大小 
	m_myToolBar.SetSizes(rectToolBar.Size(), CSize(26,26)); 
 
	m_myToolBar.EnableDocking(CBRS_ALIGN_ANY); 
	//允许停靠 
	EnableDocking(CBRS_ALIGN_ANY); 
	//漂浮停靠 
	CPoint pt(GetSystemMetrics(SM_CXSCREEN)/2-500,GetSystemMetrics(SM_CYSCREEN)/3-200); 
	FloatControlBar(&m_myToolBar,pt); 
	return TRUE; 
}