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

📄 viewmanager.cpp

📁 转载:autocad多文档tab2002版.rar 可以学习一下
💻 CPP
📖 第 1 页 / 共 2 页
字号:

	TabCtrl_SetExtendedStyle(m_ViewTabCtrl.m_hWnd, TCS_EX_FLATSEPARATORS);

	m_ViewTabCtrl.SetImageList(&m_ViewTabImages);
	// Build the image list here
    HICON hIcon = AfxGetApp() -> LoadStandardIcon(IDI_APPLICATION);
//    HICON hIcon = AfxGetApp()->LoadIcon(IDR_DEMOTYPE);
	m_ViewTabImages.Add(hIcon);
	// Enable tooltips for all controls
	EnableToolTips(TRUE);
	
	return 0;
}

void CViewManager::OnRButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	POINT  ptScreen = point;
	// Convert the mouse point to screen coordinates since that is what is used by
	// the TrackPopupMenu() function.
	ClientToScreen(&ptScreen);
	CPopupMenu cMenu;
	cMenu.CreatePopupMenu();
	
	cMenu.AppendMenu(MF_STRING, ID_WINDOW_CASCADE, _T("&Cascade Windows"));
	cMenu.AppendMenu(MF_STRING, ID_WINDOW_TILE_HORZ, _T("Tile &Horizontally"));
	cMenu.AppendMenu(MF_STRING, ID_WINDOW_TILE_VERT, _T("Tile &Vertically"));
	cMenu.AppendMenu(MF_SEPARATOR);
	cMenu.AppendMenu(MF_STRING, ID_WINDOW_MANAGE, _T("&Windows..."));

	cMenu.LoadToolBarResource(IDR_TABVIEW_MENU);
	cMenu.RemapMenu(&cMenu);
	cMenu.EnableMenuItems(&cMenu, AfxGetMainWnd());

    // insert a separator item at the top
    cMenu.InsertMenu(0, MF_BYPOSITION | MF_SEPARATOR, 0, _T(""));

    // insert title item
    // note: item is not selectable (disabled) but not grayed
    cMenu.InsertMenu(0, MF_BYPOSITION | MF_STRING | MF_DISABLED, 0, _T("Open File Tabs Bar"));

    ::SetMenuDefaultItem(cMenu.m_hMenu, 0, TRUE);
	
	cMenu.TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, ptScreen.x, 
		ptScreen.y, AfxGetMainWnd());
	
	cMenu.DestroyMenu();

	CControlBar::OnRButtonDown(nFlags, point);
}

// This function adds a title entry to a popup menu
void AddMenuTitle(CMenu* popup, LPCSTR title)
{
    // insert a separator item at the top
    popup -> InsertMenu(0, MF_BYPOSITION | MF_SEPARATOR, 0, title);

    // insert title item
    // note: item is not selectable (disabled) but not grayed
    popup -> InsertMenu(0, MF_BYPOSITION | MF_STRING | MF_DISABLED, 0, title);

    SetMenuDefaultItem(popup -> m_hMenu, 0, TRUE);
}

BOOL CViewManager::OnViewManagerToolTip(UINT id, NMHDR* pNMHDR, LRESULT* pResult)
{
	UNREFERENCED_PARAMETER(id);	   // clear that level 4 warning...

    *pResult = 0;
    TCHITTESTINFO hti;
	TOOLTIPTEXT *pTTT = reinterpret_cast<TOOLTIPTEXT *>(pNMHDR);    
	UINT nID = pNMHDR -> idFrom;

	// if there are some dialog controls, progress the tooltips
    if (pTTT -> uFlags & TTF_IDISHWND)    
	{
        // idFrom is actually the HWND of the tool
        nID = ::GetDlgCtrlID((HWND)nID);        
		if (nID)        
		{
            pTTT -> lpszText = MAKEINTRESOURCE(nID);
            pTTT -> hinst    = AfxGetResourceHandle();            
			return TRUE;
        }    
	} 

	// Now, address the view tab tooltips
    hti.pt = CPoint( GetMessagePos( ) );
    m_ViewTabCtrl.ScreenToClient( &hti.pt );
    int nTab = m_ViewTabCtrl.HitTest( &hti );

	if (nTab >= 0)
	{
		CView*	pView   = static_cast<CView *> (m_arViews.GetAt(nTab));
		ASSERT(pView != NULL);
		CDocument* pDoc = pView -> GetDocument();
		CString strTabTipText = pDoc -> GetPathName();
		if ( strTabTipText.IsEmpty() ) //... the document is not yet saved?
			strTabTipText = ID_DEFDOCTIPS;
		else
			CutDocFileName( strTabTipText );

		lstrcpy(pTTT -> lpszText, strTabTipText);
		return TRUE;
	}

	return FALSE;
}

