Announcement

Collapse
No announcement yet.

Simulating a menubar in a child window

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

  • Simulating a menubar in a child window

    I am trying to write a control that will have a standard menubar in the control. Child windows can not have a standard menubar. Has anyone written any code duplicating the look and feel of a standard menubar with buttons(sensitive to mouse movements) and popup menus - and willing to share it. Thanks

    Jim

  • #2
    Sounds a bit like a toolbar, doesn't it?

    I know for me as a user, I would prefer a toolbar in a child window to another menu... I think of menus as "top level" items and more than one would confuse me.
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Hi James,

      Here is just a thought to get you started... this is not optimized code, proof of concept only.
      The last challenge is to continue hot-tracking over the labels while the popup menu has the focus.
      I'll be thinking this over, I might be back later...

      Regards,
      Jules

      Code:
      #Compile Exe
      #Dim All
      #Include "WIN32API.INC"
      %IDC_LABEL1  = 1001
      %IDC_LABEL2  = 1002
      %IDC_LABEL3  = 1003
      %IDC_LABEL4  = 1004
      %IDC_LABEL5  = 1005
      %IDD_DIALOG1 =  101
      '-Menu declares
      %IDM_POPUP1 = 201
      %IDM_POPUP2 = 202
      %IDM_POPUP3 = 203
         
      Declare CallBack Function ShowDIALOG1Proc()
      Declare Function ShowDIALOG1(ByVal hParent As Dword) As Long
         
      Function PbMain()
          ShowDIALOG1 %HWND_DESKTOP
      End Function
         
      '------------------------------------------------------------------------------
      '
      '------------------------------------------------------------------------------
      CallBack Function ShowDIALOG1Proc()
         
          LOCAL hMenu AS DWORD
          LOCAL xPos AS LONG, yPos AS LONG
          LOCAL rc AS RECT
         
          local xp as long, yp as long, pt AS POINTAPI
          local stext as string
          local bflag as long
         
          Select Case As Long CbMsg
              Case %WM_INITDIALOG
              Case %WM_LBUTTONDOWN
                  '--determine menu item
                  xp = lowrd(cblparam)
                  yp = hiwrd(cblparam)
                  pt.x = xp
                  pt.y = yp
                  ClientToScreen CBHNDL,pt
                  '--FILE MENU
                  GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL1), rc
                  If ptInRect(rc,pt.x,pt.y) THEN
                      '--add popup menu...
                      MENU NEW POPUP TO hMenu
                      MENU ADD STRING, hMenu, "Popup item 1", %IDM_POPUP1, %MF_ENABLED
                      MENU ADD STRING, hMenu, "Popup item 2", %IDM_POPUP2, %MF_ENABLED
                      MENU ADD STRING, hMenu, "-", 0, 0
                      MENU ADD STRING, hMenu, "Popup item 3", %IDM_POPUP3, %MF_ENABLED
                      '--get position of top menu item, & position popup below the label
                      '  note that xPos and yPos are in screen coordinates!
                      GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL1), rc
                      xPos = rc.nLeft : yPos = rc.nTop + (rc.nBottom-rc.nTop)
                      TrackPopupMenu hMenu,%TPM_LEFTALIGN OR %TPM_LEFTBUTTON,xPos,yPos,0,CBHNDL,BYVAL %NULL
                  END IF
                  '--EDIT MENU
                  GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL2), rc
                  If ptInRect(rc,pt.x,pt.y) THEN
                      '--add popup menu...
                      MENU NEW POPUP TO hMenu
                      MENU ADD STRING, hMenu, "Popup item 1", %IDM_POPUP1, %MF_ENABLED
                      MENU ADD STRING, hMenu, "Popup item 2", %IDM_POPUP2, %MF_ENABLED
                      MENU ADD STRING, hMenu, "-", 0, 0
                      MENU ADD STRING, hMenu, "Popup item 3", %IDM_POPUP3, %MF_ENABLED
                      '--get position of top menu item, & position popup below the label
                      '  note that xPos and yPos are in screen coordinates!
                      GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL2), rc
                      xPos = rc.nLeft : yPos = rc.nTop + (rc.nBottom-rc.nTop)
                      TrackPopupMenu hMenu,%TPM_LEFTALIGN OR %TPM_LEFTBUTTON,xPos,yPos,0,CBHNDL,BYVAL %NULL
                  END IF
                  '--VIEW MENU
                  GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL3), rc
                  If ptInRect(rc,pt.x,pt.y) THEN
                      '--add popup menu...
                      MENU NEW POPUP TO hMenu
                      MENU ADD STRING, hMenu, "Popup item 1", %IDM_POPUP1, %MF_ENABLED
                      MENU ADD STRING, hMenu, "Popup item 2", %IDM_POPUP2, %MF_ENABLED
                      MENU ADD STRING, hMenu, "-", 0, 0
                      MENU ADD STRING, hMenu, "Popup item 3", %IDM_POPUP3, %MF_ENABLED
                      '--get position of top menu item, & position popup below the label
                      '  note that xPos and yPos are in screen coordinates!
                      GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL3), rc
                      xPos = rc.nLeft : yPos = rc.nTop + (rc.nBottom-rc.nTop)
                      TrackPopupMenu hMenu,%TPM_LEFTALIGN OR %TPM_LEFTBUTTON,xPos,yPos,0,CBHNDL,BYVAL %NULL
                  END IF
                  '--TOOL MENU
                  GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL4), rc
                  If ptInRect(rc,pt.x,pt.y) THEN
                      '--add popup menu...
                      MENU NEW POPUP TO hMenu
                      MENU ADD STRING, hMenu, "Popup item 1", %IDM_POPUP1, %MF_ENABLED
                      MENU ADD STRING, hMenu, "Popup item 2", %IDM_POPUP2, %MF_ENABLED
                      MENU ADD STRING, hMenu, "-", 0, 0
                      MENU ADD STRING, hMenu, "Popup item 3", %IDM_POPUP3, %MF_ENABLED
                      '--get position of top menu item, & position popup below the label
                      '  note that xPos and yPos are in screen coordinates!
                      GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL4), rc
                      xPos = rc.nLeft : yPos = rc.nTop + (rc.nBottom-rc.nTop)
                      TrackPopupMenu hMenu,%TPM_LEFTALIGN OR %TPM_LEFTBUTTON,xPos,yPos,0,CBHNDL,BYVAL %NULL
                  END IF
                  '--FILE MENU
                  GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL5), rc
                  If ptInRect(rc,pt.x,pt.y) THEN
                      '--add popup menu...
                      MENU NEW POPUP TO hMenu
                      MENU ADD STRING, hMenu, "Popup item 1", %IDM_POPUP1, %MF_ENABLED
                      MENU ADD STRING, hMenu, "Popup item 2", %IDM_POPUP2, %MF_ENABLED
                      MENU ADD STRING, hMenu, "-", 0, 0
                      MENU ADD STRING, hMenu, "Popup item 3", %IDM_POPUP3, %MF_ENABLED
                      '--get position of top menu item, & position popup below the label
                      '  note that xPos and yPos are in screen coordinates!
                      GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL5), rc
                      xPos = rc.nLeft : yPos = rc.nTop + (rc.nBottom-rc.nTop)
                      TrackPopupMenu hMenu,%TPM_LEFTALIGN OR %TPM_LEFTBUTTON,xPos,yPos,0,CBHNDL,BYVAL %NULL
                  END IF
         
              CASE %WM_MOUSEMOVE
                  xp = lowrd(cblparam)
                  yp = hiwrd(cblparam)
                  stext = "xPos = " & str$(xp) & "   yPos = " & str$(yp)
                  setwindowtext cbhndl, byval strptr(stext)
                  pt.x = xp
                  pt.y = yp
                  ClientToScreen CBHNDL,pt
                  '--FILE MENU
                  GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL1), rc
                  If ptInRect(rc,pt.x,pt.y) THEN
                      Control Set Color CBHNDL,%IDC_LABEL1, -1, RGB(83,83,255)
                      Control Redraw CBHNDL,%IDC_LABEL1
                  Else
                      Control Set Color CBHNDL, %IDC_LABEL1, -1, %Yellow
                      Control Redraw CBHNDL,%IDC_LABEL1
                  END IF
                  '--EDIT MENU
                  GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL2), rc
                  If ptInRect(rc,pt.x,pt.y) THEN
                      Control Set Color CBHNDL,%IDC_LABEL2, -1,  RGB(83,83,255)
                      Control Redraw CBHNDL,%IDC_LABEL2
                  Else
                      Control Set Color CBHNDL, %IDC_LABEL2, -1, %Yellow
                      Control Redraw CBHNDL,%IDC_LABEL2
                  END IF
                  '-- VIEW MENU
                  GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL3), rc
                  If ptInRect(rc,pt.x,pt.y) THEN
                      Control Set Color CBHNDL,%IDC_LABEL3, -1,  RGB(83,83,255)
                      Control Redraw CBHNDL,%IDC_LABEL3
                  Else
                      Control Set Color CBHNDL, %IDC_LABEL3, -1, %Yellow
                      Control Redraw CBHNDL,%IDC_LABEL3
                  END IF
                  '-- TOOLS MENU
                  GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL4), rc
                  If ptInRect(rc,pt.x,pt.y) THEN
                      Control Set Color CBHNDL,%IDC_LABEL4, -1,  RGB(83,83,255)
                      Control Redraw CBHNDL,%IDC_LABEL4
                  Else
                      Control Set Color CBHNDL, %IDC_LABEL4, -1, %Yellow
                      Control Redraw CBHNDL,%IDC_LABEL4
                  END IF
                  '-- HELP MENU
                  GetWindowRect GetDlgItem(CBHNDL,%IDC_LABEL5), rc
                  If ptInRect(rc,pt.x,pt.y) THEN
                      Control Set Color CBHNDL,%IDC_LABEL5, -1,  RGB(83,83,255)
                      Control Redraw CBHNDL,%IDC_LABEL5
                  Else
                      Control Set Color CBHNDL, %IDC_LABEL5, -1, %Yellow
                      Control Redraw CBHNDL,%IDC_LABEL5
                  END IF
                                 
              Case %WM_COMMAND
                  Select Case As Long CbCtl
                      CASE %IDM_POPUP1
                          IF CBCTLMSG = %BN_CLICKED THEN
                              MSGBOX "%IDM_POPUP1"
                          END IF
                      CASE %IDM_POPUP2
                          IF CBCTLMSG = %BN_CLICKED THEN
                              MSGBOX "%IDM_POPUP2"
                          END IF
                      CASE %IDM_POPUP3
                          IF CBCTLMSG = %BN_CLICKED THEN
                              MSGBOX "%IDM_POPUP3"
                          END IF
                  End Select
          End Select
      End Function
         
      '------------------------------------------------------------------------------
      '
      '------------------------------------------------------------------------------
      Function ShowDIALOG1(ByVal hParent As Dword) As Long
          Local lRslt As Long
          Local hDlg  As Dword
          Dialog New hParent, "Cheezy Menu...", 132, 80, 329, 165, %WS_POPUP Or _
              %WS_BORDER Or %WS_DLGFRAME Or %WS_THICKFRAME Or %WS_CAPTION Or _
              %WS_SYSMENU Or %WS_MINIMIZEBOX Or %WS_MAXIMIZEBOX Or _
              %WS_CLIPSIBLINGS Or %WS_VISIBLE Or %DS_MODALFRAME Or %DS_3DLOOK Or _
              %DS_NOFAILCREATE Or %DS_SETFONT, %WS_EX_CONTROLPARENT Or %WS_EX_LEFT _
              Or %WS_EX_LTRREADING Or %WS_EX_RIGHTSCROLLBAR, To hDlg
          Control Add Label, hDlg, %IDC_LABEL1, "&File", 40, 50, 30, 10, %WS_CHILD _
              Or %WS_VISIBLE Or %SS_CENTER
          Control Set Color hDlg, %IDC_LABEL1, -1, %Yellow
          Control Add Label, hDlg, %IDC_LABEL2, "&Edit", 70, 50, 30, 10, %WS_CHILD _
              Or %WS_VISIBLE Or %SS_CENTER
          Control Set Color hDlg, %IDC_LABEL2, -1, %Yellow
          Control Add Label, hDlg, %IDC_LABEL3, "&View", 100, 50, 30, 10, %WS_CHILD _
              Or %WS_VISIBLE Or %SS_CENTER
          Control Set Color hDlg, %IDC_LABEL3, -1, %Yellow
          Control Add Label, hDlg, %IDC_LABEL4, "&Tools", 130, 50, 30, 10, _
              %WS_CHILD Or %WS_VISIBLE Or %SS_CENTER
          Control Set Color hDlg, %IDC_LABEL4, -1, %Yellow
          Control Add Label, hDlg, %IDC_LABEL5, "&Help", 160, 50, 30, 10, %WS_CHILD _
              Or %WS_VISIBLE Or %SS_CENTER
              Control Set Color hDlg, %IDC_LABEL5, -1, %Yellow
          Dialog Show Modal hDlg, Call ShowDIALOG1Proc To lRslt
          Function = lRslt
      End Function
      Last edited by Jules Marchildon; 18 Nov 2007, 07:03 PM. Reason: Added to code
      Best regards
      Jules
      www.rpmarchildon.com

      Comment


      • #4
        Thanks Jules

        That is what I am looking for. I was going to look how Borje handled the flat button behavior in his RRButton control.

        Thanks again.

        Comment


        • #5
          No problem James, I need the exercise. I did make some more changes, not posted as of yet, I added a mouse hook procedure and moved the hot-tracking there. I need to find out how to programmatically dismiss the popup menu, DestroyMenu does not have any effect on TrackPopupMenu, as soon as I can figure that part out, I can move the popup menu (destroy and create) while hot-tracking the menu strip, perhaps if I could simulate an Esc key press or mouseclick that would dismiss the popup menu. Still working on it...

          Regards,
          Jules
          Best regards
          Jules
          www.rpmarchildon.com

          Comment


          • #6
            To cancel a popup menu programmatically, do this
            Code:
            PostMessage hWndOwner, %WM_CANCELMODE, 0, 0
            hWndOwner = handle of window that owns the menu

            I wrote a menubar control that ships with Phoenix. Unfortunately, if you
            want your control to act and feel like the real thing, a lot of code is required.
            Dominic Mitchell
            Phoenix Visual Designer
            http://www.phnxthunder.com

            Comment


            • #7
              >I was going to look how Borje handled the flat button behavior in his RRButton control

              Those are a simply a separate registered window class with its own window procedure. The source code is included in the RBButton package.

              IIRC you have to write one separate function to register the class if you want to use those buttons in a dialog template (SDK style coding).

              MCM
              Michael Mattias
              Tal Systems Inc. (retired)
              Racine WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Use BS_PUSHLIKE button style to make a toolbar:
                http://www.powerbasic.com/support/pb...ad.php?t=22173
                Michael Mattias
                Tal Systems Inc. (retired)
                Racine WI USA
                [email protected]
                http://www.talsystems.com

                Comment

                Working...
                X