MenuBar-菜单条元素

MenuBar 菜单条元素

菜单条元素.

步骤:

  1. XMenuBar_Create()创建菜单条.
  2. XMenuBar_AddButton()添加菜单条弹出菜单按钮.
  3. XMenuBar_GetMenu() 获取菜单句柄.
  4. XMenu_AddItem() 添加菜单项

示例代码:

#pragma comment(lib, "XCGUI.lib")
#include "xcgui.h"
class CMyWindowMenuBar
{
public:
HWINDOW m_hWindow;
HELE m_MenuBar;
CMyWindowMenuBar()
{
Init();
}
void Init()
{
m_hWindow = XWnd_Create(0, 0, 300, 200, L"炫彩界面库窗口", NULL, window_style_default);
m_MenuBar = XMenuBar_Create(20,40,260,28,m_hWindow);
XMenuBar_AddButton(m_MenuBar, L"文件");
XMenuBar_AddButton(m_MenuBar, L"编辑");
XMenuBar_AddButton(m_MenuBar, L"视图");
XMenuBar_AddButton(m_MenuBar, L"aaa");
HMENUX hMenu=XMenuBar_GetMenu(m_MenuBar,0);
if(hMenu)
{
XMenu_AddItem(hMenu, 101, L"101");
XMenu_AddItem(hMenu, 102, L"102");
XMenu_AddItem(hMenu, 103, L"103");
//XMenu_AddItem(hMenu, 0, L"",XC_ID_ROOT,menu_item_flags_separator); //分隔栏
XMenu_AddItem(hMenu, 1031, L"3-1",103);
}
hMenu=XMenuBar_GetMenu(m_MenuBar,1);
if(hMenu)
{
XMenu_AddItem(hMenu, 201, L"201");
XMenu_AddItem(hMenu, 202, L"202");
XMenu_AddItem(hMenu, 203, L"203");
}
hMenu=XMenuBar_GetMenu(m_MenuBar,2);
if(hMenu)
{
XMenu_AddItem(hMenu, 301, L"301");
}
XEle_RegEventCPP(m_MenuBar,XE_MENU_SELECT,&CMyWindowMenuBar::OnWndMenuSelect);
XWnd_ShowWindow(m_hWindow,SW_SHOW);
}
int OnWndMenuSelect(int nID,BOOL *pbHandled)
{
XTRACE("select item %d \n",nID);
return 0;
}
};
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
XInitXCGUI(TRUE);
CMyWindowMenuBar MyWindow;
return TRUE;
}
#define XE_MENU_SELECT
菜单项选择事件.
Definition: XCGUI.h:923
@ window_style_default
窗口样式-控制按钮: 居中 图标, 标题, 关闭按钮, 最大化按钮, 最小化按钮
Definition: XCGUI.h:398
void WINAPI XExitXCGUI()
炫彩_退出 退出界面库释放资源. 不可在dllmain()中卸载, 否则会死锁
Definition: App.cpp:572
void WINAPI XRunXCGUI()
炫彩_运行 运行消息循环,当炫彩窗口数量为0时退出.
Definition: App.cpp:564
BOOL WINAPI XInitXCGUI(BOOL bD2D)
炫彩_初始化 初始化界面库.
Definition: App.cpp:557
XEle_RegEventCPP(hEle, nEvent, memberFunction)
元素_注册事件CPP 注册元素事件,将类成员函数作为事件响应函数.函数省略元素自身句柄hEle.
int WINAPI XMenuBar_AddButton(HELE hEle, const wchar_t *pText)
菜单条_添加按钮 添加弹出菜单按钮.
Definition: MenuBarUI.cpp:328
HMENUX WINAPI XMenuBar_GetMenu(HELE hEle, int nIndex)
菜单条_取菜单 获取菜单.
Definition: MenuBarUI.cpp:349
HELE WINAPI XMenuBar_Create(int x, int y, int cx, int cy, HXCGUI hParent)
菜单条_创建 创建菜单条元素;如果指定了父为窗口,默认调用XWnd_AddMenuBar()函数,将菜单条添加到窗口非客户区.
Definition: MenuBarUI.cpp:315
void WINAPI XMenu_AddItem(HMENUX hMenu, int nID, const wchar_t *pText, int nParentID, int nFlags)
菜单_添加项 添加菜单项.
Definition: MenuUI.cpp:777
HWINDOW WINAPI XWnd_Create(int x, int y, int cx, int cy, const wchar_t *pTitle, HWND hWndParent, int XCStyle)
窗口_创建 创建窗口
Definition: WindowUI.cpp:5964
BOOL WINAPI XWnd_ShowWindow(HWINDOW hWindow, int nCmdShow)
@窗口_显示扩展 显示隐藏及控制窗口最大化还原等
Definition: WindowUI.cpp:6387

截图: