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

📄 bcgpoutlookbarpane.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// BCGPOutlookBarPane.cpp : implementation file
//

#include "stdafx.h"
#include "bcgcbpro.h"
#include "MenuImages.h"
#include "bcgprores.h"
#include "BCGPLocalResource.h"
#include "BCGPWorkspace.h"
#include "BCGPRegistry.h"
#include "BCGCBProVer.h"
#include "BCGPVisualManager.h"
#include "BCGPMiniFrameWnd.h"
#include "BCGPOutlookBarPane.h"
#include "BCGPOutlookButton.h"
#include "BCGPOutlookBar.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define SCROLL_BUTTON_OFFSET	5

//------------------
// Timer event IDs:
//------------------
static const UINT idScrollUp	= 1;
static const UINT idScrollDn	= 2;

static const UINT uiScrollDelay = 200;		// ms

extern CBCGPWorkspace* g_pWorkspace;

CBCGPToolBarImages CBCGPOutlookBarPane::m_Images;
CSize CBCGPOutlookBarPane::m_csImage = CSize (0, 0);

/////////////////////////////////////////////////////////////////////////////
// CBCGPOutlookBarPane

IMPLEMENT_SERIAL(CBCGPOutlookBarPane, CBCGPToolBar, 1)

CBCGPOutlookBarPane::CBCGPOutlookBarPane()
{
	m_nSize = -1;

	m_iScrollOffset = 0;
	m_iFirstVisibleButton = 0;
	m_bScrollDown = FALSE;

	m_clrRegText = (COLORREF)-1;
	m_clrBackColor = globalData.clrBtnShadow;

	m_clrTransparentColor = RGB (255, 0, 255);
	m_Images.SetTransparentColor (m_clrTransparentColor);

	m_uiBackImageId = 0;

	m_btnUp.m_nFlatStyle = CBCGPButton::BUTTONSTYLE_3D;
	m_btnUp.m_bDrawFocus = FALSE;

	m_btnDown.m_nFlatStyle = CBCGPButton::BUTTONSTYLE_3D;
	m_btnDown.m_bDrawFocus = FALSE;

	m_bDrawShadedHighlight = FALSE;

	m_bDisableControlsIfNoHandler = FALSE;
	m_nExtraSpace = 0;
	m_hRecentOutlookWnd = NULL;

	m_bPageScrollMode = FALSE;
}

CBCGPOutlookBarPane::~CBCGPOutlookBarPane()
{
}

BEGIN_MESSAGE_MAP(CBCGPOutlookBarPane, CBCGPToolBar)
	//{{AFX_MSG_MAP(CBCGPOutlookBarPane)
	ON_WM_ERASEBKGND()
	ON_WM_SIZE()
	ON_WM_CREATE()
	ON_WM_NCCALCSIZE()
	ON_WM_SYSCOLORCHANGE()
	ON_WM_TIMER()
	ON_WM_LBUTTONUP()
	ON_WM_SETFOCUS()
	ON_WM_CONTEXTMENU()
    ON_WM_NCPAINT()
	ON_WM_NCDESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


