Solved

right click menu in vb6

Posted on 2004-04-04
10
28,711 Views
Last Modified: 2013-12-26
I have a Form at Visual Basic 6.
I want to provide one pop-up menu by right mouse click on the Form.
The options on the menu are 1. Open 2. Close.

If user select Open then show frmUser.frm form as non-modal and if user select close then close that form on which he press right click.


Please, help me how to do this. If possible right me the code.

0
Comment
Question by:syamchandran
10 Comments
 
LVL 11

Accepted Solution

by:
bingie earned 50 total points
ID: 10751716
Using the menu editor, create the menu you would like to see when you right click the form.

i.e.
Top (name = mnuTop)
...Open (name = mnuOpen)
...Close (name = mnuClose)


Paste the following:

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
    Me.PopupMenu mnuTop
End If

End Sub


0
 
LVL 19

Assisted Solution

by:BrianGEFF719
BrianGEFF719 earned 50 total points
ID: 10751719
basically add a form (form2)

make the menu you want on form2. (your popup menu will be the menu on form2)


Form1_Click()
if button = 2 then
 form2.popupmenu (menu name)
end if



simple as that.


-Brian
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10751721
LOL posted at the exact same time :(
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 11

Expert Comment

by:bingie
ID: 10751728
To open the from or close it, use the click event of the menu items

Private Sub mnuClose_Click()
  Unload Me
End Sub

Private Sub mnuOpen_Click()
  Load Form2
  Form2.Show
End Sub
0
 
LVL 5

Expert Comment

by:jerry_jeremiah
ID: 10751782
Make a form that looks like this:

Private Declare Function CreatePopupMenu Lib "user32" () As Long
Private Declare Function DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Private Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hwnd As Long, lprc As Any) As Long

Const TPM_NONOTIFY = &H80
Const TPM_RETURNCMD = &H100

Private Type PointAPI
    x As Long
    y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long

Dim Menu As Long

Private Sub Form_Load()
    Menu = CreatePopupMenu()
    Call AppendMenu(Menu, MF_STRING, 1, "Open")
    Call AppendMenu(Menu, MF_STRING, 2, "Close")
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim ID As Long
    Dim Cursor As PointAPI
    Call GetCursorPos(Cursor)
    ID = TrackPopupMenu(Menu, TPM_NONOTIFY + TPM_RETURNCMD, Cursor.x, Cursor.y, 0, Me.hwnd, 0)
    Select Case ID
    Case 1:
        'MsgBox ("Open")
        Show frmUser
    Case 2:
        'MsgBox ("Close")
        Unload Me
    End Select
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Call DestroyMenu(Menu)
End Sub
0
 
LVL 5

Expert Comment

by:amit1978
ID: 10755339
Hello syamchandran,

To display the menu on mouse right  button is as said in starting message :

* Create the popup menu thru menu wizard and made visible false.

* now my question is  what type of applicatio u r using SDK or MDI
  - if its SDI its is quit simple, u have to create the menu on the same form and display them on click of mouse button down if "Button" value of mouse button down is 2 (mean right mouse button down) thru function me.PopupMenu passing parent menu name.

  - if its MDI its not difficult but u have to do some code..... create the menu on mdi form and on mouse down of active form in MDI u have to do the things like in SDI but click button as its call menu click event of MDI Form. In Open menu click u have to call <MDIFormName>.ActiveForm.Open and define public open function in every form where u want to diaplay menu. And perform the required function in Open function.

visible off the menu is not compulsory.....its depend on ur requirement.

Amit Jain
<email removed by Bingie EE Page Editor>
0
 
LVL 5

Expert Comment

by:Pi7
ID: 10774833
Or after creating the menu (called mnuName with submenus Open and Close) at design time, set its visible property to false to hide the menu.you can then use Me.PopUpMenu mnuName to display the popup menu
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel VBA combine two working workbooks 8 54
Reading the Contents of a Directory In Access VBA 5 70
MS Date Picker 64 bit 32 bit issue 12 53
Visual Studio 2005 text editor 10 38
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question