首页 > 代码库 > 禁用CMFCRibbonApplicationButton的单击和双击事件

禁用CMFCRibbonApplicationButton的单击和双击事件

为了禁用CMFCRibbonApplicationButton的单击和双击事件,我重载了CMFCRibbonApplicationButton如下:

1. MyRibbonApplicationButton.h文件内容:

#pragma once

class CMyRibbonApplicationButton :
public CMFCRibbonApplicationButton
{
public:
CMyRibbonApplicationButton();
//~CMyRibbonApplicationButton();

protected:
virtual void OnLButtonDown(CPoint point);
virtual void OnLButtonDblClk(CPoint point);
};

 

2. MyRibbonApplicationButton.cpp文件内容:

 

#include "stdafx.h"
#include "MyRibbonApplicationButton.h"


CMyRibbonApplicationButton::CMyRibbonApplicationButton()
{
}

//CMyRibbonApplicationButton::~CMyRibbonApplicationButton()
//{
//}

// CMyRibbonApplicationButton 成员函数
void CMyRibbonApplicationButton::OnLButtonDblClk(CPoint point)
{
return;
}

void CMyRibbonApplicationButton::OnLButtonDown(CPoint point)
{
return;
}

 

3. 

在CMainFrame的中的OnCreate函数中找到

m_wndRibbonBar.LoadFromResource(IDR_RIBBON);

在这一行的下面添加

CMFCRibbonApplicationButton* pMainButton = m_wndRibbonBar.GetApplicationButton();
delete pMainButton; //删除框架自动生成的RibbonApplicationButton

CMyRibbonApplicationButton* pMyMainButton = new CMyRibbonApplicationButton();
pMyMainButton->SetImage(IDB_MAIN);
m_wndRibbonBar.SetApplicationButton(pMyMainButton, CSize(45, 45));

就可以了。

禁用CMFCRibbonApplicationButton的单击和双击事件