A class for API Created Dynamic Menus


For some controls In my current project, I wanted To be able To display a simple context menu using the Right mouse button.

The solution In plain VB uses an existing menu, which must be extended (at runtime Or at design Time). I found this unacceptable.

Searching the web offered the solution of using the API functions CreatePopupMenu(), TrackPopupMenu() And AppendMenu().

I extended the sample To work With a undetermined number of arguments, thus giving Me the flexibility I needed.

The presented Function Popup() assumes the user wants a context menu at the current mouse pointer location. The argument Array consists of menu items Or separators (presented by a Single dash). The user can Select a menu Item by using either the Left Or Right mouse button. The index of the chosen menu Item Is returned, Or zero If cancelled.

A simple usage of the class module could be : (on a list box)


private Sub List1_MouseUp(Button as Integer, Shift as Integer, _
      x as Single, y as Single)
    Dim oMenu as cPopupMenu
    Dim lMenuChosen as Long
'
    If Button = vbRightButton then
        set oMenu = new cPopupMenu
'
' Pass in the desired menu, use '-' for a separator
'
        lMenuChosen = oMenu.Popup("Menu 1", "Menu 2", "Menu 3", _
                "-", "Menu 4")
'
        Debug.print lMenuChosen
    End If
'
End Sub
'
'

Download Zipped Project File and API Menu Class (3k)



Comments

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • The explosion in mobile devices and applications has generated a great deal of interest in APIs. Today's businesses are under increased pressure to make it easy to build apps, supply tools to help developers work more quickly, and deploy operational analytics so they can track users, developers, application performance, and more. Apigee Edge provides comprehensive API delivery tools and both operational and business-level analytics in an integrated platform. It is available as on-premise software or through …

  • This ESG study by Mark Peters evaluated a common industry-standard disk VTl deduplication system (with 15:1 reduction ratio) versus a tape library with LTO-5, drives with full nightly backups, over a five-year period.  The scenarios included replicated systems and offsite tape vaults.  In all circumstances, the TCO for VTL with deduplication ranged from about 2 to 4 times more expensive than the LTO-5 tape library TCO. The paper shares recent ESG research and lots more. 

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds