Force MeasureItem in OwnerDraw menu?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob Mayo

    #1

    Force MeasureItem in OwnerDraw menu?

    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


  • Mick Doherty

    #2
    Re: Force MeasureItem in OwnerDraw menu?

    Remove the menuitem, modify it's text then reinsert the menuitem.

    --
    Mick Doherty
    Dotnetrix offers Nothing. Standard and Premium versions available.



    "Rob Mayo" <NOSPAM@NOSPAM. com> wrote in message
    news:%23jk5ggzp FHA.320@TK2MSFT NGP09.phx.gbl.. .[color=blue]
    > 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
    >
    >[/color]


    Comment

    • Rob Mayo

      #3
      Re: Force MeasureItem in OwnerDraw menu?

      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 MenuItemCollect ion class. There I found a method called ItemsChanged().
      I examined that method and found another called DestroyMenuItem s(). 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"
      <EXCHANGE#WITH@ AND.REMOVE.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]> wrote in
      message news:%23Vcnh10p FHA.1028@TK2MSF TNGP09.phx.gbl. ..[color=blue]
      > Remove the menuitem, modify it's text then reinsert the menuitem.
      >
      > --
      > Mick Doherty
      > http://dotnetrix.co.uk/nothing.html
      >
      >
      > "Rob Mayo" <NOSPAM@NOSPAM. com> wrote in message
      > news:%23jk5ggzp FHA.320@TK2MSFT NGP09.phx.gbl.. .[color=green]
      > > 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[/color][/color]
      items[color=blue][color=green]
      > > 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[/color][/color]
      to[color=blue][color=green]
      > > the text. The next time the menu is shown, the text will be different[/color][/color]
      (in[color=blue][color=green]
      > > 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[/color][/color]
      text[color=blue][color=green]
      > > 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
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Rob Mayo

        #4
        Re: Force MeasureItem in OwnerDraw menu?

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

        "Mick Doherty"
        <EXCHANGE#WITH@ AND.REMOVE.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]> wrote in
        message news:%23Vcnh10p FHA.1028@TK2MSF TNGP09.phx.gbl. ..[color=blue]
        > Remove the menuitem, modify it's text then reinsert the menuitem.
        >
        > --
        > Mick Doherty
        > http://dotnetrix.co.uk/nothing.html
        >
        >
        > "Rob Mayo" <NOSPAM@NOSPAM. com> wrote in message
        > news:%23jk5ggzp FHA.320@TK2MSFT NGP09.phx.gbl.. .[color=green]
        > > 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[/color][/color]
        items[color=blue][color=green]
        > > 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[/color][/color]
        to[color=blue][color=green]
        > > the text. The next time the menu is shown, the text will be different[/color][/color]
        (in[color=blue][color=green]
        > > 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[/color][/color]
        text[color=blue][color=green]
        > > 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
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Rob Mayo

          #5
          Re: Force MeasureItem in OwnerDraw menu?

          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" <NOSPAM@NOSPAM. com> wrote in message
          news:eP77PC2pFH A.2652@tk2msftn gp13.phx.gbl...[color=blue]
          > Now if I could only figure out how to intercept/override the method which
          > populates window lists, I'll be sitting pretty.
          > ;)
          >
          > "Mick Doherty"
          > <EXCHANGE#WITH@ AND.REMOVE.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]> wrote[/color]
          in[color=blue]
          > message news:%23Vcnh10p FHA.1028@TK2MSF TNGP09.phx.gbl. ..[color=green]
          > > Remove the menuitem, modify it's text then reinsert the menuitem.
          > >
          > > --
          > > Mick Doherty
          > > http://dotnetrix.co.uk/nothing.html
          > >
          > >
          > > "Rob Mayo" <NOSPAM@NOSPAM. com> wrote in message
          > > news:%23jk5ggzp FHA.320@TK2MSFT NGP09.phx.gbl.. .[color=darkred]
          > > > How can I force a MeasureItem message for an owner-dramn menu item?
          > > >
          > > > Here is the dilemma. I wrote a lovely little Component for[/color][/color][/color]
          owner-drawing[color=blue][color=green][color=darkred]
          > > > 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[/color][/color][/color]
          wrote,[color=blue][color=green][color=darkred]
          > > > which is using this Component. The app changes the text in the menu[/color][/color]
          > items[color=green][color=darkred]
          > > > depending on what is selected in the app. The fisrt time the menu may[/color][/color][/color]
          be[color=blue][color=green][color=darkred]
          > > > show (when it calls MeasureItem), the menu is appropriately[/color][/color][/color]
          owner-sized[color=blue]
          > to[color=green][color=darkred]
          > > > the text. The next time the menu is shown, the text will be different[/color][/color]
          > (in[color=green][color=darkred]
          > > > 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[/color][/color]
          > text[color=green][color=darkred]
          > > > 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
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Rob Mayo

            #6
            Re: Force MeasureItem in OwnerDraw menu?

            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" <NOSPAM@NOSPAM. com> wrote in message
            news:%23$h17VBq FHA.644@TK2MSFT NGP10.phx.gbl.. .[color=blue]
            > 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" <NOSPAM@NOSPAM. com> wrote in message
            > news:eP77PC2pFH A.2652@tk2msftn gp13.phx.gbl...[color=green]
            > > Now if I could only figure out how to intercept/override the method[/color][/color]
            which[color=blue][color=green]
            > > populates window lists, I'll be sitting pretty.
            > > ;)
            > >
            > > "Mick Doherty"
            > > <EXCHANGE#WITH@ AND.REMOVE.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]> wrote[/color]
            > in[color=green]
            > > message news:%23Vcnh10p FHA.1028@TK2MSF TNGP09.phx.gbl. ..[color=darkred]
            > > > Remove the menuitem, modify it's text then reinsert the menuitem.
            > > >
            > > > --
            > > > Mick Doherty
            > > > http://dotnetrix.co.uk/nothing.html
            > > >
            > > >
            > > > "Rob Mayo" <NOSPAM@NOSPAM. com> wrote in message
            > > > news:%23jk5ggzp FHA.320@TK2MSFT NGP09.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[/color][/color]
            > owner-drawing[color=green][color=darkred]
            > > > > 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[/color][/color]
            > wrote,[color=green][color=darkred]
            > > > > which is using this Component. The app changes the text in the menu[/color]
            > > items[color=darkred]
            > > > > depending on what is selected in the app. The fisrt time the menu[/color][/color][/color]
            may[color=blue]
            > be[color=green][color=darkred]
            > > > > show (when it calls MeasureItem), the menu is appropriately[/color][/color]
            > owner-sized[color=green]
            > > to[color=darkred]
            > > > > the text. The next time the menu is shown, the text will be[/color][/color][/color]
            different[color=blue][color=green]
            > > (in[color=darkred]
            > > > > this case longer). Since MeasureItem is never called again, the menu
            > > > > cannot
            > > > > be appropriately sized to the text. In this instance, it cuts off[/color][/color][/color]
            the[color=blue][color=green]
            > > text[color=darkred]
            > > > > 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
            > > > >
            > > > >
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            Working...