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

📄 wzdtlbar.cpp

📁 MFC扩展编程实例
💻 CPP
字号:
// WzdTlBar.cpp : implementation file
//

#include "stdafx.h"
#include "wzd.h"
#include "WzdTlBar.h"

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

/////////////////////////////////////////////////////////////////////////////
// CWzdToolBar

CWzdToolBar::CWzdToolBar()
{
}

CWzdToolBar::~CWzdToolBar()
{
}


BEGIN_MESSAGE_MAP(CWzdToolBar, CToolBar)
	//{{AFX_MSG_MAP(CWzdToolBar)
	//}}AFX_MSG_MAP
	ON_NOTIFY_REFLECT(TBN_DROPDOWN,OnDropdownButton)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWzdToolBar message handlers

BOOL CWzdToolBar::LoadToolBarEx(UINT id)
{
	// load toolbar info
	BOOL bRet;
	bRet=CToolBar::LoadToolBar(id);

	// find where our dropdown button will go
	int pos=CommandToIndex(IDC_WZD_DROPBUTTON);

	// set this button to be a dropdown button
	int iImage;
	UINT nID,nStyle;
	GetButtonInfo(pos,nID,nStyle,iImage);
	SetButtonInfo(pos,nID,nStyle|TBSTYLE_DROPDOWN,iImage);

	// ask toolbar to draw a down arrow next to this and any button with TBSTYLE_DROPDOWN
	SendMessage(TB_SETEXTENDEDSTYLE,0,TBSTYLE_EX_DRAWDDARROWS);

	return bRet;
}

CSize CWzdToolBar::CalcDynamicLayout( int nLength, DWORD dwMode )
{
	CSize size=CToolBar::CalcDynamicLayout(nLength,dwMode);
	// make room on non-fixed toolbars for additional down arrows
	if (dwMode&LM_HORZ) size.cx+=16*1; //16 * number of buttons with arrows
	return size;
}

void CWzdToolBar::OnDropdownButton(LPNMTOOLBAR lpnmtb, LRESULT *result)
{
	// get location of clicked button
	CRect rect;
	GetItemRect(CommandToIndex(lpnmtb->iItem),&rect);
	ClientToScreen(&rect);

// putup a popup menu there
	CMenu menu;
	menu.LoadMenu(IDR_WZD_MENU);
	CMenu* pPopup = menu.GetSubMenu(0);
	pPopup->TrackPopupMenu(TPM_RIGHTBUTTON, rect.left, rect.bottom, this);

	*result=TBDDRET_DEFAULT; //drop-down was handled, also 
							//  TBDDRET_NODEFAULT drop-down was not handled.  
							//  TBDDRET_TREATPRESSED treat click as a button press
}

⌨️ 快捷键说明

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