Results 1 to 6 of 6

Thread: How do I show a menu?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 1999
    Location
    East Anglia, England
    Posts
    73

    Post

    I would like to show my File Menu when the user clicks on a command button, how would I go about doing this?

    Thanks
    Desire

  2. #2
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Post

    I'm not too sure what you mean but this might help???

    set the file menu's Visible property to false
    and put this code behind the button:

    private sub cmdGo_Click()
    file_Menu.visible = true
    end sub()

    Hope this helps!

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Assuming your file menu has an access key (an underlined letter) of "F", then SendKeys "%{F}" will do what you want.

    ------------------
    Marty

  4. #4
    Member
    Join Date
    Jan 1999
    Location
    Gig Harbor, WA, USA
    Posts
    48

    Post

    Or, you can just show a temporary copy of the menu, using the PopupMenu method.

    Code:
    Private Sub Command1_Click()
    Me.PopupMenu mnuFile
    End Sub
    ------------------
    (¯`·.¸¸.·´¯`·->ShadowCrawler<-·´¯`·.¸¸.·´¯)
    Teenage Programmer
    Visual Basic, HTML, C++, JavaScript

    http://welcome.to/X12Tech
    Email: [email protected]
    ICQ#: 9872708

  5. #5
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    Here's code I just made which entirely emulates the menu popping up:
    Code:
    Option Explicit
    
    
    Private Type POINTAPI
            X As Long
            Y As Long
    End Type
    
    
    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
    
    
    Private Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
    Private Declare Function GetMenuItemRect Lib "user32" (ByVal hWnd As Long, ByVal hMenu As Long, ByVal uItem As Long, lprcItem As RECT) As Long
    Private Declare Function HiliteMenuItem Lib "user32" (ByVal hWnd As Long, ByVal hMenu As Long, ByVal wIDHiliteItem As Long, ByVal wHilite As Long) As Long
    Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
    
    
    Private Const MF_BYPOSITION = &H400&
    Private Const MF_HILITE = &H80&
    Private Const MF_UNHILITE = &H0&
    
    
    Private Sub Command1_Click()
        Dim hMenu As Long, RCMenu As RECT, PT As POINTAPI
        Const MenuNumber = 0 ' Should be 0 for first menu in menu bar, 1 for second, etc.
        hMenu = GetMenu(hWnd)
        Call GetMenuItemRect(hWnd, hMenu, MenuNumber, RCMenu)
        PT.X = RCMenu.Left
        Call ScreenToClient(hWnd, PT)
        Call HiliteMenuItem(hWnd, hMenu, MenuNumber, MF_BYPOSITION Or MF_HILITE)
        Call PopupMenu(Menu:=mnuFile, X:=ScaleX(PT.X, vbPixels, ScaleMode), Y:=0) ' Menu:=YourMenuName
        Call HiliteMenuItem(hWnd, hMenu, MenuNumber, MF_BYPOSITION Or MF_UNHILITE)
    End Sub
    ------------------
    Yonatan
    Teenage Programmer
    E-Mail: [email protected]
    ICQ: 19552879



  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    The problem (or the benefit depending on your point of view) with PopupMenu, is that it pops up where your cursor is. PopupMenu is usually used for "What's This?", context sensitive, type help, where when the user right-clicks an object, that object issues a PopupMenu that displays a "What's This?" menu item. When that menu item is clicked, help for that item is displayed. If you want to know the details of how to do it, email me.

    ------------------
    Marty

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width