Solved

right click menu in vb6

Posted on 2004-04-04
10
28,976 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 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
Industry Leaders: 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

739 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