Announcement

Collapse
No announcement yet.

Need help with MENU commands

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help with MENU commands

    I've created a nice menu bar in a dialog with nested pop-up menus using the DDT MENU commands.

    The problem I'm having is that I cannot get the MENU SET STATE statement (are the pos& & state& parameters backwards from the docs?) to work with either the main menu handle or the nested menu handles. I am using the MENU DRAW BAR statement afterwards, but to no effect.

    Also, the MENU GET TEXT returns empty strings every time:

    ' ** Create a new dialog template
    DIALOG NEW 0, $Title, ,, 300, 200, %WS_POPUPWINDOW OR %WS_CAPTION OR _
    %WS_MAXIMIZEBOX OR %WS_MINIMIZEBOX OR %WS_SIZEBOX TO hDlg&

    ' Add a menu bar to the GUI
    MENU NEW BAR TO hMenu&

    ' Create a popup menu "File"
    MENU NEW POPUP TO hFile&
    MENU ADD STRING, hFile&, "E&xit", %IDCANCEL, %MF_ENABLED, CALL CancelButton
    ' Attach the popup menu to the menu bar
    MENU ADD POPUP, hMenu&, "&File", hFile&, %MF_ENABLED

    ' Create a popup menu "Edit"
    MENU NEW POPUP TO hEdit&
    MENU NEW POPUP TO hFirstEd&
    MENU ADD STRING, hFirstEd&, "&One", %ONE, %MF_ENABLED, CALL OneButton
    MENU ADD STRING, hFirstEd&, "&Two", %TWO, %MF_DISABLED, CALL TwoButton
    ...
    MENU ADD POPUP, hEdit&, "&First Edit Line", hFirstEd&, %MF_ENABLED
    MENU NEW POPUP TO hSecEd&
    MENU ADD STRING, hSecEd&, "&TwoOne", %TWOONE, %MF_ENABLED, CALL TwoOneButton
    MENU ADD STRING, hSecEd&, "T&woTwo", %TWOTWO, %MF_ENABLED, CALL TwoTwoButton
    ...
    MENU ADD POPUP, hEdit&, "&Second Edit Line", hSecEd&, %MF_ENABLED
    ...
    ' Attach the popup menu to the menu bar
    MENU ATTACH hMenu&, hDlg&

    I& = 0
    DIALOG SHOW MODELESS hDlg&
    DO
    DIALOG DOEVENTS

    IF I& = 1 THEN
    INCR I&
    MENU GET TEXT hFirstEd&, %ONE TO T$
    MSGBOX "hFirstEd Text = <"+T$+">"
    MENU GET TEXT hMenu&, %ONE TO T$
    MSGBOX "hMenu Text = <"+T$+">"
    END IF

    IF I& = 0 THEN
    INCR I&
    MENU SET STATE hMenu&, %MF_GRAYED, BYCMD %ONE
    MENU SET STATE hMenu&, %MF_ENABLED, BYCMD %TWO
    MENU DRAW BAR hDlg&
    END IF

    DIALOG GET SIZE hDlg& TO x&, x&
    LOOP UNTIL x& = 0


    ------------------
    Bernard Ertl

    [This message has been edited by Bern Ertl (edited January 31, 2001).]
    Bernard Ertl
    InterPlan Systems

  • #2
    There are some known "issues" with DDT's menu commands. Use the API
    instead, much safer. Some examples:
    Code:
    'to disable menu item
      EnableMenuItem hMenu&, %ONE,%MF_GRAYED
     
    'to get menu item's text
      LOCAL ln AS LONG, txt AS STRING
      ln = GetMenuString(hFirstEd&, %ONE, BYVAL %NULL, 0, %MF_BYCOMMAND) 'to get string length
      txt = SPACE$(ln + 1) 'add one for terminating zero
      ln = GetMenuString(hFirstEd&, %ONE, BYVAL STRPTR(Txt), LEN(Txt), %MF_BYCOMMAND)
      MSGBOX txt

    ------------------

    Comment


    • #3
      Aha! OK. Thanks Borje! Back to the saltmines.....



      ------------------
      Bernard Ertl
      Bernard Ertl
      InterPlan Systems

      Comment


      • #4
        Oops.. Forgot. One more question.

        Is there a direct way to disable the nested pop-ups ("First Edit Line" in my example), or do I need to disable all the strings it conatins? The DDT MENU statements don't assign an ID% to it....



        ------------------
        Bernard Ertl
        Bernard Ertl
        InterPlan Systems

        Comment


        • #5
          Add %MF_BYPOSITION to the call and you can disable/enable any item,
          even entire submenu, by its position, like: (not tested, but should work)

          EnableMenuItem hEdit&, 0, %MF_BYPOSITION OR %MF_GRAYED


          ------------------

          Comment


          • #6
            Thanks Borje, I got it working. Another success story.



            ------------------
            Bernard Ertl
            Bernard Ertl
            InterPlan Systems

            Comment


            • #7
              Aye caramba!

              I thought I had this menu business down. I'm trying to get a menu item to toggle the checked/unchecked mark. I'm using:

              EnableMenuItem hEdit&, 0, %MF_BYPOSITION OR %MF_CHECKED
              EnableMenuItem hEdit&, 0, %MF_BYPOSITION OR %MF_UNCHECKED

              but it is not working. If I use %MF_GRAYED, it does grey out the item, so everything appears to be in order. Are the equates in the WIN32API.INC file correct?

              Help!




              ------------------
              Bernard Ertl
              Bernard Ertl
              InterPlan Systems

              Comment


              • #8
                Yes, the equates are correct, but wrong call. Two ways to do it,
                either via SetMenuItemInfo, or simplier, toggle it via:
                Code:
                IF GetMenuState(hEdit&, 0, %MF_BYPOSITION OR %MF_CHECKED) THEN
                  CheckMenuItem hEdit&, 0, %MF_BYPOSITION OR %MF_UNCHECKED
                ELSE
                  CheckMenuItem hEdit&, 0, %MF_BYPOSITION OR %MF_CHECKED
                END IF
                ------------------


                [This message has been edited by Borje Hagsten (edited February 02, 2001).]

                Comment


                • #9
                  Aha! Thank you very much. Your patience and wisdom are greatly appreciated.



                  ------------------
                  Bernard Ertl
                  Bernard Ertl
                  InterPlan Systems

                  Comment


                  • #10
                    You should avoid using MF_BYPOSITION when working with menus since this
                    makes your code difficult to maintain. Use MF_BYCOMMAND instead. Now,
                    may have a valid reason for using MF_BYPOSITION if you are working with a
                    popup menu item and is using a version of the sdk that is older than version
                    4.0 or using a resource compiler that does not support the extended menu
                    structure(MENUEX).
                    See chapter 12, page 835 in Newcomer and Rector for more information on this topic.

                    ------------------
                    Dominic Mitchell
                    Dominic Mitchell
                    Phoenix Visual Designer
                    http://www.phnxthunder.com

                    Comment

                    Working...
                    X