⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.cpp

📁 《面向对象程序设计实用教程》一书的源码
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "cge.h"
#include "MainFrm.h"
#include "Splash.h"
#include "cgeView.h"
#include "View0.h"
#include "View1.h"
#include "View2.h"
#include "filepath.h"
#include <direct.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)
	ON_COMMAND_EX(CG_ID_VIEW_MYDIALOGBAR, OnBarCheck)
	ON_UPDATE_COMMAND_UI(CG_ID_VIEW_MYDIALOGBAR, OnUpdateControlBarMenu)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_COMMAND(ID_VIEW_FULLSCR, OnViewFullscr)
	ON_COMMAND(ID_VIEW_STANDARD, OnViewStandard)
	ON_WM_GETMINMAXINFO()
	ON_COMMAND(ID_TDBAR, OnTdbar)
	ON_UPDATE_COMMAND_UI(ID_TDBAR, OnUpdateTdbar)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_SEPARATOR,
	ID_SEPARATOR,
	//ID_SEPARATOR,
	//ID_INDICATOR_CAPS,
	//ID_INDICATOR_NUM,
	//ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	m_bFullScreen = FALSE;
	
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if (!m_wndToolBar.Create(this) ||
		!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
	}
    
	dtKey = true;
	//立体条
	m_wndStatusBar.SetPaneInfo(0,0,SBPS_STRETCH,0);
	//设置StatusBar Pane Width
	UINT nID, nStyle;
	int nWidth;
	int m_nTimePaneNo=1;
	m_wndStatusBar.GetPaneInfo(m_nTimePaneNo, nID, nStyle, nWidth);
	m_wndStatusBar.SetPaneInfo(m_nTimePaneNo, nID, nStyle, 76);
	m_wndStatusBar.SetPaneInfo(m_nTimePaneNo+1, nID, nStyle, 50);
	m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
		CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

	// 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);

	// TODO: Add a menu item that will toggle the visibility of the	// dialog bar named "My Dialog Bar":	//   1. In ResourceView, open the menu resource that is used by	//      the CMainFrame class	//   2. Select the View submenu	//   3. Double-click on the blank item at the bottom of the submenu	//   4. Assign the new item an ID: CG_ID_VIEW_MYDIALOGBAR	//   5. Assign the item a Caption: My Dialog Bar	// TODO: Change the value of CG_ID_VIEW_MYDIALOGBAR to an appropriate value:	//   1. Open the file resource.h	// CG: The following block was inserted by the 'Dialog Bar' component	{		// Initialize dialog bar m_wndMyDialogBar		if (!m_wndMyDialogBar.Create(this, CG_IDD_MYDIALOGBAR,			CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_HIDE_INPLACE,
			//CBRS_RIGHT | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_HIDE_INPLACE,			CG_ID_VIEW_MYDIALOGBAR))		{			TRACE0("Failed to create dialog bar m_wndMyDialogBar\n");			return -1;		// fail to create		}
		m_wndMyDialogBar.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);//		m_wndMyDialogBar.EnableDocking(CBRS_ALIGN_RIGHT   );
		EnableDocking(CBRS_ALIGN_ANY);		DockControlBar(&m_wndMyDialogBar);		
		CRect rect, rect1; //M
		m_wndToolBar.GetWindowRect(&rect1);
		m_wndMyDialogBar.GetWindowRect(&rect);

		//WINDOWPLACEMENT Placement;
		//m_wndMyDialogBar.GetWindowPlacement(&Placement); //ptMaxPosition = 0,0
		//Placement.rcNormalPosition = {rect1.Width(), rect1.top, rect.Width(), rect1.Height()};
		/*Placement.rcNormalPosition.left = rect1.Width();
		Placement.rcNormalPosition.top = rect1.top;
		Placement.rcNormalPosition.right = rect.Width();;
		Placement.rcNormalPosition.bottom = rect1.Height();
		m_wndMyDialogBar.SetWindowPlacement(&Placement);*/
		//CRect rect, rect1;
		//m_wndToolBar.GetWindowRect(&rect1);
		//m_wndMyDialogBar.GetWindowRect(&rect);
		//DWORD style = m_wndMyDialogBar.GetStyle();
		//BOOL tmp;
		//tmp = m_wndMyDialogBar.SetWindowPos( &m_wndToolBar, //, &wndTop, // &wndTopMost,  &m_wndToolBar, 
		//		rect1.Width(), rect1.top, rect.Width(), rect1.Height(), SWP_SHOWWINDOW);//SWP_NOSIZE);//style);
								//M
		//m_wndMyDialogBar.MoveWindow(380, 0, 60, 10,true);	}    m_standardstretchKey = false;
	m_HVstretchKey = false;
	//C++中,基类的对象或对象指针必须经过强制转换后才可以赋值给派生类的对象或对象指针,
	//这样使用可能发生危险,因为这样的派生类对象或指针对象中可能只有基类中的成员
	//而派生类的对象或对象指针可以直接赋值给基类的对象或对象指针,因为派生类中包含了基类中的所有成员
	//CSpinButtonCtrl* pspinbutton 
	  //= (CSpinButtonCtrl* )m_wndMyDialogBar.GetDlgItem(IDC_DLGBARSPIN3);
    //pspinbutton->SetRange (-10,10);
    //pspinbutton->SetPos(0);

    m_wndMyDialogBar.GetDlgItem(IDC_DLGBARCOMBO1)->SetWindowText(_T("40"));

    ShowWindow(SW_SHOWMAXIMIZED);

	DockControlBarLeftOf(&m_wndMyDialogBar,&m_wndToolBar);
	//OnPotMessage(WM_SYSCOMMAND,SW_SHOWMAXIMIZED);
	// CG: The following line was added by the Splash Screen component.	CSplashWnd::ShowSplashScreen(this);
	return 0;
}
void CMainFrame::DockControlBarLeftOf(CDialogBar* Bar,CToolBar* LeftOf)
{ 	 //设置工具条并列停靠在同一条边上
     //矩形区域定义        
	 CRect rect;
	 DWORD dw;
     UINT n=0;
//重新显示
     RecalcLayout();
	 LeftOf->GetWindowRect(&rect);
//设置偏移值以停靠在同一边上
     rect.OffsetRect(1,0);
	 dw=LeftOf->GetBarStyle();
	 n=(dw&CBRS_ALIGN_TOP)?AFX_IDW_DOCKBAR_TOP:n;
     n=(dw&CBRS_ALIGN_BOTTOM && n==0)?AFX_IDW_DOCKBAR_BOTTOM:n; 
	 n=(dw&CBRS_ALIGN_LEFT && n==0)?AFX_IDW_DOCKBAR_LEFT:n; 
	 n=(dw&CBRS_ALIGN_RIGHT && n==0)?AFX_IDW_DOCKBAR_RIGHT:n; 
	 DockControlBar(Bar,n,&rect);
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	//WIN95 工控窗口属性设置
	cs.style &= ~WS_MINIMIZEBOX;
	//m_607 win98窗口属性设置
	//cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
	//	| WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZE | WS_MAXIMIZEBOX;
	return CFrameWnd::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers

//DEL void CMainFrame::OnDlgbarbutton1() 
//DEL {
//DEL     m_wndMyDialogBar.GetDlgItem(IDC_DLGBAREDIT2)->GetWindowText(Strbil);
//DEL     m_standardstretchKey = true;
//DEL 	CCgeDoc pDoc=GetDocument();
//DEL 	//pDoc->m_stepX=10;
//DEL 	m_HVstretchKey = false;
//DEL 	RedrawWindow(NULL,NULL);
//DEL 	//Invalidate();//指视窗的全部重画
//DEL 	//UpdateWindow();
//DEL 
//DEL }



BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
	int cxl = 20;
	int cyr = 940;
	int cx = 520;
	int cy = 960;
	if (!m_wndSplitter.CreateStatic(this, 2, 2))
	{
		TRACE0("Failed to CreateStatic Splitter\n");
		return FALSE;
	}
	
	//m_wndSplitter.SetRowInfo(1, 50, 10);//

	if (!m_wndSplitter.CreateView(0, 0,
		RUNTIME_CLASS(CView0), CSize(cxl, cy-cyr), pContext))
	{
		TRACE0("Failed to create first pane\n");
		return FALSE;
	}

	if (!m_wndSplitter.CreateView(0, 1,
		RUNTIME_CLASS(CView1), CSize(cx-cxl, cy-cyr), pContext))
	{
		TRACE0("Failed to create second pane\n");
		return FALSE;
	}
	if (!m_wndSplitter.CreateView(1, 0,
		RUNTIME_CLASS(CView2), CSize(cxl, cyr), pContext))
	{
		TRACE0("Failed to create third pane\n");
		return FALSE;
	}
	if (!m_wndSplitter.CreateView(1, 1,
		RUNTIME_CLASS(CCgeView), CSize(cx-cxl, cyr), pContext))
	{
		TRACE0("Failed to create f orth pane\n");
		return FALSE;                                           
	}

	m_wndSplitter.SetActivePane(1,1);  //(0,1)
	return TRUE;

}


