CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Nov 2003
    Location
    Bucharest, Romania
    Posts
    32

    MeasureItem doesn't get called for a menu item....why?

    Hi !

    Situation:
    I created a self-drawn menu. My class it's called GMenu (derivated from CMenu).
    The first item in the menu is a popup item.
    In OnInitDialog I called ModifyMenu for setting the handle to the popup menu that would appear if user clicks the popup item, like this:
    Code:
    ModifyMenu( 0, MF_BYPOSITION | MF_POPUP | MF_OWNERDRAW, (UINT_PTR)hMenu, (LPCTSTR)data );
    (hMenu is a handle to a loaded menu)

    Problem:
    GMenu::MeasureItem it's called for all items except this popup item. In output window I get the warning:
    Code:
    Warning: unknown WM_MEASUREITEM for menu item 0x4160665
    What I already know
    I suppose the MFC is unable to transform this message to a function call.
    Menu isn't displayed correctly because the size of menu item is not known by MFC.

    Question
    Where could be my mistake? How can I convince MFC to call MeasureItem for this popup item?

    Thanks for your help.

  2. #2
    Join Date
    Jun 2003
    Location
    Bucharest, Romania
    Posts
    529

    Talking Re: MeasureItem doesn't get called for a menu item....why?

    would be much easier to search for a already implemented owner-draw menu.. And samples are enaugh...

    nu?
    Last edited by chi_luci; December 20th, 2004 at 07:14 AM.
    Help me help you ... rate this article if any good!

  3. #3
    Join Date
    Jun 2003
    Location
    Bucharest, Romania
    Posts
    529

    Lightbulb Re: MeasureItem doesn't get called for a menu item....why?

    and more:

    BOOL ModifyMenu(
    HMENU hMnu, // handle to menu
    UINT uPosition, // menu item to modify
    UINT uFlags, // menu item flags
    UINT uIDNewItem, // menu item identifier or handle to drop-down
    // menu or submenu
    LPCTSTR lpNewItem // menu item content
    );




    ----> daca pasezi NULL ca id de meniu nu prea are ce modifica, nu?
    Help me help you ... rate this article if any good!

  4. #4
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: MeasureItem doesn't get called for a menu item....why?

    Quote Originally Posted by chi_luci
    ----> daca pasezi NULL ca id de meniu nu prea are ce modifica, nu?
    Please keep everything in english as not everyone knows romanian...
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,241

    Re: MeasureItem doesn't get called for a menu item....why?

    Time to learn...
    Well, I agree with Marc. I just have tried to translate and it's quite difficult...
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  6. #6
    Join Date
    Jun 2003
    Location
    Bucharest, Romania
    Posts
    529

    Talking Re: MeasureItem doesn't get called for a menu item....why?

    Quote Originally Posted by Marc G
    Please keep everything in english as not everyone knows romanian...
    âââââ 꽾ﴙ
    well, they could learn...
    the thing is djeecka is less than 100m away so that if I screem he'll hear me for sure! And I surelly don't know how to scream in english!
    That line was not for "the forum" - just for him!
    Last edited by chi_luci; December 20th, 2004 at 07:19 AM.
    Help me help you ... rate this article if any good!

  7. #7
    Join Date
    Jun 2003
    Location
    Bucharest, Romania
    Posts
    529

    Re: MeasureItem doesn't get called for a menu item....why?

    Quote Originally Posted by ovidiucucu
    Time to learn...
    Well, I agree with Marc. I just have tried to translate and it's quite difficult...
    Help me help you ... rate this article if any good!

  8. #8
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: MeasureItem doesn't get called for a menu item....why?

    Quote Originally Posted by chi_luci
    well, they could learn...
    the thing is djeecka is less than 100m away so that if I screem he'll hear me for sure! And I surelly don't know how to scream in english!
    Lol

    Quote Originally Posted by chi_luci
    That line was not for "the forum" - just for him!
    That's what Instant Messaging (IM) is for
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  9. #9
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: MeasureItem doesn't get called for a menu item....why?

    Quote Originally Posted by ovidiucucu
    Time to learn...
    Well, I agree with Marc. I just have tried to translate and it's quite difficult...
    Lol... you have difficulty to translate it though you are from Romania yourself ....
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  10. #10
    Join Date
    Nov 2003
    Location
    Bucharest, Romania
    Posts
    32

    Re: MeasureItem doesn't get called for a menu item....why?

    for the most of the people (the ones that don't know ROMANIAN ):

    Quote Originally Posted by chi_luci
    ----> daca pasezi NULL ca id de meniu nu prea are ce modifica, nu?
    means that
    "----> if you pass NULL as Menu ID in the call to ModifyMenu(...) you don't have what to modify"

    but chi_luci hadn't seen that I pass 0 as menu item ID because I access the item by his position( MF_BYPOSITION... yes, it's the first item) ;

    So, where is my mistake?

  11. #11
    Join Date
    Nov 2003
    Location
    Bucharest, Romania
    Posts
    32

    Re: MeasureItem doesn't get called for a menu item....why?

    Everything is woking well until I insert a popup item.

    DrawItem gets called for this popup item but MeasureItem doesn't. Why?
    The more you learn, the more you want...C++

  12. #12
    Join Date
    Jun 2003
    Location
    Bucharest, Romania
    Posts
    529

    Re: MeasureItem doesn't get called for a menu item....why?

    Quote Originally Posted by djeecka
    for the most of the people (the ones that don't know ROMANIAN ):
    means that
    "----> if you pass NULL as Menu ID in the call to ModifyMenu(...) you don't have what to modify"

    but chi_luci hadn't seen that I pass 0 as menu item ID because I access the item by his position( MF_BYPOSITION... yes, it's the first item) ;

    So, where is my mistake?
    ?? the real translation is "----> if you pass NULL as Menu ID in the call to ModifyMenu(...) you don't quite have what to modify" if you want to be 100% correct!

    now I get it:
    by
    Quote Originally Posted by djeecka
    ModifyMenu( 0, MF_BYPOSITION | MF_POPUP | MF_OWNERDRAW, (UINT_PTR)hMenu, (LPCTSTR)data );
    you meant:
    Code:
    pMenu->ModifyMenu( 0, MF_BYPOSITION | MF_POPUP | MF_OWNERDRAW, (UINT_PTR)hMenu, (LPCTSTR)data )
    which is other thing!
    you didn't specify that ...
    Help me help you ... rate this article if any good!

  13. #13
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: MeasureItem doesn't get called for a menu item....why?

    It's a 'bug/feature' of MFC. You need to handle the WM_MEASUREITEM message in the owner-window as it's explained in the following knowledge base article:
    http://support.microsoft.com/default...b;en-us;143209
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  14. #14
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: MeasureItem doesn't get called for a menu item....why?

    Quote Originally Posted by chi_luci
    ok, now serious.. I think that the framework does not send this message for popups.
    Yes it does. Window that owns menu received WM_MEASUREITEM message and calls MeasureItem virtual member of the menu for owner drawn menu items after performing certain checking.

    Default implementation of WM_MEASUREITEM handler in CWnd class tries to find menu item ID iterating all menus.
    Then it compares itemID member of MEASUREITEMSTRUCT with menu item ID.
    Since popup menus do not have ID therefore MEASUREITEMSTRUCT contains handle to a popup instead. Comparison fails and MeasureItem is not called. This also trace message you have posted before.

    Override WM_MEASUREITEM in a class that menu is assigned to *** follows:


    Code:
    void CYourWindowClass::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
    {
    	if (lpMeasureItemStruct->CtlType == ODT_MENU && lpMeasureItemStruct->itemID == (UINT)m_YourPopup.m_hMenu)
    	{
    		m_YourPopup.MeasureItem(lpMeasureItemStruct);
    		return;
    	}
    	CWnd::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
    }
    m_YourPopup is your CMenu derived class type that contains MeasureItem override..
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  15. #15
    Join Date
    Nov 2003
    Location
    Bucharest, Romania
    Posts
    32

    Re: MeasureItem doesn't get called for a menu item....why?

    I hoped GMenu will do all the work...but it seems that this can't be done.

    Thanks...
    The more you learn, the more you want...C++

Page 1 of 2 12 LastLast

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