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

📄 mainfrm.cpp

📁 BCGCBDotNetExample 修改后的通用模板
💻 CPP
📖 第 1 页 / 共 2 页
字号:

    if (pMenuPopup->GetMenuBar ()->CommandToIndex (ID_VIEW_TOOLBARS) >= 0)
    {
		if (CBCGPToolBar::IsCustomizeMode ())
		{
			return FALSE;
		}

		pMenuPopup->RemoveAllItems ();

		CMenu menu;
		VERIFY(menu.LoadMenu (IDR_POPUP_TOOLBAR));

		CMenu* pPopup = menu.GetSubMenu(0);
		ASSERT(pPopup != NULL);

		SetupToolbarMenu (*pPopup, ID_VIEW_USER_TOOLBAR1, ID_VIEW_USER_TOOLBAR10);
		pMenuPopup->GetMenuBar ()->ImportFromMenu (*pPopup, TRUE);
    }

	return TRUE;
}

void CMainFrame::OnViewOutput() 
{
	ShowControlBar (&m_wndOutputView,
					!m_wndOutputView.IsVisible (),
					FALSE, FALSE);
	RecalcLayout ();
}

void CMainFrame::OnUpdateViewOutput(CCmdUI* pCmdUI) 
{
	if (pCmdUI->m_pOther != NULL &&
		!pCmdUI->m_pOther->IsKindOf (RUNTIME_CLASS (CBCGPPopupMenuBar)))
	{
		pCmdUI->SetCheck (m_wndOutputView.IsVisible ());
	}
}


void CMainFrame::OnWindowManager() 
{
	ShowWindowsDialog ();
}

BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext) 
{
	if (!CMDIFrameWnd::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext))
	{
		return FALSE;
	}

	// Add some tools for example....
	CBCGPUserToolsManager* pUserToolsManager = theApp.GetUserToolsManager ();
	if (pUserToolsManager != NULL &&
		pUserToolsManager->GetUserTools ().IsEmpty ())
	{
		CBCGPUserTool* pTool1 = pUserToolsManager->CreateNewTool ();
		pTool1->m_strLabel = _T("Notepad");
		pTool1->SetCommand (_T("notepad.exe"));

		CBCGPUserTool* pTool2 = pUserToolsManager->CreateNewTool ();
		pTool2->m_strLabel = _T("Paint Brush");
		pTool2->SetCommand (_T("mspaint.exe"));

		CBCGPUserTool* pTool3 = pUserToolsManager->CreateNewTool ();
		pTool3->m_strLabel = _T("Windows Explorer");
		pTool3->SetCommand (_T("explorer.exe"));

		CBCGPUserTool* pTool4 = pUserToolsManager->CreateNewTool ();
		pTool4->m_strLabel = _T("BCGSoft On-Line");
		pTool4->SetCommand (_T("http://www.bcgsoft.com"));
	}

	EnableMDITabs (TRUE, FALSE, CBCGPTabWnd::LOCATION_TOP, TRUE);

	//----------------------------------------------------
	// Enable customization button fore all user toolbars:
	//----------------------------------------------------
	for (int i = 0; i < iMaxUserToolbars; i ++)
	{
		CBCGPToolBar* pUserToolbar = GetUserBarByIndex (i);
		if (pUserToolbar != NULL)
		{
			pUserToolbar->EnableCustomizeButton (TRUE, ID_VIEW_CUSTOMIZE, _T("Customize..."));
		}
	}


	return TRUE;
}

BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
{
	return CMDIFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}


void CMainFrame::OnHelpKeyboardmap() 
{
	CBCGPKeyMapDlg dlg (this, TRUE /* Enable Print */);
	dlg.DoModal ();
}

void CMainFrame::OnContextMenu(CWnd* pWnd, CPoint point) 
{
		CMenu menu;
		menu.LoadMenu(IDR_POPUP_MDITABS);
		
		CMenu* pSumMenu = menu.GetSubMenu(0);
		
		if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CBCGPMDIFrameWnd)))
		{
			CBCGPPopupMenu* pPopupMenu = new CBCGPPopupMenu;
			
			if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE))
				return;
			
		((CBCGPMDIFrameWnd*)AfxGetMainWnd())->OnShowPopupMenu (pPopupMenu);
		UpdateDialogControls(this, FALSE);
	}
	
	SetFocus ();

	
	
}

void CMainFrame::OnViewClass() 
{
	// demonstartes how to make bar active in autohide mode and inactive when non-tabbed
	BOOL bAutoHideMode = m_wndClassView.IsAutoHideMode ();
	BOOL bTabbed = m_wndClassView.IsTabbed ();

	ShowControlBar (&m_wndClassView,
					!m_wndClassView.IsVisible (),
					FALSE, bAutoHideMode || !bTabbed);
	RecalcLayout ();
}

void CMainFrame::OnUpdateViewClass(CCmdUI* pCmdUI) 
{
	if (pCmdUI->m_pOther != NULL &&
		!pCmdUI->m_pOther->IsKindOf (RUNTIME_CLASS (CBCGPPopupMenuBar)))
	{
		pCmdUI->SetCheck (m_wndClassView.IsVisible ());	
	}
}

void CMainFrame::OnViewResource() 
{
	// demonstartes how to make bar active in autohide mode and inactive when non-tabbed
	BOOL bAutoHideMode = m_wndResourceView.IsAutoHideMode ();
	BOOL bTabbed = m_wndResourceView.IsTabbed ();

	ShowControlBar (&m_wndResourceView,
					!m_wndResourceView.IsVisible (),
					FALSE, bAutoHideMode || !bTabbed);
	RecalcLayout ();
}

void CMainFrame::OnUpdateViewResource(CCmdUI* pCmdUI) 
{
	if (pCmdUI->m_pOther != NULL &&
		!pCmdUI->m_pOther->IsKindOf (RUNTIME_CLASS (CBCGPPopupMenuBar)))
	{
		pCmdUI->SetCheck (m_wndResourceView.IsVisible ());	
	}
}




//***************************************************************************************
LRESULT CMainFrame::OnToolbarCreateNew(WPARAM wp,LPARAM lp)
{
	LRESULT lres = CBCGPMDIFrameWnd::OnToolbarCreateNew (wp,lp);
	if (lres == 0)
	{
		return 0;
	}

	CBCGPToolBar* pUserToolbar = (CBCGPToolBar*) lres;
	ASSERT_VALID (pUserToolbar);

	pUserToolbar->EnableCustomizeButton (TRUE, ID_VIEW_CUSTOMIZE, _T("Customize..."));
	return lres;
}
//*************************************************************************************
BOOL CMainFrame::CreateDockingBars ()
{
	//------------------
	// Crate class view:
	//------------------
	if (!m_wndClassView.Create (_T("光缆"), this, CRect (0, 0, 200, 200),
		TRUE, 
		ID_VIEW_CLASS,
		WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
	{
		TRACE0("Failed to create Class View bar\n");
		return FALSE;      // fail to create
	}

	HICON hClassViewIcon = (HICON) ::LoadImage (::AfxGetResourceHandle (), 
				MAKEINTRESOURCE (IDI_CLASS_VIEW),
				IMAGE_ICON, ::GetSystemMetrics (SM_CXSMICON), ::GetSystemMetrics (SM_CYSMICON), 0);
	m_wndClassView.SetIcon (hClassViewIcon, FALSE);

	//----------------------
	// Create resource view:
	//----------------------
	if (!m_wndResourceView.Create (_T("设备管理"), this, CRect (0, 0, 250, 250),
		TRUE, 
		ID_VIEW_RESOURCE,
		WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
	{
		TRACE0("Failed to create Resource View bar\n");
		return FALSE;      // fail to create
	}

	HICON hResViewIcon = (HICON) ::LoadImage (::AfxGetResourceHandle (), 
				MAKEINTRESOURCE (IDI_RES_VIEW),
				IMAGE_ICON, ::GetSystemMetrics (SM_CXSMICON), ::GetSystemMetrics (SM_CYSMICON), 0);
	m_wndResourceView.SetIcon (hResViewIcon, FALSE);


	if (!m_wndResourceView2.Create (_T("线路管理"), this, CRect (0, 0, 250, 250),
		TRUE, 
		ID_TEST,
		WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
	{
		TRACE0("Failed to create Resource View bar\n");
		return FALSE;      // fail to create
	}
	
	hResViewIcon = (HICON) ::LoadImage (::AfxGetResourceHandle (), 
		MAKEINTRESOURCE (IDI_RES_VIEW),
		IMAGE_ICON, ::GetSystemMetrics (SM_CXSMICON), ::GetSystemMetrics (SM_CYSMICON), 0);
	m_wndResourceView2.SetIcon (hResViewIcon, FALSE);

	//////////////////////////////////New Output////////////////////////////////////////
	if (!m_wndOutputView.Create (_T("Output"), this, CRect (0, 0, 250, 250),
		TRUE, 
		ID_VIEW_OUTPUT,
		WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI))
	{
		TRACE0("Failed to create output bar\n");
		return FALSE;      // fail to create
	}

	HICON hOutputBarIcon = (HICON) ::LoadImage (::AfxGetResourceHandle (), 
				MAKEINTRESOURCE (IDI_OUTPUT_BAR),
				IMAGE_ICON, ::GetSystemMetrics (SM_CXSMICON), ::GetSystemMetrics (SM_CYSMICON), 0);
	m_wndOutputView.SetIcon (hOutputBarIcon, FALSE);

	////////////////////////////////////////////////////////////////////////////////////

	return TRUE;
}










void CMainFrame::OnViewRefresh() 
{
	// TODO: Add your command handler code here
}

void CMainFrame::OnToolsConnectToDatabase() 
{
	// TODO: Add your command handler code here
}

void CMainFrame::OnToolsDebugProcesses() 
{
	// TODO: Add your command handler code here
	
}

void CMainFrame::OnClose() 
{
	if (IsFullScreen())
		OnViewFullScreen();	// Return to normal mode 

	CMDIFrameWnd::OnClose();
}

void CMainFrame::OnUpdateViewFullScreen(CCmdUI* pCmdUI)
{
	pCmdUI->Enable(TRUE);
	pCmdUI->SetCheck(IsFullScreen());
}

void CMainFrame::OnViewFullScreen()
{
	WINDOWPLACEMENT wpNew;
	
	if (!IsFullScreen())
	{
		// We'll need these to restore the original state.
		m_wpPrev.length	= sizeof m_wpPrev;
		GetWindowPlacement(&m_wpPrev);
		
		CMDIChildWnd*	pChildWnd	= MDIGetActive();
		CWnd*			pViewWnd	= pChildWnd->GetActiveView();
		if (pViewWnd == NULL)
			return;

		CRect	rectDesktop, rectFrame, rectView;

		// Adjust RECT to new size of window
		VERIFY(::GetWindowRect(::GetDesktopWindow(), &rectDesktop));
		GetWindowRect(&rectFrame);
		pViewWnd->GetWindowRect(&rectView);
		rectFrame.InflateRect(
			rectView.left - rectDesktop.left,
			rectView.top - rectDesktop.top,
			rectDesktop.right - rectView.right,
			rectDesktop.bottom - rectView.bottom);
		
		// Remember this for OnGetMinMaxInfo()
		m_rectFullScreenWindow = rectFrame;
		
		wpNew					= m_wpPrev;
		wpNew.showCmd			= SW_SHOWNORMAL;
		wpNew.rcNormalPosition	= rectFrame;
		
		m_pwndFullScreenBar	= new CBCGPToolBar;
		
		if (!m_pwndFullScreenBar->Create(this))
		{
            TRACE0("Failed to create toolbar\n");
			return;      // fail to create
		}
		
		//don't allow the toolbar to dock
		CBCGPToolbarButton	button(ID_VIEW_FULLSCREEN, -1, _T("Close Full Screen"), FALSE, TRUE);
		m_pwndFullScreenBar->InsertButton(button);
		m_pwndFullScreenBar->EnableDocking(0);
		m_pwndFullScreenBar->SetWindowPos(0, 100, 100, 100, 100, SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW);
		m_pwndFullScreenBar->SetWindowText(_T("Full Screen"));
		m_pwndFullScreenBar->FloatControlBar(CRect(100, 100, 200, 200));
		m_bFullScreen = true;
	}
	else
	{
		// Destroy the toolbar
		CWnd*	pWnd	= m_pwndFullScreenBar->GetParentMiniFrame();
		if (pWnd == NULL)
			pWnd	= m_pwndFullScreenBar;
		VERIFY(pWnd->DestroyWindow());

		delete m_pwndFullScreenBar; m_pwndFullScreenBar = NULL;

		// !!!! This was the code that was needed in MFC and BCG Standard !!!!
		//m_pwndFullScreenBar->DestroyWindow();
		//delete m_pwndFullScreenBar; m_pwndFullScreenBar = NULL;
		// !!!!!!!!
		
		m_bFullScreen	= false;
		
		{	// This is a workaround to prevent the toolbars from being broken
			//	into different rows, when the window is maximized and
			//	the restored position is too small.
			WINDOWPLACEMENT	wpNew(m_wpPrev);
			VERIFY(::CopyRect(&wpNew.rcNormalPosition, &m_rectFullScreenWindow));
			VERIFY(SetWindowPlacement(&wpNew));
		}

		wpNew	= m_wpPrev;
	}
	
	VERIFY(SetWindowPlacement(&wpNew));
}

void CMainFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
	if (IsFullScreen())
	{
		lpMMI->ptMaxSize.x		=
		lpMMI->ptMaxTrackSize.x	= m_rectFullScreenWindow.Width();

		lpMMI->ptMaxSize.y		=
		lpMMI->ptMaxTrackSize.y	= m_rectFullScreenWindow.Height();
	}
}


CBCGPToolbarComboBoxButton* CMainFrame::GetFindCombo()
{
	CBCGPToolbarComboBoxButton* pFindCombo = NULL;

	CObList listButtons;
	if (CBCGPToolBar::GetCommandButtons (ID_EDIT_FIND_COMBO, listButtons) > 0)
	{
		for (POSITION posCombo = listButtons.GetHeadPosition (); 
			 pFindCombo == NULL && posCombo != NULL;)
		{
			CBCGPToolbarComboBoxButton* pCombo = 
				DYNAMIC_DOWNCAST (CBCGPToolbarComboBoxButton, listButtons.GetNext (posCombo));

			if (pCombo != NULL)
			{
				pFindCombo = pCombo;
			}
		}
	}

	return pFindCombo;
}

⌨️ 快捷键说明

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