简体   繁体   中英

How can I resize an application menu bar in a MFC application?

I am working with MFC and I have created succesfully custom-drawn menus. Each menu-item is measured and drawn correctly, except the mainlevel-items. The only thing I can't get done is redrawing the application menubar.

I attached two images:

  1. The first shows a part of the menubar. The font Consolas 11pt is drawed correct. The width of the buttons is calculated correct, the buttons need to be spread over two rows.
  2. The second image shows the same menubar with font Consolas 20pt. Now the menu needs three rows to contain all menu-items. However, the height for each separate row, is not updated. (while debugging, I see the MeasureItem override calculates the correct height for each menu-item). Below the menubar, there is a toolbar (BCGToolBar), which calculates the correct height for its bar.

So whatever the fontsize is, the Application Menu Bar will never change its height?

How can I resize the application menu bar in this MFC application?

两行菜单,字体大小正常 两行大字体的菜单

Things I have tried so far is following lines of code in different orders:

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);

The first part is not an answer to the direct question but it should clarify why there is no need for it.

The menu is part of the global UI. Also the size of a menu items is part of the global settings.

If the user wants it, he can change the windows settings to get a larger menu.

I don't think it is a good way to change the standard behaviour. A UI should be stable, persistent and consistent. All programs should have the same look and feel. This includes the menu bar.

Now to your question.

You receive the WM_MEASUREITEM message. Respond to it and you can change the height for an onwerdraw menu.

See: http://www.codeguru.com/cpp/controls/menu/article.php/c3719/The-Easiest-Way-to-Code-the-Owner-Drawn-Menu.htm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM