Announcement

Collapse
No announcement yet.

MDI Menu Dropdown

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

  • MDI Menu Dropdown

    I was looking through past questions I had to see if questions I had then, I could understand now? and ran into Pierre Bellisle's Menu-Dropdown example. (I will post a copy below) that works GREAT with a single dialog, but I am trying to get it to work with an MDI window.

    Thinking it was a mistake in my code, I went back to PbNote.bas example to see if it would work there, and I can not make it work there either.

    Win32Api docs say
    Any WM_SYSCOMMAND messages not handled by the application must be passed to DefWindowProc. Any command values added by an application must be processed by the application and cannot be passed to DefWindowProc.
    But I am unsure how to handle it in the MDI environment.

    Does anyone have an example how to drop down the menu in a MDI dialog?
    Pierre's excellent example for a single dialog is below
    Code:
    #COMPILE EXE '#Win 8.04#
    #DIM ALL
    #INCLUDE "Win32Api.inc" '#2005-01-27#
    
    %ButtonTest  = 101
    %ButtonQuit  = 102
    %MenuOpen    = 201
    %MenuExit    = 202
    %MenuOption1 = 203
    %MenuOption2 = 204
    %MenuHelp    = 205
    %MenuAbout   = 206
    %TimerOne    = 301
    '______________________________________________________________________________
    
    CALLBACK FUNCTION DlgProc()
     STATIC NextStep AS LONG
    
     SELECT CASE CBMSG
    
       CASE %WM_COMMAND
         SELECT CASE LOWRD(CBWPARAM)
    
           CASE %ButtonTest
             IF NextStep = 0 THEN
               SetTimer CBHNDL, %TimerOne, 500, BYVAL %NULL
               NextStep = 1
               CONTROL SET TEXT CBHNDL, %ButtonTest, "&Stop"
             ELSE
               KillTimer CBHNDL, %TimerOne
               NextStep = 0
               CONTROL SET TEXT CBHNDL, %ButtonTest, "&Start"
             END IF
    
           CASE %MenuOpen TO %MenuAbout
            ' MessageBox CBHNDL, BYCOPY "%Menu id" & STR$(CBWPARAM), _
            '   BYCOPY "Pop menu", %MB_ICONINFORMATION OR %MB_OK
    
           CASE %ButtonQuit
             DIALOG END CBHNDL, 0
    
         END SELECT
    
       CASE %WM_TIMER
         IF CBWPARAM = %TimerOne THEN
           IF NextStep >= 1 THEN
    MSGBOX STR$(CBHNDL)            
             SELECT CASE NextStep
               CASE  1 : PostMessage CBHNDL, %WM_SYSCOMMAND, %SC_KEYMENU, %VK_F 'ALT-F
               CASE  2 : PostMessage CBHNDL, %WM_KEYDOWN, %VK_M, 0              'M key
               CASE  3 : PostMessage CBHNDL, %WM_KEYDOWN, %VK_DOWN, 0           'Down arrow
               CASE  4 : PostMessage CBHNDL, %WM_KEYDOWN, %VK_LEFT, 0           'Left arrow
               CASE  5 : PostMessage CBHNDL, %WM_KEYDOWN, %VK_UP, 0             'Up arrow
               CASE  6 : PostMessage CBHNDL, %WM_KEYDOWN, %VK_MENU, 0           'A second ALT key to exit menu
               CASE  7 : PostMessage CBHNDL, %WM_SYSCOMMAND, %SC_KEYMENU, %VK_H 'ALT-H
               CASE  8 : PostMessage CBHNDL, %WM_KEYDOWN, %VK_DOWN, 0           'Down arrow
               CASE  9 : PostMessage CBHNDL, %WM_KEYDOWN, %VK_UP, 0             'Up arrow
               CASE 10 : PostMessage CBHNDL, %WM_KEYDOWN, %VK_DOWN, 0           'Down arrow
               CASE 11 : PostMessage CBHNDL, %WM_KEYDOWN, %VK_A, 0              'A key
               CASE 12 : 'Do a half seconds pause
               CASE ELSE : NextStep = 0
             END SELECT
             INCR NextStep
           END IF
         END IF
    
       CASE %WM_ENTERSIZEMOVE
         IF NextStep >= 1 THEN
           NextStep = -1
         END IF
    
       CASE %WM_EXITSIZEMOVE
         IF NextStep = -1 THEN
           NextStep = 1
         END IF
    
       CASE %WM_NCACTIVATE
         IF CBWPARAM THEN 'Application is getting focus
           IF NextStep = -1 THEN
             NextStep = 1
           END IF
         ELSE 'Application is about to loose focus
           IF NextStep THEN
             NextStep = -1
           END IF
         END IF
    
       CASE %WM_DESTROY
         IF NextStep THEN KillTimer CBHNDL, %TimerOne
    
     END SELECT
    
    END FUNCTION
    '______________________________________________________________________________
    
    FUNCTION PBMAIN () AS LONG
     LOCAL hDlg    AS DWORD
     LOCAL hMenu   AS DWORD
     LOCAL hPopup1 AS DWORD
     LOCAL hPopup2 AS DWORD
     LOCAL hPopup3 AS DWORD
    
     MENU NEW BAR TO hMenu
    
     MENU NEW POPUP TO hPopup1
     MENU ADD STRING, hPopup1, "&Open", %MenuOpen, %MF_ENABLED
     MENU ADD STRING, hPopup1, "&Exit", %MenuExit, %MF_ENABLED
     MENU ADD STRING, hPopup1, "-",      0, 0
     MENU ADD POPUP, hMenu, "&File", hPopup1, %MF_ENABLED
    
     MENU NEW POPUP TO hPopup2
     MENU ADD STRING, hPopup2, "Option &1", %MenuOption1, %MF_ENABLED
     MENU ADD STRING, hPopup2, "Option &2", %MenuOption2, %MF_ENABLED
    
     MENU ADD POPUP, hPopup1, "&More Options", hPopup2, %MF_ENABLED
    
     MENU NEW BAR TO hPopup3
     MENU ADD STRING, hPopup3, "&Help", %MenuHelp, %MF_ENABLED
     MENU ADD STRING, hPopup3, "-",      0, 0
     MENU ADD STRING, hPopup3, "&About", %MenuAbout, %MF_ENABLED
    
     MENU ADD POPUP, hMenu, "&Help", hPopup3, %MF_ENABLED
    
     DIALOG NEW %HWND_DESKTOP, "Provoke menu", , ,160, 80, _
       %DS_CENTER OR %WS_SYSMENU OR %WS_MINIMIZEBOX TO hDlg
    
     SetClassLong hDlg, %GCL_HICON, LoadIcon(BYVAL %NULL, BYVAL %IDI_INFORMATION) 'Set a nice icon
    
     MENU ATTACH hMenu, hDlg
    
     CONTROL ADD BUTTON, hDlg, %ButtonTest, "&Start", 110, 8, 40, 14
     CONTROL ADD BUTTON, hDlg, %ButtonQuit, "&Quit", 110, 28, 40, 14, 0
    
     DIALOG SHOW MODAL hDlg, CALL DlgProc
    
    END FUNCTION
    '______________________________________________________________________________
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

  • #2
    >unsure how to handle it in the MDI environment
    DDT <> MDI

    >Does anyone have an example how to drop down the menu in a MDI dialog?

    You could try Key_event sending Alt+(menu hotkey) when the frame window is focused.

    Or, you could give the user a message when he does whatever it is you want him to do to get that menu to drop down: "Why don't you try using Alt+W; that's why the "W" is underlined on the menu bar! BTW if you move the mouse over the menu item; that will also drop down the menu."

    Or, you could call TrackPopupMenu (after getting a handle to desired menu) to show the desired menu wherever you want it and wait for the user to select something or dismiss the menu.



    MCM
    Last edited by Michael Mattias; 22 Mar 2008, 10:43 AM.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment

    Working...
    X