|
-
December 19th, 2004, 04:54 PM
#1
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.
-
December 20th, 2004, 04:48 AM
#2
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!
-
December 20th, 2004, 05:53 AM
#3
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!
-
December 20th, 2004, 06:49 AM
#4
Re: MeasureItem doesn't get called for a menu item....why?
 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...
-
December 20th, 2004, 06:58 AM
#5
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...
-
December 20th, 2004, 07:11 AM
#6
Re: MeasureItem doesn't get called for a menu item....why?
Last edited by chi_luci; December 20th, 2004 at 07:19 AM.
Help me help you ... rate this article if any good!
-
December 20th, 2004, 07:13 AM
#7
Re: MeasureItem doesn't get called for a menu item....why?
 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!
-
December 20th, 2004, 07:30 AM
#8
Re: MeasureItem doesn't get called for a menu item....why?
 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 
 Originally Posted by chi_luci
That line was not for "the forum" - just for him! 
That's what Instant Messaging (IM) is for
-
December 20th, 2004, 07:30 AM
#9
Re: MeasureItem doesn't get called for a menu item....why?
 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 ....
-
December 20th, 2004, 08:28 AM
#10
Re: MeasureItem doesn't get called for a menu item....why?
for the most of the people (the ones that don't know ROMANIAN ):
 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?
-
December 20th, 2004, 08:48 AM
#11
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++
-
December 20th, 2004, 09:17 AM
#12
Re: MeasureItem doesn't get called for a menu item....why?
 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
 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!
-
December 20th, 2004, 11:30 AM
#13
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
-
December 20th, 2004, 01:29 PM
#14
Re: MeasureItem doesn't get called for a menu item....why?
 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.
-
December 20th, 2004, 01:44 PM
#15
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++
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|