wxWidgets中从xrc文件中获取菜单选项的指针

前端之家收集整理的这篇文章主要介绍了wxWidgets中从xrc文件中获取菜单选项的指针前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
加载一个menu.xrc文件
 
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1">
	
		<object class="wxMenuBar" name="m_menubar1">
			<label>MyMenuBar</label>
			<object class="wxMenu" name="m_menu1">
				<label>File</label>
				<object class="wxMenuItem" name="m_menuItem1">
					<label>Open</label>
					<help></help>
				</object>
				<object class="wxMenuItem" name="m_menuItem2">
					<label>Select</label>
					<help></help>
				</object>
				<object class="wxMenuItem" name="m_menuItem3">
					<label>Select ALL</label>
					<help></help>
				</object>
				<object class="wxMenuItem" name="m_menuItem4">
					<label>Exit\tCtrl+Q</label>
					<help></help>
				</object>
			</object>
		</object>							
</resource>

然后在初始化函数Init()里面

	m_menubar = wxXmlResource::Get()->LoadMenuBar(wxT("m_menubar1"));
	SetMenuBar(m_menubar);
	assert(m_menubar);

这样就可以在菜单中进行相应的操作。如:

获取一个子菜单项的指针

m_menuItem=m_menubar->FindItem(wxXmlResource::GetXRCID(wxT("m_menuItem1")));
原文链接:https://www.f2er.com/xml/298412.html

猜你在找的XML相关文章