BOOL CViewManager::CreateViewManager(CMDIFrameWnd *pMDIFrameWnd, UINT uID)
{
    if (!Create(ID_DEFCAPTION, pMDIFrameWnd, m_sizeDefault, uID))
	{
		TRACE0(_T("Failed to create Tab bar\n"));  
		return FALSE;      // fail to create
	}

	SetBarStyle(GetBarStyle() | CBRS_TOP |
		CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
	EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
 	pMDIFrameWnd -> DockControlBar(this); 

	return TRUE;
}

BOOL CViewManager::Create(LPCTSTR lpszWindowName, CWnd* pParentWnd,
                               CSize sizeDefault, UINT nID, DWORD dwStyle)
{
    // must have a parent
    ASSERT_VALID(pParentWnd);
    // cannot be both fixed and dynamic
    // (CBRS_SIZE_DYNAMIC is used for resizng when floating)
    ASSERT (!((dwStyle & CBRS_SIZE_FIXED) && (dwStyle & CBRS_SIZE_DYNAMIC)));

    m_dwStyle = dwStyle & CBRS_ALL; // save the control bar styles
	m_sizeDefault = sizeDefault;    // set fixed size
	m_sizeMRU     = sizeDefault;
    // register and create the window - skip CControlBar::Create()
    CString strWndclass = ::AfxRegisterWndClass(CS_DBLCLKS,
        ::LoadCursor(NULL, IDC_ARROW), ::GetSysColorBrush(COLOR_BTNFACE), 0);

    dwStyle &= ~CBRS_ALL;
	dwStyle |= WS_CLIPCHILDREN | CCS_NOPARENTALIGN | CCS_NOMOVEY | CCS_NORESIZE;
    if (!CWnd::Create(strWndclass, lpszWindowName, dwStyle,
        CRect(0, 0, 0, 0), pParentWnd, nID))
        return FALSE;

    return TRUE;
}

CSize CViewManager::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
{
	ASSERT_VALID(this);
	ASSERT(::IsWindow(m_hWnd));
	
	if (bStretch) // if not docked stretch to fit
		return CSize(bHorz ? 32767 : m_sizeDefault.cx, bHorz ? m_sizeDefault.cy : 32767);
	
	CClientDC dc(NULL);
	HFONT hFont    = reinterpret_cast<HFONT>(SendMessage(WM_GETFONT));
	HFONT hOldFont = NULL;
	if (hFont != NULL)
		hOldFont = reinterpret_cast<HFONT>(dc.SelectObject(hFont));
	TEXTMETRIC tm;
	VERIFY(dc.GetTextMetrics(&tm));
	if (hOldFont != NULL)
		dc.SelectObject(hOldFont);
	
	// get border information
	CSize size;
	CRect rcInside, rcWnd; 
	rcInside.SetRectEmpty();
	CalcInsideRect(rcInside, bHorz);
	GetParentFrame() -> GetWindowRect(&rcWnd);
	size.cx = rcWnd.Width();
	size.cy = tm.tmHeight + tm.tmInternalLeading/* - 1 */+ 
		::GetSystemMetrics(SM_CYBORDER) * 5 - rcInside.Height();
	
	return size;
}

CSize CViewManager::CalcDynamicLayout(int nLength, DWORD dwMode)
{
	UNREFERENCED_PARAMETER(nLength);	   // clear that level 4 warning...

	if (dwMode & LM_HORZDOCK)
	{
		ASSERT(dwMode & LM_HORZ);
		return CalcFixedLayout(dwMode & LM_STRETCH, dwMode & LM_HORZ);
	}

	if (m_sizeMRU.cx > m_sizeDefault.cx)
		return m_sizeMRU;
	else
		return m_sizeDefault;
}

void CViewManager::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) 
{
	lpwndpos -> flags |= SWP_FRAMECHANGED;
	CControlBar::OnWindowPosChanging(lpwndpos);
	
	UINT nOldDockID = m_nDockID;
	m_nDockID = GetParent() -> GetDlgCtrlID();
	if (nOldDockID == m_nDockID)
		return;
	else
	{
		DWORD dwStyle = m_ViewTabCtrl.GetStyle();
		switch(m_nDockID)
		{
		case AFX_IDW_DOCKBAR_TOP:
			if (dwStyle & TCS_BOTTOM)
			{
				DWORD dwNewStyle = dwStyle & ~TCS_BOTTOM;
				m_ViewTabCtrl.ModifyStyle(dwStyle, dwNewStyle);
			}
			break;
		case AFX_IDW_DOCKBAR_BOTTOM:
			if ((dwStyle & TCS_BOTTOM) == 0)
			{
				DWORD dwNewStyle = dwStyle | TCS_BOTTOM;
				m_ViewTabCtrl.ModifyStyle(dwStyle, dwNewStyle);
			}
			break;
		case AFX_IDW_DOCKBAR_LEFT:
			break;
		case AFX_IDW_DOCKBAR_RIGHT:
			break;
		default:
				DWORD dwNewStyle = dwStyle & ~TCS_BOTTOM;
				m_ViewTabCtrl.ModifyStyle(dwStyle, dwNewStyle);
			break;
		}
	}
}

void CViewManager::DoPaint(CDC* pDC)
{
	CRect rect;
	GetClientRect(rect);

	// clean background
	COLORREF clr = ::GetSysColor(COLOR_BTNFACE);
	pDC -> FillSolidRect(rect, clr);	

	// draw the gripper
	DrawGripper(pDC);
	// It is better to let the underlining control bar take the last shot
	CControlBar::DoPaint(pDC);
}

void CViewManager::DrawGripper(CDC* pDC)
{
	if( (m_dwStyle & CBRS_FLOATING) || m_dwDockStyle == 0 )
		return;

	COLORREF clrBtnHilight = ::GetSysColor(COLOR_BTNHILIGHT);
	COLORREF clrBtnShadow  = ::GetSysColor(COLOR_BTNSHADOW);

	CRect rcGrip;					 
	GetWindowRect(&rcGrip);
	ScreenToClient(&rcGrip);
	rcGrip.OffsetRect(-rcGrip.left, -rcGrip.top);

	if(m_dwStyle & CBRS_ORIENT_HORZ) 
	{
		// gripper at left
		rcGrip.DeflateRect(4, 4);
		rcGrip.right = rcGrip.left + 3;
        pDC -> Draw3dRect(rcGrip, clrBtnHilight, clrBtnShadow);
		rcGrip.OffsetRect(3, 0);
        pDC -> Draw3dRect(rcGrip,	clrBtnHilight, clrBtnShadow);
	}
	else 
	{
		// gripper at top
		rcGrip.DeflateRect(4, 4);
		rcGrip.bottom = rcGrip.top + 3;
		pDC -> Draw3dRect(rcGrip, clrBtnHilight, clrBtnShadow);
		rcGrip.OffsetRect(0, 3);
        pDC -> Draw3dRect(rcGrip, clrBtnHilight, clrBtnShadow);
	}
}

⌨️ 快捷键说明

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