Announcement

Collapse
No announcement yet.

Dialog Menu Item -> ContextMenu

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

  • Dialog Menu Item -> ContextMenu

    How can i create ContextMenu for a dialog menu item.
    For example if i choose File -> Save and i press the right mouse
    botton a context menu will appear.

    Thank you
    Stavros


    ------------------
    Byte Hunters of the World Unite.

  • #2
    In 98+/2000+ there is even a special message - WM_MENURBUTTONUP.
    In 95/NT, I guess, should work following algorithm:
    %WM_INITMENU - Set a flag "in menu"
    %WM_EXITMENULOOP - Turn off "in menu"
    %WM_MENUSELECT
    If (HiWrd(wParam) And %MF_POPUP) = %MF_POPUP Then
    Ignore
    ElseIf (HiWrd(wParam) And %MF_SYSMENU) = %MF_SYSMENU Then
    Ignore
    Else
    Remember menu id (LoWrd(wParam))
    End If
    %WM_RBUTTONUP
    If "in menu" then ...

    ------------------
    E-MAIL: [email protected]

    Comment


    • #3
      Semen
      Thank you for your reply.This works fine when i right click on the
      main menu title (eg. File Edit ...) but when i right click a sub item
      in the pull down area (eg. File -> Save As) then nothing happens.
      Thanks again for your time
      Stavros


      ------------------
      Byte Hunters of the World Unite.

      Comment


      • #4
        Stavros --
        Following works fine on my PC under Win2000.
        Code:
           #Compile Exe
           #Register None
           #Dim All
           #Include "Win32Api.Inc"
        
           Function MainWndProc (ByVal hWnd As Long, ByVal wMsg As Long, _
                          ByVal wParam As Long, ByVal lParam As Long) As Long
        
              Select Case wMsg
                 Case %WM_CREATE
                    Local hMenu As Long, hPopup As Long
          
                    Menu New Bar To hMenu
                    Menu New Popup To hPopup
                    Menu Add String, hPopup, "&Load", 101, %MF_ENABLED
                    Menu Add String, hPopup, "&Save", 102, %MF_ENABLED
                    Menu Add String, hPopup, "-", 0, 0
                    Menu Add String, hPopup, "&Exit", 103, %MF_ENABLED
                    Menu Add Popup, hMenu, "&File", hPopup, %MF_ENABLED
        
                    Menu New Popup To hPopup
                    Menu Add String, hPopup, "&Undo", 111, %MF_ENABLED
                    Menu Add String, hPopup, "-", 0, 0
                    Menu Add String, hPopup, "&Cut", 112, %MF_ENABLED
                    Menu Add String, hPopup, "&Paste", 113, %MF_ENABLED
                    Menu Add Popup, hMenu, "&Edit", hPopup, %MF_ENABLED
                    
                    SetMenu hWnd, hMenu
                    
                Case %WM_INITMENU
                   Static InMenu As Long, IdMenu As Long
                   InMenu = %True: IdMenu = 0
                   
                Case %WM_EXITMENULOOP
                   InMenu = %False
                Case %WM_MENUSELECT
                   IdMenu = 0
                   If (HiWrd(wParam) And %MF_POPUP) = %MF_POPUP Then
                   ElseIf (HiWrd(wParam) And %MF_SYSMENU) = %MF_SYSMENU Then
                   Else
                      IdMenu = LoWrd(wParam)
                   End If
                     
                Case %WM_RBUTTONUP
                   If IdMenu Then MsgBox "Id =" + Str$(IdMenu)
                   
                Case %WM_DESTROY
                   PostQuitMessage 0
        
              End Select
        
              Function = DefWindowProc(hWnd, wMsg, wParam, lParam)
           End Function
        
           '-------------------------------------------------------------------------------------------------
        
           Function WinMain (ByVal hInstance As Long, ByVal hPrevInstance As Long, _
              lpCmdLine As Asciiz Ptr, ByVal iCmdShow As Long) As Long
        
              Local szClassName As Asciiz * 12
              Local wc          As WndClassEx
        
              szClassName       = "LtrXMainWnd"
              wc.cbSize        = Len(WndClassEx)
              wc.style         = %CS_HREDRAW Or %CS_VREDRAW
              wc.lpfnWndProc   = CodePtr(MainWndProc )
              wc.hInstance     = hInstance
              wc.hCursor       = LoadCursor(ByVal 0, ByVal %IDC_ARROW)
              wc.hbrBackground = %COLOR_WINDOW + 1
              wc.lpszClassName = VarPtr(szClassName)
              RegisterClassEx wc
        
              Local hWnd As Long
        
        
              hWnd = CreateWindowEx (0, szClassName, " Ltr-eXpress", _
                  %WS_SYSMENU Or %WS_THICKFRAME Or %WS_CLIPCHILDREN, _
                  0, 0, 0, 0, %HWND_DESKTOP, 0, hInstance, ByVal 0)
        
              ShowWindow hWnd, %SW_MAXIMIZE
              UpdateWindow hWnd
        
              Local Msg As tagMsg
        
              While GetMessage(Msg, ByVal 0&, 0, 0)
                 TranslateMessage Msg
                 DispatchMessage  Msg
              Wend
        
           End Function
        ------------------
        E-MAIL: [email protected]

        Comment


        • #5
          Semen
          Thanks again for your reply.Under Win98 second edition this
          example doesn't work,the problem is that idMenu remains 0 (zero)
          so the If IdMenu in the %WM_MENUSELECT is always false.
          I took out the 'IF' just to check on the %WM_RBUTTONUP message and
          i found out that i only get it when i press the right click over File or
          Edit ,and not over their sub menu items.


          ------------------
          Byte Hunters of the World Unite.

          Comment


          • #6
            A context menu is intended to be used in place of a normal menu, as
            a shortcut for actions that make the most sense in context. Using a
            context menu in a regular menu is not really appropriate unless,
            perhaps, you wish to offer context options that modify the regular
            menu itself.

            ------------------
            Tom Hanlin
            PowerBASIC Staff

            Comment


            • #7
              Stavros --
              I looked, what happends in 98 SE.
              There is no message WM_RBUTTONUP.
              Change %WM_RBUTTONUP to %WM_RBUTTONDOWN

              Tom --
              Microsoft made recursive menues exactly to display some menues.
              Exotic, but cool. Unf., works in 98/2000 only.

              ------------------
              E-MAIL: [email protected]

              Comment


              • #8
                Just because Microsoft does it, does not mean it's a good idea!

                ------------------
                Tom Hanlin
                PowerBASIC Staff

                Comment


                • #9
                  Thanks again for your replies.
                  Tom this is exactly the reason for wanting to use contextMenu
                  within a menu.
                  Stavros


                  ------------------
                  Byte Hunters of the World Unite.

                  Comment

                  Working...
                  X