0

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?

Two lines of menu with normal fontsize Two lines of menu with big fontsize

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);
Jaap Scheper
  • 67
  • 11
  • What class your `CMainFrame` derives from? If it is a `CFrameWndEx`|`CMDIFrameWndEx` and you are using a `CMFCMenubar` most likely you will not work the way you want as normal menus' behavior is overriden by the MFC Feature Pack – sergiol Sep 15 '17 at 15:27
  • `CMainFrame : : CMDIFrameWnd` I'm not using a CMFCMenubar afaik. I'm initializing the menus as follows: `if (!m_pTemplateCoverView) { m_pTemplateCoverView = new CMultiDocTemplate( IDR_EFAPPTYPE, RUNTIME_CLASS(CDBMaskeDoc), RUNTIME_CLASS(CCoverFrame), RUNTIME_CLASS(CCoverView)); m_TemplateCoverViewMenu.Attach(m_pTemplateCoverView->m_hMenuShared); } AddDocTemplate(m_pTemplateCoverView);` IDR_EFAPPTYPEis the resourceID of the menu. m_TemplateCoverViewMenu is the menu on which I will call later ChangeToOwnerDraw – Jaap Scheper Sep 20 '17 at 09:03

1 Answers1

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

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
xMRi
  • 14,982
  • 3
  • 26
  • 59
  • Thanks for replying. I have this assignment, so although I agree with you, I have to make the menu custom-drawn. I looked at the link you provided, and compiled the project I found there. That project does also not resize the menubar. I am already able to change the menubars font, fontsize, fontcolor, backgroundcolor, etcetera. Even the height of the toplevelmenu-items are calculated correct. – Jaap Scheper Sep 20 '17 at 11:11