BOOL CBCGPOutlookBarPane::Create(CWnd* pParentWnd,
		DWORD dwStyle/* = dwDefaultToolbarStyle*/,
		UINT uiID/* = (UINT)-1*/,
		DWORD dwBCGStyle/* = 0*/)
{
	if (!CBCGPToolBar::Create (pParentWnd, dwStyle, uiID))
	{
		return FALSE;
	}

	m_dwBCGStyle = dwBCGStyle;
	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CBCGPOutlookBarPane message handlers

//*************************************************************************************
BOOL CBCGPOutlookBarPane::OnEraseBkgnd(CDC* /*pDC*/) 
{
	return TRUE;
}
//*************************************************************************************
BOOL CBCGPOutlookBarPane::AddButton (LPCTSTR szBmpFileName, LPCTSTR szLabel, 
								UINT iIdCommand, int iInsertAt)
//
// Adds a button by loading the image from disk instead of a resource
//
{
	ASSERT (szBmpFileName != NULL);

	HBITMAP hBmp = (HBITMAP) ::LoadImage (	
								NULL, szBmpFileName, IMAGE_BITMAP, 0, 0, 
								LR_DEFAULTSIZE | LR_LOADFROMFILE); 
	if (hBmp == NULL)
	{
		TRACE(_T("Can't load bitmap resource: %s"), szBmpFileName);
		ASSERT (FALSE);

		return FALSE;
	}

	int iImageIndex = AddBitmapImage (hBmp);
	ASSERT (iImageIndex >= 0);

	return InternalAddButton (iImageIndex, szLabel, iIdCommand, iInsertAt);
}
//*************************************************************************************
BOOL CBCGPOutlookBarPane::AddButton (UINT uiImage, UINT uiLabel, UINT iIdCommand, 
								int iInsertAt)
{
	CString strLable;
	strLable.LoadString (uiLabel);

	return AddButton (uiImage, strLable, iIdCommand, iInsertAt);
}
//*************************************************************************************
BOOL CBCGPOutlookBarPane::AddButton (UINT uiImage, LPCTSTR lpszLabel, UINT iIdCommand,
								int iInsertAt)
{
	int iImageIndex = -1;
	if (uiImage != 0)
	{
		CBitmap bmp;
		if (!bmp.LoadBitmap (uiImage))
		{
			TRACE(_T("Can't load bitmap resource: %d"), uiImage);
			return FALSE;
		}

		iImageIndex = AddBitmapImage ((HBITMAP) bmp.GetSafeHandle ());
	}

	return InternalAddButton (iImageIndex, lpszLabel, iIdCommand, iInsertAt);
}
//**************************************************************************************
BOOL CBCGPOutlookBarPane::AddButton (HBITMAP hBmp, LPCTSTR lpszLabel, UINT iIdCommand, int iInsertAt)
{
	ASSERT (hBmp != NULL);

	int iImageIndex = AddBitmapImage (hBmp);
	return InternalAddButton (iImageIndex, lpszLabel, iIdCommand, iInsertAt);
}
//**************************************************************************************
BOOL CBCGPOutlookBarPane::AddButton (HICON hIcon, LPCTSTR lpszLabel, UINT iIdCommand, int iInsertAt)
{
	ASSERT (hIcon != NULL);

	ICONINFO iconInfo;
	::GetIconInfo (hIcon, &iconInfo);

	CClientDC dc (this);

	CDC dcMem;
	dcMem.CreateCompatibleDC (&dc);

	BITMAP bitmap;
	::GetObject (iconInfo.hbmColor, sizeof (BITMAP), &bitmap);

	CSize size (bitmap.bmWidth, bitmap.bmHeight);

	CBitmap bmp;
	bmp.CreateCompatibleBitmap (&dc, size.cx, size.cy);

	CBitmap* pOldBmp = dcMem.SelectObject (&bmp);

	dcMem.FillSolidRect (0, 0, size.cx, size.cy, m_clrTransparentColor);
	::DrawIconEx (dcMem.GetSafeHdc (), 0, 0, hIcon, size.cx, size.cy,
		0, NULL, DI_NORMAL);

	dcMem.SelectObject (pOldBmp);

	::DeleteObject (iconInfo.hbmColor);
	::DeleteObject (iconInfo.hbmMask);

	int iImageIndex = AddBitmapImage ((HBITMAP) bmp.GetSafeHandle ());
	return InternalAddButton (iImageIndex, lpszLabel, iIdCommand, iInsertAt);
}
//**************************************************************************************
BOOL CBCGPOutlookBarPane::RemoveButton (UINT iIdCommand)
{
	for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL;)
	{
		POSITION posSave = pos;

		CBCGPOutlookButton* pButton = (CBCGPOutlookButton*) m_Buttons.GetNext (pos);
		ASSERT (pButton != NULL);

		if (pButton->m_nID == iIdCommand)
		{
			m_Buttons.RemoveAt (posSave);
			delete pButton;

			if (GetSafeHwnd () != NULL)
			{
				AdjustLocations ();
				UpdateWindow ();
				Invalidate ();
			}

			return TRUE;
		}
	}

	return FALSE;
}
//*************************************************************************************
BOOL CBCGPOutlookBarPane::InternalAddButton (int iImageIndex, LPCTSTR lpszLabel,
										UINT iIdCommand, int iInsertAt)
{
	CBCGPOutlookButton* pButton = new CBCGPOutlookButton;
	ASSERT (pButton != NULL);

	pButton->m_nID = iIdCommand;
	pButton->m_strText = (lpszLabel == NULL) ? _T("") : lpszLabel;
	pButton->SetImage (iImageIndex);
	pButton->m_bTextBelow = m_bTextLabels;

	if (iInsertAt == -1)
	{
		iInsertAt = m_Buttons.GetCount ();
	}
	
	InsertButton (pButton, iInsertAt);

	AdjustLayout ();
	return TRUE;
}
//*************************************************************************************
int CBCGPOutlookBarPane::AddBitmapImage (HBITMAP hBitmap)
{
	ASSERT (hBitmap != NULL);

	BITMAP	bitmap;
	::GetObject (hBitmap, sizeof (BITMAP), &bitmap);

	CSize csImage = CSize (bitmap.bmWidth, bitmap.bmHeight);

	if (m_Images.GetCount() == 0)	// First image
	{
		m_csImage = csImage;
		m_Images.SetImageSize(csImage);
	}
	else
	{
		ASSERT (m_csImage == csImage);	// All buttons should be of the same size!
	}

	return m_Images.AddImage (hBitmap);
}
//*************************************************************************************
void CBCGPOutlookBarPane::OnSize(UINT nType, int cx, int cy) 
{
	CBCGPToolBar::OnSize(nType, cx, cy);

	AdjustLayout ();

	int iButtons = m_Buttons.GetCount ();
	if (iButtons > 0)
	{
		POSITION posLast = m_Buttons.FindIndex (iButtons - 1);
		CBCGPOutlookButton* pButtonLast = (CBCGPOutlookButton*) m_Buttons.GetAt (posLast);
		ASSERT (pButtonLast != NULL);

		while (m_iScrollOffset > 0 &&
			pButtonLast->Rect ().bottom < cy)
		{
			ScrollUp ();
		}
	}
}
//*************************************************************************************
void CBCGPOutlookBarPane::SetTextColor (COLORREF clrRegText, COLORREF/* clrSelText obsolete*/)
{
	m_clrRegText = clrRegText;
	if (GetSafeHwnd () != NULL)
	{
		Invalidate ();
		UpdateWindow ();
	}
}
//*************************************************************************************
int CBCGPOutlookBarPane::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CBCGPToolBar::OnCreate(lpCreateStruct) == -1)
		return -1;

	SetBarStyle (m_dwStyle & ~(CBRS_BORDER_ANY | CBRS_GRIPPER));

	m_cxLeftBorder = m_cxRightBorder = 0;
	m_cyTopBorder = m_cyBottomBorder = 0;

	//-------------------------------------------
	// Adjust Z-order in the parent frame window:
	//-------------------------------------------
	SetWindowPos(&wndBottom, 0,0,0,0,SWP_NOSIZE|SWP_NOMOVE | SWP_NOACTIVATE);

	//-----------------------
	// Create scroll buttons:
	//-----------------------
	CRect rectDummy (CPoint (0, 0), CMenuImages::Size ());
	rectDummy.InflateRect (2, 2);

	m_btnUp.Create (_T(""), WS_CHILD | BS_PUSHBUTTON, rectDummy,
					this, idScrollUp);
	m_btnUp.SetStdImage (CMenuImages::IdArowUp);

	m_btnDown.Create (_T(""), WS_CHILD | BS_PUSHBUTTON, rectDummy,
					this, idScrollDn);
	m_btnDown.SetStdImage (CMenuImages::IdArowDown);

	return 0;
}
//*************************************************************************************
void CBCGPOutlookBarPane::ScrollUp ()
{
	if (m_iScrollOffset <= 0 ||
		m_iFirstVisibleButton <= 0)
	{
		m_iScrollOffset = 0;
		m_iFirstVisibleButton = 0;

		KillTimer (idScrollUp);
		return;
	}

	CBCGPToolbarButton* pFirstVisibleButton = GetButton (m_iFirstVisibleButton);
	if (pFirstVisibleButton == NULL)
	{
		KillTimer (idScrollDn);
		return;
	}

	m_iFirstVisibleButton--;
	m_iScrollOffset -= pFirstVisibleButton->Rect ().Height ();

	if (m_iFirstVisibleButton == 0)
	{
		m_iScrollOffset = 0;
	}

	ASSERT (m_iScrollOffset >= 0);

	AdjustLocations ();
	Invalidate ();
	UpdateWindow ();
}
//*************************************************************************************
void CBCGPOutlookBarPane::ScrollDown ()
{
	if (!m_bScrollDown ||
		m_iFirstVisibleButton + 1 >= GetCount ())
	{
		KillTimer (idScrollDn);
		return;
	}

	CBCGPToolbarButton* pFirstVisibleButton = GetButton (m_iFirstVisibleButton);
	if (pFirstVisibleButton == NULL)
	{
		KillTimer (idScrollDn);
		return;
	}

	m_iFirstVisibleButton++;
	m_iScrollOffset += pFirstVisibleButton->Rect ().Height ();

	AdjustLocations ();
	Invalidate ();
	UpdateWindow ();
}
//*************************************************************************************
CSize CBCGPOutlookBarPane::CalcFixedLayout (BOOL bStretch, BOOL bHorz)
{
	CRect rect;
	GetClientRect (rect);

	return rect.Size ();
}
//*************************************************************************************

⌨️ 快捷键说明

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