?
Solved

right click menu in vb6

Posted on 2004-04-04
10
Medium Priority
?
29,241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 11

Accepted Solution

by:
bingie earned 200 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 200 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

765 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