CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2021
    Posts
    10

    [RESOLVED] CMenu own draw - set submenu height

    Hi gurus,

    I have my custom context menu created. Everything is working well, except for one thing. I can set up menu-item height in the MeasureItem function, but my context menu contains a submenu how can I the submenu height?

    Thx in advance.

    Screenshot: Notice the first item is a submenu and it's narrow against the rest of the items.
    Name:  sb.jpg
Views: 87
Size:  12.6 KB

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,313

    Re: CMenu own draw - set submenu height

    See this Microsoft KB
    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2021
    Posts
    10

    Re: CMenu own draw - set submenu height

    I got your point but this is not my case. The itemIDs in my OnMeasureItem func are indeed itemIDs. The problem is simply that I enter this function only 6 times and I have 7 menu items including the submenu. So the submenu is not treated as a menuitem.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,313

    Re: CMenu own draw - set submenu height

    Have you implemented the OnMeasureItem method in the window class that owns the menu?
    Example: https://forums.codeguru.com/showthre...76#post1066776
    Victor Nijegorodov

  5. #5
    Join Date
    Dec 2021
    Posts
    10

    Re: CMenu own draw - set submenu height

    Thank you for your help. I found the problem. I followed owner menu article from here: https://www.codeguru.com/cplusplus/c...-step-by-step/.
    The problem was in the ChangeToOwnerDraw function, which set the MF_OWNERDRAW flag to every menuitem or submenu.

    For submenus they set 0 as a NewItemID which should be a handle to submenu instead. Now I get into the OnMeasureItem function 7 times and the itemID is a submenu handle as you mentioned. This is no problem for me because I set the same height for every item.
    pMyMenu->ModifyMenu(i, MF_BYPOSITION | MF_OWNERDRAW, 0, (LPCTSTR)pMenuData);

    The altered piece of code is :
    pMyMenu->ModifyMenu(i, MF_BYPOSITION | MF_OWNERDRAW , (UINT) pMyMenu->GetSubMenu(i)->GetSafeHmenu(), (LPCTSTR)pMenuData);

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,313

    Re: CMenu own draw - set submenu height

    Glad you could solve it!
    Victor Nijegorodov

  7. #7
    Join Date
    Dec 2021
    Posts
    10

    Re: CMenu own draw - set submenu height

    Thanks again for your time. Have a nice day.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured