我是CMFCMenuButton
控件的新手;这是我的代码OnInitDialog()
:
// Load application list into menu button
m_ApplicationMenu = CreateMenu();
m_MenuInfoSize = 2;
m_MenuInfo = new MENUITEMINFO[m_MenuInfoSize];
memset(m_MenuInfo, 0, sizeof(MENUITEMINFO) * m_MenuInfoSize);
UINT menuIndex = 0;
BOOL b;
// 1st menu item
memset(m_MenuInfo + menuIndex, 0, sizeof(MENUITEMINFO));
m_MenuInfo[menuIndex].cbSize = sizeof(MENUITEMINFO);
m_MenuInfo[menuIndex].fMask = MIIM_ID | MIIM_STRING | MIIM_DATA;
m_MenuInfo[menuIndex].wID = menuIndex;
m_MenuInfo[menuIndex].dwTypeData = new WCHAR[10];
swprintf_s(m_MenuInfo[menuIndex].dwTypeData, 10, L"%s", L"A1");
m_MenuInfo[menuIndex].cch = wcslen(m_MenuInfo[menuIndex].dwTypeData) + 1;
b = InsertMenuItem(m_ApplicationMenu, menuIndex, TRUE, &(m_MenuInfo[menuIndex]));
menuIndex++;
// 2nd menu item
memset(&m_MenuInfo[menuIndex], 0, sizeof(MENUITEMINFO));
m_MenuInfo[menuIndex].cbSize = sizeof(MENUITEMINFO);
m_MenuInfo[menuIndex].fMask = MIIM_ID | MIIM_STRING | MIIM_DATA;
m_MenuInfo[menuIndex].wID = menuIndex;
m_MenuInfo[menuIndex].dwTypeData = new WCHAR[10];
swprintf_s(m_MenuInfo[menuIndex].dwTypeData, 10, L"%s", L"B2");
m_MenuInfo[menuIndex].cch = wcslen(m_MenuInfo[menuIndex].dwTypeData) + 1;
b = InsertMenuItem(m_ApplicationMenu, menuIndex, TRUE, &(m_MenuInfo[menuIndex]));
menuIndex++;
// Attach menu to CMFCMenuButton
m_ApplicationList.m_bOSMenu = TRUE;
m_ApplicationList.m_bRightArrow = FALSE;
m_ApplicationList.m_bStayPressed = TRUE;
m_ApplicationList.m_bDefaultClick = FALSE;
m_ApplicationList.m_hMenu = m_ApplicationMenu;
// Testing the constructed menu with the dialog's menu bar
::SetMenu(this->m_hWnd, m_ApplicationMenu);
当我运行该应用程序时,CMFCMenuButton
单击它时会显示一个下拉菜单......但这两个项目是空的,没有文本也没有图像。
我添加了最后一行来测试我构建的菜单;并且这两个项目正确显示在菜单栏中。
我还尝试使用从资源编辑器创建的菜单。它在菜单栏中显示得很好,但在 中CMFCMenuButton
,又出现了空白。
我错过了什么?