uiextensionuihelper.cpp

来自「管理项目进度工具的原代码」· C++ 代码 · 共 89 行

CPP
89
字号
// UIExtensionUIHelper.cpp: implementation of the CUIExtensionUIHelper class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "UIExtensionUIHelper.h"
#include "UIExtensionmgr.h"
#include "sysimagelist.h"
#include "MenuIconMgr.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CUIExtensionUIHelper::CUIExtensionUIHelper(const CUIExtensionMgr& mgrUIExt, CMenuIconMgr& mgrIcon) : 
	m_mgrUIExt(mgrUIExt), m_mgrIcon(mgrIcon)
{

}

CUIExtensionUIHelper::~CUIExtensionUIHelper()
{

}

void CUIExtensionUIHelper::UpdateMenu(CCmdUI* pCmdUI, int nMaxCount, BOOL bEnabled) const
{
	if (pCmdUI->m_pMenu)
	{
		UINT nStartID = pCmdUI->m_nID;

		// delete existing tool entries and their icons first
		int nTool;
		for (nTool = 0; nTool < nMaxCount; nTool++)
		{
			pCmdUI->m_pMenu->DeleteMenu(nStartID + nTool, MF_BYCOMMAND);
			m_mgrIcon.DeleteImage(nStartID + nTool);
		}
		
		// if we have any tools to add we do it here
		int nNumExporters = m_mgrUIExt.GetNumUIExtensions();

		if (nNumExporters)
		{
			CSysImageList sil;

			int nPos = 0;
			UINT nFlags = MF_BYPOSITION | MF_STRING | (bEnabled ? 0 : MF_GRAYED);
			
			for (nTool = 0; nTool < nMaxCount && nTool < nNumExporters; nTool++)
			{
				CString sMenuItem, sText = m_mgrUIExt.GetUIExtensionMenuText(nTool);
								
				if (nPos < 9)
					sMenuItem.Format("&%d %s", nPos + 1, sText);
				else
					sMenuItem = sText;

				pCmdUI->m_pMenu->InsertMenu(pCmdUI->m_nIndex++, nFlags, 
											nStartID + nTool, sMenuItem);

				// icon
				HICON hIcon = m_mgrUIExt.GetUIExtensionIcon(nTool);
				m_mgrIcon.AddImage(nStartID + nTool, hIcon);
				
				nPos++;
			}
			
			// update end menu count
			pCmdUI->m_nIndex--; // point to last menu added
			pCmdUI->m_nIndexMax = pCmdUI->m_pMenu->GetMenuItemCount();
			
			pCmdUI->m_bEnableChanged = TRUE;    // all the added items are enabled
		}
		else // if nothing to add just re-add placeholder
		{
			pCmdUI->m_pMenu->InsertMenu(pCmdUI->m_nIndex, MF_BYPOSITION | MF_STRING | MF_GRAYED, 
				nStartID, "3rd Party Extensions");
		}
	}
}

⌨️ 快捷键说明

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