Announcement

Collapse
No announcement yet.

Menus made easy

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

  • Charles Dietz
    replied
    Cliff, in CALLBACK FUNCTION DlgProc()

    IF CB.CTL => %ID_OPEN AND CB.CTL <= %ID_ABOUT THEN

    Shouldn't it be >= ?

    Leave a comment:


  • Cliff Nichols
    replied
    I found this in the docs:
    A DDT menu requires the parent DDT dialog to contain at least one child control for the menu to operate correctly.
    So I added a button, thinking maybe this is the problem? (Funny how my menu works fine with no DDT controls on the dialog, but I digress....)

    Anyways, I went back a step to the PB example for menus and I get the same sort of problem

    The PB code (Slightly Modified)
    Code:
    '===========================================================
    
    '
    
    ' Simple example of an application that has a menu and
    
    ' requires absolutely no API calls!
    
    '
    
    '===========================================================
    
    
    
    #COMPILE EXE
    
    
    
    %IDOK = 1
    
    %IDCANCEL = 2
    
    %IDTEXT = 100
    
    %BN_CLICKED = 0
    
    %BS_DEFAULT = 1
    
    %MF_ENABLED = 0
    
    %WM_COMMAND = &H111
    
    
    
    %ID_OPEN = 401
    
    %ID_EXIT = 402
    
    %ID_OPTION1 = 403
    
    %ID_OPTION2 = 404
    
    %ID_HELP = 405
    
    %ID_ABOUT = 406
    
    
    
    '-----------------------------------------------------------
    
    
    
    ' ** Global variable to receive the user name
    
    GLOBAL gsUserName AS STRING
    
    
    
    '-----------------------------------------------------------
    
    
    
    CALLBACK FUNCTION OkButton()
    
      IF CB.MSG = %WM_COMMAND AND CB.CTLMSG = %BN_CLICKED THEN
    
        CONTROL GET TEXT CB.HNDL, %IDTEXT TO gsUserName
    
        DIALOG END CB.HNDL, 1
    
        FUNCTION = 1
    
      END IF
    
    END FUNCTION
    
    
    
    '-----------------------------------------------------------
    
    
    
    CALLBACK FUNCTION CancelButton()
    
      IF CB.MSG = %WM_COMMAND AND CB.CTLMSG = %BN_CLICKED THEN
    
        DIALOG END CB.HNDL, 0
    
        FUNCTION = 1
    
        END IF
    
      END FUNCTION
    
    
    
    '-----------------------------------------------------------
    
    
    
    CALLBACK FUNCTION DlgProc()
    
      IF CB.MSG = %WM_COMMAND THEN
    
        IF CB.CTL => %ID_OPEN AND CB.CTL <= %ID_ABOUT THEN
    
          MSGBOX "WM_COMMAND received from a menu item!", &H00002000& ' = %MB_TASKMODAL
    
          FUNCTION = 1
    
        END IF
    
      END IF
    
    END FUNCTION
    
    
    
    '-----------------------------------------------------------
    
    
    
    FUNCTION PBMAIN () AS LONG
    
      LOCAL hDlg AS DWORD
    
      LOCAL lResult AS LONG
    
      LOCAL hMenu AS DWORD
    
      LOCAL hPopup1 AS DWORD
    
      LOCAL hPopup2 AS DWORD
    
    
    
      ' ** First create a top-level menu:
    
      MENU NEW BAR TO hMenu
    
    
    
      ' ** Add a top-level menu item with a popup menu:
    
      MENU NEW POPUP TO hPopup1
    
      MENU ADD POPUP, hMenu, "&File", hPopup1, %MF_ENABLED
    
      MENU ADD STRING, hPopup1, "&Open", %ID_OPEN, %MF_ENABLED
    
      MENU ADD STRING, hPopup1, "&Exit", %ID_EXIT, %MF_ENABLED
    
      MENU ADD STRING, hPopup1, "-", 0, 0
    
    
    
      ' ** Now we can add another item to the menu that will bring up a sub-menu.
    
      ' First we obtain a new popup menu handle to distinguish it from the first
    
      ' popup menu:
    
      MENU NEW POPUP TO hPopup2
    
    
    
      ' ** Now add a new menu item to the first menu.
    
      ' This item will bring up the sub-menu when selected:
    
      MENU ADD POPUP, hPopup1, "&More Options", hPopup2, %MF_ENABLED
    
    
    
      ' ** Now we will define the sub menu:
    
      MENU ADD STRING, hPopup2, "Option &1", %ID_OPTION1, %MF_ENABLED
    
    
    '&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
      MENU ADD STRING, hPopup2, "Option &2", %ID_OPTION2, %MF_DISABLED
    '*** Added Code
    LOCAL TempState AS LONG
      MENU GET STATE hPopup2, BYCMD %ID_OPTION2 TO TempState
    '  MENU GET STATE hPopup1, BYCMD hPopup2 TO TempState
    MSGBOX STR$(TempState) + $CR + STR$(HI(BYTE, TempState))
    '&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    
      ' ** Finally, we'll add a second top-level menu and popup.
    
      ' For this popup, we can reuse the first popup variable:
    
      MENU NEW POPUP TO hPopup1
    
      MENU ADD POPUP, hMenu, "&Help", hPopup1, %MF_ENABLED
    
      MENU ADD STRING, hPopup1, "&Help", %ID_HELP, %MF_ENABLED
    
      MENU ADD STRING, hPopup1, "-", 0, 0
    
      MENU ADD STRING, hPopup1, "&About", %ID_ABOUT, %MF_ENABLED
    
    
    
      ' ** Create a new dialog template
    
      DIALOG NEW 0, "What is your name?", ,, 160, 60, 0, 0 TO hDlg
    
    
    
      ' ** Add controls to it
    
      CONTROL ADD TEXTBOX, hDlg, %IDTEXT, "", 14, 12, 134, 12, 0
    
      CONTROL ADD BUTTON, hDlg, %IDOK, "OK", 34, 32, 40, 14, %BS_DEFAULT CALL OkButton
    
      CONTROL ADD BUTTON, hDlg, %IDCANCEL, "Cancel", 84, 32, 40, 14, 0 CALL CancelButton
    
    
    
      MENU ATTACH hMenu, hDlg
    
    
    
      ' ** Display the dialog
    
      DIALOG SHOW MODAL hDlg, CALL DlgProc TO lResult
    
    
    
      ' ** Check the dialog return result
    
      IF lResult THEN
    
        MSGBOX "Hello " & gsUserName
    
      END IF
    
    END FUNCTION
    
    
    
    '-----------------------------------------------------------
    Obviously I am mis-understanding the docs, but where

    I also could SWEAR I could add a menu bar to any side of my dialog, but can not find the doc that says that now???

    Leave a comment:


  • Cliff Nichols
    replied
    Every Menu.ParentMenu is a "PopUp" (Whether it is the "PopUp" menu above menu items it contains) or if it is a "PopUp" I am adding then the parentmenu would be the "PopUp" that contains this "PopUp" that I am adding.

    In the case of "Menu_Get_NumOf_Items" I am passing a PopUp to that function so it should come back with the number of "MenuItems" in that "PopUp" (Seeing how I have not begun to think of a function to determine if a popup or a menuitem just yet)

    Mostly a learning process type thing for me.

    Leave a comment:


  • Michael Mattias
    replied
    Well, just a quick look at your code....
    Iin your count function...
    Code:
             MENU GET STATE Menus.ParentMenu, BYCMD Menus.Identifier TO Menus.MenuState
    .. I don't think you are dealing with the right kind of menu for the LO(BYTE) thing to work:
    If the menu item is a popup child menu, the LO(BYTE, state&) of the return value contains the menu flags for the item, and the HI(BYTE, state&) contains the number of items in the popup child menu
    Menus.ParentMenu is not a child popup menu far as I can tell.

    (but I'm not a DDT guy)

    MCM

    Leave a comment:


  • Michael Mattias
    replied
    I have not looked at your code, but the GetMenuItemCount() function sure looks promising.

    Note that separators ARE included in this count.

    Leave a comment:


  • Cliff Nichols
    started a topic Menus made easy

    Menus made easy

    PB makes menus easy, but for me it can get really confusing as to which popup belongs where and etc. So normally I just put my menu in a resource (So I can see better what goes where).

    Now I find I have a need to clear things in my head so I decided to make a wrapper to keep things straight for me.

    Usually my train of thought is there is a menu, and there is a menu-item.

    One thing I can not make sense of is getting the number of menu-items as the docs say I can get from the Hi byte of the menu (popup) state.

    Attached is my code I am working on, can anyone see my mistake in getting the number of menu items????
    Attached Files
Working...
X