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

📄 chevbar.cpp

📁 深入剖析Visual C++编程技术及应用实例
💻 CPP
字号:
#include "stdafx.h"
#include "Chev.h"
#include "ChevBar.h"
#include "ToolMenu.h"

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


/////////////////////////////////////////////////////////////////////////////
// CChevBar

CChevBar::CChevBar()
{
}

CChevBar::~CChevBar()
{
}


BEGIN_MESSAGE_MAP(CChevBar, CReBar)
	//{{AFX_MSG_MAP(CChevBar)
	//}}AFX_MSG_MAP

	// Reflection message entry for Chevron push
	ON_NOTIFY_REFLECT( RBN_CHEVRONPUSHED, OnChevronPushed )
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChevBar
/*
	This is the handler when a chevron is pushed.
*/
void CChevBar::OnChevronPushed( NMHDR * pNotifyStruct, LRESULT* result )
{
	NMREBARCHEVRON* pChev = (NMREBARCHEVRON*) pNotifyStruct;
	//强制转换	
	int	iBand = pChev->uBand;
	//获取发送消息的控件序号
	REBARBANDINFO	rbinfo;
	rbinfo.cbSize = sizeof(rbinfo);
	rbinfo.fMask = RBBIM_CHILD;
	GetReBarCtrl().GetBandInfo ( iBand, &rbinfo );
	//获取控件的信息
	CToolBar *pTBar = (CToolBar *)CToolBar::FromHandle ( rbinfo.hwndChild );
	ASSERT(pTBar);
	ASSERT(pTBar->IsKindOf(RUNTIME_CLASS(CToolBar)));
	//确保是一个ToolBar
	CToolMenu	pop;
	pop.CreatePopupMenu ();
	//创建一个弹出菜单
	pop.m_pToolbar = pTBar; 

	CRect	rectBand;
	GetReBarCtrl ().GetRect( iBand, &rectBand );
	rectBand.right = rectBand.Width ();
	rectBand.left  = 0 ;
	CRect rectChevron;
	rectChevron = pChev->rc;
	rectBand.right -= rectChevron.Width ();
	CPoint	ptMenu;
	ptMenu.x = rectChevron.left;
	ptMenu.y = rectChevron.bottom;
	ClientToScreen ( &ptMenu );
	//转换坐标,显示菜单
	BOOL	bAtleastOne=FALSE;
	//表明是否有菜单需要显示
	int iCount, iButtonCount = pTBar->GetToolBarCtrl().GetButtonCount();
	for ( iCount = 0 ; iCount < iButtonCount ; iCount++ )
	{
		int id = pTBar->GetItemID( iCount );
		//获取菜单的ID		
		if (  pTBar->GetButtonStyle ( iCount ) & TBSTYLE_SEP )
		{
			//如果有一个分割线,弹出菜单也应该有
			if ( bAtleastOne )
				pop.AppendMenu ( MF_SEPARATOR );
		}
		else
		{
			CRect rectButton;
			pTBar->GetItemRect ( iCount, &rectButton );
			//获取按钮的区域
			CRect interRect;
			interRect.IntersectRect ( &rectButton, &rectBand );
			//获取相交区域						
			if ( interRect != rectButton )
			{
				UINT	iMenuStyle = MF_OWNERDRAW;				
				if ( pTBar->GetToolBarCtrl().IsButtonEnabled ( id ) )
					iMenuStyle |= MF_ENABLED;
				else
					iMenuStyle |= MF_DISABLED;

				pop.AppendMenu ( iMenuStyle, id );
				//添加菜单项
				bAtleastOne=TRUE;
			}
		}
	}

	if ( bAtleastOne )
		pop.TrackPopupMenu ( TPM_LEFTALIGN|TPM_TOPALIGN, ptMenu.x, ptMenu.y, this );
	//显示菜单
	pop.DestroyMenu ();
	//销毁菜单
}

⌨️ 快捷键说明

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