//static char szFilter[] = "Accounting Files (*.dat)|*.dat|All Files (*.*)|*.*||";
//static char lpstrCustomFilter[255]={"Previous Filter\0*.dat\0"};
//#define MAX_PATH          260
//DEL void CMainFrame::OnParaNew() 
//DEL {
//DEL 		FilePath dlg(
//DEL 		false,						
//DEL 		_T(".dat"),					//default filename extension
//DEL 		"",							//initial filename in edit box
//DEL // functionality flags
//DEL //		OFN_ALLOWMULTISELECT| 		//allow multiple files to be selected
//DEL 		OFN_CREATEPROMPT |			// if File Save As, prompts user if they want to create non-existant file
//DEL 		OFN_OVERWRITEPROMPT |		// if File Save As--prompts user to ask if they want to overwrite an existing file
//DEL 		OFN_ENABLESIZING |  		// if Windows NT 5.0 or Win 98, causes box to be resizable by user
//DEL 		//OFN_EXTENSIONDIFFERENT|		// allows user to enter a filename with a different extension from the default
//DEL //		OFN_FILEMUSTEXIST 			// file must exist
//DEL //		OFN_NOLONGNAMES |			// causes dialog to use short filenames (8.3)
//DEL //		OFN_PATHMUSTEXIST |			// user can only type valid paths and filenames
//DEL //		OFN_NOVALIDATE |			// the returned filname can have invalid characters
//DEL // appearence flags
//DEL //		OFN_HIDEREADONLY |			// hides read-only check box
//DEL //		OFN_NONETWORKBUTTON |		// hides Network button
//DEL 		OFN_READONLY |				// initially check Read Only check box
//DEL //		OFN_SHOWHELP |				// Help button appears--when clicked the hook procedure gets a CDN_HELP message
//DEL // custom template flags
//DEL 		OFN_ENABLETEMPLATE | 		// you will be supplying your own custom dialog box template
//DEL 		0,
//DEL 		szFilter,					//file filter
//DEL 		this);						// parent window
//DEL 
//DEL 		// set an initial directory
//DEL         char lpszInitDir[MAX_PATH];
//DEL 	    _getcwd(lpszInitDir,MAX_PATH);  		
//DEL 		dlg.m_ofn.lpstrInitialDir=lpszInitDir;
//DEL 
//DEL 		//set the dialog's title
//DEL 		char lpszTitle[]={"Save As File"};
//DEL 		dlg.m_ofn.lpstrTitle=lpszTitle;
//DEL 
//DEL 		// retain the customer's last file filter selection
//DEL 		dlg.m_ofn.lpstrCustomFilter=lpstrCustomFilter;
//DEL 		dlg.m_ofn.nMaxCustFilter=255;
//DEL 
//DEL 		// if OFN_ENABLETEMPLATE is set, define the custom dialog template here
//DEL 		dlg.m_ofn.lpTemplateName=MAKEINTRESOURCE(IDD_DIALOGBAR_NEWFILE);
//DEL 
//DEL 		// open file dialog and get file name(s)
//DEL 		if (dlg.DoModal()==IDOK)
//DEL 		{
//DEL 			// get filter number selected (index into filter list that user selected)
//DEL 			int nFilterIndex=dlg.m_ofn.nFilterIndex;
//DEL 
//DEL 			// get file name
//DEL 			CString path=dlg.GetPathName();		//ex: c:\temp\temp.tmp
//DEL 			CString file=dlg.GetFileName();		//ex: temp.tmp
//DEL 			CString title=dlg.GetFileTitle();	//ex: temp
//DEL 			CString ext=dlg.GetFileExt();		//ex: tmp	  
//DEL 
//DEL 		//	CCgeDoc* pDoc = (CCgeDoc* )GetDocument();
//DEL 		//	ASSERT_VALID(pDoc);
//DEL 		    
//DEL 			AfxMessageBox(dlg.m_StrLine);	
//DEL 			BOOL bReadOnly = dlg.GetReadOnlyPref();
//DEL 
//DEL 			// if OFN_ALLOWMULTISELECT is set, loop to get all file names
//DEL 			for (POSITION pos=dlg.GetStartPosition();pos;)
//DEL 			{
//DEL 				CString pathx=dlg.GetNextPathName(pos); 
//DEL 			}
//DEL 		}	
//DEL }


