Announcement

Collapse
No announcement yet.

adding to "sub" popup menus

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

  • adding to "sub" popup menus

    I have an SDK app with several popup menus defined in the .rc file. The first popup is "&File". Several menu items into this popup I have added two popup menus. Each is for a list of recent ly used files (files are for different devices and file types).

    I add a single dummy entry for both of these popups in the resource script.

    When my application initialized and loads its configuration, I want to add the menu items to each of these popups. I curently have a kludgy way of doing this and I know it can't be the correct/scnctioned way as it involves getting the popup menu menu
    handles when the WM_MENUSELECT message i sprocessed for either of these two popups.

    I have done extensive searching on the web and gone through Petzold's book thoroughly and it doesn't get this deep into menus.

    Is there a way to get the menu handle for these popup menus in lieu of waiting for them to be accessed?

    Here's an edited snippet of the &File popup menu with the "sub" popup menus.
    Code:
        POPUP "&File"
        BEGIN
            MENUITEM "Select &xxx xxxxxx File...",  %IDM_FILE_OPEN_xxx
            MENUITEM SEPARATOR
            MENUITEM "&Upload Text File xxxxxxxx...", %IDM_ULTEXTFILE
            MENUITEM SEPARATOR
            POPUP "&Recent U/L Files"
            BEGIN
                MENUITEM "&F",                          %IDM_RECENT_1
            END
            MENUITEM SEPARATOR
            POPUP "Recent &Cxxxx U/L Files"
            BEGIN
                MENUITEM "&F",                          %IDM_RECENT_Cxxxx_1
            END
            MENUITEM SEPARATOR
            MENUITEM "E&xit",                       %IDM_EXIT
        END
    Thanks,
    Ron

  • #2
    FROM THE SDK...
    The GetSubMenu function retrieves the handle of the pop-up menu activated by the specified menu item.

    HMENU GetSubMenu(

    HMENU hMenu, // handle of menu
    int nPos // menu item position
    );
    Parameters

    hMenu

    Identifies the menu.

    nPos

    Specifies the zero-based relative position in the given menu of an item that activates a pop-up menu.
    MCM
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Here's what I do in own MDI editor, maybe it can give tips. In WinMain:
      Code:
        hMenu       = LoadMenu(hInstance, "MAINMENU")
        hMnuFile    = GetSubMenu(hMenu, 0)            'File menu
        hMnuReopen  = GetSubMenu(hMnuFile, 2)         'Reopen files' submenu
      Menu in RC file looks like:
      Code:
      MAINMENU MENU LOADONCALL MOVEABLE
        BEGIN
          POPUP "&File"
            BEGIN
              MENUITEM "&New\tCtrl+N",                         IDM_NEW
              MENUITEM "&Open..\tCtrl+O",                      IDM_OPEN
              POPUP    " &Reopen..."
              BEGIN
                MENUITEM SEPARATOR
              END
              MENUITEM SEPARATOR
              MENUITEM "&Save\tCtrl+S",                        IDM_SAVE
              MENUITEM "Save &As..",                           IDM_SAVEAS
              MENUITEM SEPARATOR
              MENUITEM "&Print..\tCtrl+P",                     IDM_PRINT
              MENUITEM SEPARATOR
              MENUITEM "E&xit\tAlt+F4",                        IDM_EXIT
            END
      And just for fun - following is used to populate it from own ini file:
      Code:
      '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
      ' Read list of recently opened files from ini to menu - here max 8 files in list
      '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
      SUB GetRecentFiles ()
        LOCAL lpmii AS MENUITEMINFO, InString AS ASCIIZ * 255
        LOCAL Bc AS LONG, RetVal AS LONG
       
        lpmii.cbSize = SIZEOF(lpmii)
        lpmii.fMask  = %MIIM_TYPE OR %MIIM_ID
        lpmii.fType  = %MFT_STRING
       
        FOR Bc = GetMenuItemCount(hMnuReopen) - 1 TO 0 STEP - 1 'clear menu
           IF RemoveMenu(hMnuReopen, Bc, %MF_BYPOSITION) = 0 THEN EXIT FOR
           CALL DrawMenuBar(hMnuReopen)
        NEXT Bc
       
        Bc = 1
        DO
           RetVal = GetPrivateProfileString("Reopen files" & CHR$(0), _
                                             "File " & FORMAT$(Bc) & CHR$(0), _
                                             "Free" & CHR$(0), _
                                             InString, 255, INIfile & CHR$(0))
       
           IF RetVal AND LEFT$(InString, 4) <> "Free" THEN
              TempInString$ = TRIM$(LEFT$(InString, INSTR(InString, CHR$(0)) - 1))
              TempInString$ = "&" & FORMAT$(Bc) & " " & TempInString$
       
              lpmii.wID        = %IDM_RECENT1 + Bc - 1
              lpmii.dwTypeData = STRPTR(TempInString$)
              InsertMenuItem hMnuReopen, Bc, -1, BYVAL VARPTR(lpmii)
              'TempInString$ = CutDlgFileName$(TempInString$, 32, 0)
           ELSE
              EXIT DO
           END IF
           INCR Bc
           IF Bc > 8 THEN EXIT DO
        LOOP
       
      END SUB

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

      Comment


      • #4
        Michael, thanks for the reply. I was already aware of GetSubmenu () but failed to understand I could continue going deeper once I had a popup's (&File) handle.

        Borje, thanks for sending the snippet!. The first three lines showed me the way:
        hMenu = LoadMenu(hInstance, "MAINMENU")
        hMnuFile = GetSubMenu(hMenu, 0) 'File menu
        hMnuReopen = GetSubMenu(hMnuFile, 2) 'Reopen files Submenu
        Obtaining the handle to the popups under the &File popup was
        my delimna. I also, opted to use a SEPARATOR as the required MENUITEM for the popups under &File. The kludge is history.

        Thanks again, Michael and Borje!

        Ron

        [This message has been edited by Ron Pierce (edited July 01, 2001).]

        Comment

        Working...
        X