我正在使用 MFC,并且成功地创建了自定义绘制的菜单。每个菜单项都被正确测量和绘制,除了主级别项。我唯一无法完成的是重绘应用程序菜单栏。
我附上了两张图片:
- 第一个显示菜单栏的一部分。字体 Consolas 11pt 绘制正确。按钮的宽度计算正确,按钮需要分布在两行中。
- 第二张图片显示了相同的菜单栏,字体为 Consolas 20pt。现在菜单需要三行来包含所有菜单项。但是,每个单独行的高度不会更新。(在调试时,我看到 MeasureItem 覆盖计算每个菜单项的正确高度)。在菜单栏下方,有一个工具栏 (BCGToolBar),用于计算其栏的正确高度。
所以无论字体大小是什么,应用程序菜单栏永远不会改变它的高度?
如何在此 MFC 应用程序中调整应用程序菜单栏的大小?
到目前为止,我尝试过的事情是以不同的顺序遵循代码行:
RECT barRect;
barRect.top = 0;
barRect.left = 0;
barRect.bottom = 100;
barRect.right = 1020;
m_pMainWnd->RepositionBars(0, 0, 0, 2, &barRect);
m_pMainWnd->GetTopLevelFrame()->RecalcLayout();
m_pMainWnd->DrawMenuBar();
for (POSITION pos = m_pMainWnd->GetTopLevelFrame()->m_listControlBars.GetHeadPosition(); pos != NULL;)
{
CControlBar* controlBar = reinterpret_cast<CControlBar*>(m_pMainWnd->GetTopLevelFrame()->m_listControlBars.GetNext(pos));
controlBar = nullptr; //Let's see what we can do with this. Is the menuBar a ControlBar? Didnt think so.
}
m_pMainWnd->RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);