CDialogBar& CMainFrame::GetDlgBar()
{
	return m_wndMyDialogBar;
}



void CMainFrame::OnViewFullscr() 
{
	GetWindowPlacement(&m_Oldwndpl);

	CRect WindowRect,ClientRect;
	GetWindowRect(&WindowRect);

	RepositionBars(0,0xffff,AFX_IDW_PANE_FIRST,
				   reposQuery,&ClientRect);
	ClientToScreen(&ClientRect);

	int nFullWidth = GetSystemMetrics(SM_CXSCREEN);
	int nFullHeight = GetSystemMetrics(SM_CYSCREEN);

	m_FullScreenRect.left = WindowRect.left-ClientRect.left;
	m_FullScreenRect.top = WindowRect.top-ClientRect.top;
	m_FullScreenRect.right = WindowRect.right-ClientRect.right
							+nFullWidth;
	m_FullScreenRect.bottom = WindowRect.bottom-ClientRect.bottom
							+nFullHeight;
    
	m_bFullScreen = TRUE;
	//
	WINDOWPLACEMENT wndpl;
	wndpl.length = sizeof(WINDOWPLACEMENT);
	wndpl.flags = 0;
	wndpl.showCmd = SW_SHOWNORMAL;
	wndpl.rcNormalPosition = m_FullScreenRect;
    SetWindowPlacement (&wndpl);
	//	Invalidate();

	
}

void CMainFrame::OnViewStandard() 
{
	if (!m_bFullScreen)
	{
		AfxMessageBox("当前状态即为标准显示!");
		return;
	}
	if (m_bFullScreen)
	{
		m_bFullScreen = FALSE;
		ShowWindow(SW_HIDE);
		SetWindowPlacement(&m_Oldwndpl);
	
	}
	
}

void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 
{
	if (m_bFullScreen)
	{
		lpMMI->ptMaxSize.x = m_FullScreenRect.Width();
		lpMMI->ptMaxSize.y = m_FullScreenRect.Height();
		lpMMI->ptMaxPosition.x = m_FullScreenRect.left;
		lpMMI->ptMaxPosition.y = m_FullScreenRect.top;

		lpMMI->ptMaxTrackSize.x = m_FullScreenRect.Width();
		lpMMI->ptMaxTrackSize.y = m_FullScreenRect.Height();
	}
	
	CFrameWnd::OnGetMinMaxInfo(lpMMI);
}



void CMainFrame::OnTdbar() 
{	
	dtKey = !dtKey;
	m_wndMyDialogBar.ShowWindow(dtKey);
 	m_wndToolBar.ShowWindow(dtKey);
	ShowWindow(SW_SHOWNORMAL);
	ShowWindow(SW_SHOWMAXIMIZED);
	//ShowWindow(SW_SHOWNA    );  
	//RedrawWindow();
}

void CMainFrame::OnUpdateTdbar(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(dtKey);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -