Solved

right click menu in vb6

Posted on 2004-04-04
10
28,521 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now