Exemplo n.º 1
0
bool CMainFrame::UpdateTemplateMenu(CMFCPopupMenu* pMenu)
{
	if(pMenu == nullptr)
	{
		return false;
	}


	CString str;
	CMFCToolBarMenuButton* pParent = pMenu->GetParentButton();

	if(pParent == nullptr)
	{
		return false;
	}
	if(pParent->m_strText != L"GameObject")
	{
		return false;
	}


	UpdateTemplateMap();
	using namespace engine;

	boost::unordered_map<std::wstring, std::vector<engine::GameObjectTemplate*> >::iterator it = m_templateMap.begin();

	pMenu->RemoveAllItems();

	CMFCToolBarMenuButton b(ID_GAMEOBJECT_CREATEEMPTY, nullptr, -1, L"Empty");

	pMenu->InsertItem(b);

	pMenu->InsertSeparator();

	int id = ID_COMPONENT_MENU_BASE + 1001;
	for(it; it != m_templateMap.end(); ++it)
	{
		if(it->second.size() == 0)
		{
			continue;
		}
		CMenu m;
		
		m.CreateMenu();
		for(size_t i = 0; i < it->second.size(); ++i)
		{
			m.InsertMenuW(i, MF_BYPOSITION, id, it->second[i]->GetName().c_str());

			id++;
		}

		CMFCToolBarMenuButton b(-1, m.GetSafeHmenu(), -1, it->first.c_str());
		m.Detach();

		pMenu->InsertItem(b);
	}

	return true;
}
Exemplo n.º 2
0
bool CMainFrame::UpdateComponentMenu(CMFCPopupMenu* pMenu)
{
	if(pMenu == nullptr)
	{
		return false;
	}

	CString str;
	CMFCToolBarMenuButton* pParent = pMenu->GetParentButton();

	if(pParent == nullptr)
	{
		return false;
	}
	if(pParent->m_strText != L"Component")
	{
		return false;
	}

	using namespace engine;

	UpdateComClassMap();

	boost::unordered_map<std::wstring, std::vector<ExtPackage::ComponentClass*> >::iterator it = m_ComClassMap.begin();

	pMenu->RemoveAllItems();

	int id = ID_COMPONENT_MENU_BASE + 1;
	for(it; it != m_ComClassMap.end(); ++it)
	{
		if(it->second.size() == 0)
		{
			continue;
		}
		CMenu m;
		m.CreateMenu();
		for(size_t i = 0; i < it->second.size(); ++i)
		{
			m.InsertMenuW(i, MF_BYPOSITION, id, it->second[i]->m_name.c_str());

			id++;
		}

		CMFCToolBarMenuButton b(-1, m.GetSafeHmenu(), -1, it->first.c_str());
		m.Detach();

		pMenu->InsertItem(b);
	}

	return true;
}
Exemplo n.º 3
0
//动态添加菜单,根据应用的需要进行添加,不是必须的操
extern"C" _declspec(dllexport) BOOL	InstallExtMenu(CWnd* pChild, HWND Parent, UINT* NextMenuID)
{
	AFX_MANAGE_STATE(AfxGetAppModuleState());
	BOOL bReturn = FALSE;
	if (!pChild)					//dll 中的wnd为空,无法添加
		return FALSE;
	if (!Parent)
		return FALSE;
	HMENU hMenu = ::GetMenu(Parent);		//获取父窗口的菜单
	if (!hMenu)
		return FALSE;
	CMenu ParentMenu;
	ParentMenu.Attach(hMenu);
	CMenu Menu;
	if (!Menu.CreateMenu())						//创建菜单
		return FALSE;
	theApp.m_CommandToMessage.InitHashTable(3);		//预定3项,可修改

	NextMenuID = new UINT[3];
	NextMenuID[0] = theApp.ID_MENU_SHOWHINT;
	NextMenuID[1] = theApp.ID_MENU_HIDEHINT;
	NextMenuID[2] = theApp.ID_MENU_SETTASK;

	Menu.AppendMenu(MF_STRING, (UINT_PTR)(*NextMenuID), L"显示提示符");
	theApp.m_CommandToMessage.SetAt(*(NextMenuID)++, theApp.ID_MENU_SHOWHINT);	//设置映射
	Menu.AppendMenu(MF_STRING, (UINT_PTR)(*NextMenuID), L"隐藏提示符");
	theApp.m_CommandToMessage.SetAt(*(NextMenuID)++, theApp.ID_MENU_HIDEHINT);
	Menu.AppendMenu(MF_STRING, (UINT_PTR)(*NextMenuID), L"设置任务");
	theApp.m_CommandToMessage.SetAt(*(NextMenuID)++, theApp.ID_MENU_SETTASK);

	HMENU hsubMenu = Menu.Detach();
	ParentMenu.InsertMenuW(ParentMenu.GetMenuItemCount(), MF_BYPOSITION | MF_STRING | MF_POPUP, (UINT_PTR)hsubMenu,
		_T("数字应用设置"));

	ParentMenu.Detach();
	CWnd::FromHandle(Parent)->DrawMenuBar();		//强制重绘菜单
	return TRUE;
}