By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,136 Members | 1,054 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,136 IT Pros & Developers. It's quick & easy.

Force MeasureItem in OwnerDraw menu?

P: n/a
How can I force a MeasureItem message for an owner-dramn menu item?

Here is the dilemma. I wrote a lovely little Component for owner-drawing all
the menus on a form and making them look like Office XP-style menus (mostly
an academic exercise). I came across a problem with another app I wrote,
which is using this Component. The app changes the text in the menu items
depending on what is selected in the app. The fisrt time the menu may be
show (when it calls MeasureItem), the menu is appropriately owner-sized to
the text. The next time the menu is shown, the text will be different (in
this case longer). Since MeasureItem is never called again, the menu cannot
be appropriately sized to the text. In this instance, it cuts off the text
of the longer menu text.

Is there any way I can force Windows to send this message again?

Any help is appreciated.
Thanks in advance

WALDO
MCP, MCAD, MCSD
Aug 22 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Remove the menuitem, modify it's text then reinsert the menuitem.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Rob Mayo" <NO****@NOSPAM.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
How can I force a MeasureItem message for an owner-dramn menu item?

Here is the dilemma. I wrote a lovely little Component for owner-drawing
all
the menus on a form and making them look like Office XP-style menus
(mostly
an academic exercise). I came across a problem with another app I wrote,
which is using this Component. The app changes the text in the menu items
depending on what is selected in the app. The fisrt time the menu may be
show (when it calls MeasureItem), the menu is appropriately owner-sized to
the text. The next time the menu is shown, the text will be different (in
this case longer). Since MeasureItem is never called again, the menu
cannot
be appropriately sized to the text. In this instance, it cuts off the text
of the longer menu text.

Is there any way I can force Windows to send this message again?

Any help is appreciated.
Thanks in advance

WALDO
MCP, MCAD, MCSD

Aug 22 '05 #2

P: n/a
That did it. Thanks Mick

That seems to work very well as a rule when using OwnerDraw menus in
applications. If you're going to change the text of an owner drawn menu
item, remove it, change the text, then re-add it.

Just FYI, since my Component is where all the code lies, and is dependent on
menu events firing, it wasn't really feasible to add code like this here,
but I have a nice little workaraound.

From you telling me to remove the menu and add it again, I looked under the
hood (Using Lutz Roeder's Reflector) at what's going on in the Add method of
the MenuItemCollection class. There I found a method called ItemsChanged().
I examined that method and found another called DestroyMenuItems(). From
that I figured how the menus are getting refreshed.

In my Component, I hook into the Popup event (which fires before the actual
menu pops up), then use reflection to call that method to destroy the
handles on the sub items of the menu.

"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
Remove the menuitem, modify it's text then reinsert the menuitem.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Rob Mayo" <NO****@NOSPAM.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
How can I force a MeasureItem message for an owner-dramn menu item?

Here is the dilemma. I wrote a lovely little Component for owner-drawing
all
the menus on a form and making them look like Office XP-style menus
(mostly
an academic exercise). I came across a problem with another app I wrote,
which is using this Component. The app changes the text in the menu items depending on what is selected in the app. The fisrt time the menu may be
show (when it calls MeasureItem), the menu is appropriately owner-sized to the text. The next time the menu is shown, the text will be different (in this case longer). Since MeasureItem is never called again, the menu
cannot
be appropriately sized to the text. In this instance, it cuts off the text of the longer menu text.

Is there any way I can force Windows to send this message again?

Any help is appreciated.
Thanks in advance

WALDO
MCP, MCAD, MCSD


Aug 22 '05 #3

P: n/a
Now if I could only figure out how to intercept/override the method which
populates window lists, I'll be sitting pretty.
;)

"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
Remove the menuitem, modify it's text then reinsert the menuitem.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Rob Mayo" <NO****@NOSPAM.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
How can I force a MeasureItem message for an owner-dramn menu item?

Here is the dilemma. I wrote a lovely little Component for owner-drawing
all
the menus on a form and making them look like Office XP-style menus
(mostly
an academic exercise). I came across a problem with another app I wrote,
which is using this Component. The app changes the text in the menu items depending on what is selected in the app. The fisrt time the menu may be
show (when it calls MeasureItem), the menu is appropriately owner-sized to the text. The next time the menu is shown, the text will be different (in this case longer). Since MeasureItem is never called again, the menu
cannot
be appropriately sized to the text. In this instance, it cuts off the text of the longer menu text.

Is there any way I can force Windows to send this message again?

Any help is appreciated.
Thanks in advance

WALDO
MCP, MCAD, MCSD


Aug 22 '05 #4

P: n/a
Well, never bloody mind then ;)

It would seem that destroying the handles the way i did ALSO solved my
problem of hooking into the MDI list method. Yay :D

"Rob Mayo" <NO****@NOSPAM.com> wrote in message
news:eP**************@tk2msftngp13.phx.gbl...
Now if I could only figure out how to intercept/override the method which
populates window lists, I'll be sitting pretty.
;)

"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
Remove the menuitem, modify it's text then reinsert the menuitem.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Rob Mayo" <NO****@NOSPAM.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
How can I force a MeasureItem message for an owner-dramn menu item?

Here is the dilemma. I wrote a lovely little Component for owner-drawing all
the menus on a form and making them look like Office XP-style menus
(mostly
an academic exercise). I came across a problem with another app I wrote, which is using this Component. The app changes the text in the menu items depending on what is selected in the app. The fisrt time the menu may be show (when it calls MeasureItem), the menu is appropriately
owner-sized
to the text. The next time the menu is shown, the text will be different (in this case longer). Since MeasureItem is never called again, the menu
cannot
be appropriately sized to the text. In this instance, it cuts off the text of the longer menu text.

Is there any way I can force Windows to send this message again?

Any help is appreciated.
Thanks in advance

WALDO
MCP, MCAD, MCSD



Aug 23 '05 #5

P: n/a
Actually, I opened my big mouth too soon. It seems that if my MDI children
don't have menus of their own, Destroying the handles works lovely. But when
they do, the merged menus aren't owner drawn and neither is the window list.

D'oh!
Back to the drawing board.

"Rob Mayo" <NO****@NOSPAM.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
Well, never bloody mind then ;)

It would seem that destroying the handles the way i did ALSO solved my
problem of hooking into the MDI list method. Yay :D

"Rob Mayo" <NO****@NOSPAM.com> wrote in message
news:eP**************@tk2msftngp13.phx.gbl...
Now if I could only figure out how to intercept/override the method which
populates window lists, I'll be sitting pretty.
;)

"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
Remove the menuitem, modify it's text then reinsert the menuitem.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Rob Mayo" <NO****@NOSPAM.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
> How can I force a MeasureItem message for an owner-dramn menu item?
>
> Here is the dilemma. I wrote a lovely little Component for owner-drawing > all
> the menus on a form and making them look like Office XP-style menus
> (mostly
> an academic exercise). I came across a problem with another app I wrote, > which is using this Component. The app changes the text in the menu

items
> depending on what is selected in the app. The fisrt time the menu
may be > show (when it calls MeasureItem), the menu is appropriately

owner-sized
to
> the text. The next time the menu is shown, the text will be

different (in
> this case longer). Since MeasureItem is never called again, the menu
> cannot
> be appropriately sized to the text. In this instance, it cuts off
the text
> of the longer menu text.
>
> Is there any way I can force Windows to send this message again?
>
> Any help is appreciated.
> Thanks in advance
>
> WALDO
> MCP, MCAD, MCSD
>
>



Aug 26 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.