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

📄 viewmanager.cpp

📁 一个多窗口的浏览器的程序benbrowse
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{
	// TODO: Add your message handler code here and/or call default
	
	// Now, process the popup menu for the tab control
	POINT  ptScreen = point;
	// Convert the mouse point to screen coordinates since that is what is used by
	// the TrackPopupMenu() function.
	ClientToScreen(&ptScreen);
	CMenu *popupMenu;
	CMenu menu;
	menu.LoadMenu(IDR_TABBAR_MENU);
	if(menu)
	{
		popupMenu=menu.GetSubMenu(0);
		ASSERT(popupMenu);
		TranslateMenu(popupMenu,conmeu_item_text);
		// insert a separator item at the top
		popupMenu->InsertMenu(0, MF_BYPOSITION | MF_SEPARATOR, 0, _T(""));
		CString strcontextmenu;
		// insert title item
		// note: item is not selectable (disabled) but not grayed
		GetText("ConMeuTabbarCaption",strcontextmenu,conmeu_item_text);
		popupMenu->InsertMenu(0, MF_BYPOSITION | MF_STRING | MF_DISABLED, 0, strcontextmenu);
		
		::SetMenuDefaultItem(popupMenu->m_hMenu, 0, TRUE);
		
		popupMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, ptScreen.x, ptScreen.y, AfxGetMainWnd());
		popupMenu->DestroyMenu();
	}
/*	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();
	CString strcontextmenu;
	GetText("ConMeuTabView",strcontextmenu,conmeu_item_text);
	cMenu.AppendMenu(MF_STRING, ID_VIEW_VIEWTAB, strcontextmenu);
	GetText("ConMeuFullScrn",strcontextmenu,conmeu_item_text);
	cMenu.AppendMenu(MF_STRING, ID_VIEW_FULLSCREEN,strcontextmenu);
	cMenu.AppendMenu(MF_SEPARATOR);
	GetText("ConMeuClosALL",strcontextmenu,conmeu_item_text);
	cMenu.AppendMenu(MF_STRING, ID_WINDOW_CLOSE_ALL_BEN, strcontextmenu);
//	cMenu.AppendMenu(MF_STRING, ID_WINDOW_SAVE_ALL, _T("&Save All"));
	cMenu.AppendMenu(MF_SEPARATOR);
//	cMenu.AppendMenu(MF_STRING, ID_WINDOW_NEW, _T("&New Windows"));
//	cMenu.AppendMenu(MF_STRING, ID_WINDOW_ARRANGE, _T("&Arrange Icons"));
//	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);
	GetText("ConMeuNextWin",strcontextmenu,conmeu_item_text);
	cMenu.AppendMenu(MF_STRING, ID_WINDOW_NEXT, strcontextmenu);
	GetText("ConMeuPreWin",strcontextmenu,conmeu_item_text);
	cMenu.AppendMenu(MF_STRING, ID_WINDOW_PREVIOUS,strcontextmenu);
//	cMenu.AppendMenu(MF_SEPARATOR);
	GetText("ConMeuShowWinList",strcontextmenu,conmeu_item_text);
	cMenu.AppendMenu(MF_STRING, ID_WINDOW_MANAGE, strcontextmenu);

	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
	GetText("ConMeuTabbarCaption",strcontextmenu,conmeu_item_text);
    cMenu.InsertMenu(0, MF_BYPOSITION | MF_STRING | MF_DISABLED, 0,strcontextmenu);

    ::SetMenuDefaultItem(cMenu.m_hMenu, 0, TRUE);
	
	cMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, ptScreen.x, 
		ptScreen.y, AfxGetMainWnd());
	
	cMenu.DestroyMenu();
*/
	CControlBar::OnRButtonDown(nFlags, point);
}


void CViewManager::OnViewManagerToolTip(NMHDR* pNMHDR, LRESULT* pResult)
{
	//benben 5/5/2002
	try
	{
		*pResult = 0;
		TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
		UINT nID =pNMHDR->idFrom;
		if (pTTT!=NULL  &&  ! (pTTT->uFlags & TTF_IDISHWND))
		{
			// idFrom is actually the HWND of the tool
			if(nID==0&&m_ViewTabCtrl.GetItemCount()>0)
			{
				CString tip=m_arViewTitles.GetAt(0);
				strncpy(pTTT->szText, (LPCSTR)tip, 79);
				pTTT->szText[79]='\0';
				return ;//TRUE;
			}
			
			return ;//FALSE;
		}
	}
	catch(...)
	{
	}
  /*  *pResult = 0;
    TCHITTESTINFO hti;
	TOOLTIPTEXT *pTTT = reinterpret_cast<TOOLTIPTEXT *>(pNMHDR);    
	UINT nID = pNMHDR->idFrom;
	if(!pTTT)
	{
		MessageBox("ass tooltip error");
		return FALSE;
	}
	// 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)
	{
		CHtmlView* pView   = static_cast<CHtmlView *> (m_arViews.GetAt(nTab));
		ASSERT(pView != NULL);
		CString strTabText =pView->GetLocationName();// pDoc->GetPathName();
		if (strTabText.IsEmpty()) //... the document is not yet saved?
			return FALSE;//strTabText = ID_DEFDOCTIPS;
		//lstrcpy(pTTT->lpszText, strTabText);
		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);
	try
	{
		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;
			}
		}
	}
	catch(...)
	{
	}
}

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)
{
	try
	{
		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);
			if (!m_bWin2000)
			{
				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);
			if (!m_bWin2000)
			{
				rcGrip.OffsetRect(0, 3);
				pDC->Draw3dRect(rcGrip, clrBtnHilight, clrBtnShadow);
			}
		}
	}
	catch(...)
	{
	}
}


void CViewManager::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos) 
{
	OnSize(0, lpwndpos->cx, lpwndpos->cy);
	CControlBar::OnWindowPosChanged(lpwndpos);
}





void CViewManager::SetAddLast(BOOL last)
{
	m_beAddLast=last;
}

BOOL CViewManager::GetAddLast()
{
	return m_beAddLast;
}

⌨️ 快捷键说明

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