Force MeasureItem in OwnerDraw menu?

R

Rob Mayo

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
 
R

Rob Mayo

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"
 
R

Rob Mayo

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

"Mick Doherty"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top