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

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

Most Popular Programming Stories

More for Developers

RSS Feeds