?
Solved

PopupMenu on a modal form doesnt work

Posted on 2000-03-31
8
Medium Priority
?
540 Views
Last Modified: 2012-06-21
i am developing a SDI application using a lot the PopupMenu method and i notice that on the main form it works very well but when another form is called modally the popupmenu method is executed but nothing happens, i changed the call of this second form for not modally and everything worked so good.
For test just create an module and two form, set start to a sub main, call the form1.show [vbModal] on the sub Main and create something for call the popupmenu method, call form2.show and do something with popupmenu. Now change the call of form2 to vbmodal and watch what happens.
Does anyone know why it is like this???
0
Comment
Question by:Feres
[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
8 Comments
 
LVL 6

Accepted Solution

by:
VBGuru earned 200 total points
ID: 2673060
From the help

When you display a pop-up menu, the code following the call to the PopupMenu method isn't executed until the user either chooses a command from the menu (in which case the code for that command's Click event is executed before the code following the PopupMenu statement) or cancels the menu. In addition, only one pop-up menu can be displayed at a time; therefore, calls to this method are ignored if a pop-up menu is already displayed or if a pull-down menu is open.

When a call is made to popupmenu and by selecting an option from it and that option if it opens a modal form. then the call to the popupmenu doesn't work.


Alternative is the use of APIs to create the popupo menus

Here is an example


Const MF_CHECKED = &H8&
Const MF_APPEND = &H100&
Const TPM_LEFTALIGN = &H0&
Const MF_DISABLED = &H2&
Const MF_GRAYED = &H1&
Const MF_SEPARATOR = &H800&
Const MF_STRING = &H0&
Private Type POINTAPI
    x As Long
    y As Long
End Type
Private Declare Function CreatePopupMenu Lib "user32" () 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, ByVal lprc As Any) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert 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 DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Dim hMenu As Long
Private Sub Form_Load()
    'Create an empty popupmenu
    hMenu = CreatePopupMenu()
    'Append a few menu items
    AppendMenu hMenu, MF_STRING, ByVal 0&, "Hello !"
    AppendMenu hMenu, MF_GRAYED Or MF_DISABLED, ByVal 0&, "Testing ..."
    AppendMenu hMenu, MF_SEPARATOR, ByVal 0&, ByVal 0&
    AppendMenu hMenu, MF_CHECKED, ByVal 0&, "TrackPopupMenu"
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim Pt As POINTAPI
    'Get the position of the mouse cursor
    GetCursorPos Pt
    If Button = 1 Then
        'Show our popupmenu
        TrackPopupMenu hMenu, TPM_LEFTALIGN, Pt.x, Pt.y, 0, Me.hwnd, ByVal 0&
    Else
        'Show our form's default popup menu
        TrackPopupMenu GetSystemMenu(Me.hwnd, False), TPM_LEFTALIGN, Pt.x, Pt.y, 0, Me.hwnd, ByVal 0&
    End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
    'Destroy our menu
    DestroyMenu hMenu
End Sub

0
 
LVL 6

Expert Comment

by:VBGuru
ID: 2673063
even I faced that problem in my project
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2673064
I'm showing popupmenus on modal forms without problems. Must be something else.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:bpoff
ID: 2673084
This is a known bug.  You can find a work-around from MS at:

http://support.microsoft.com/support/kb/articles/Q167/8/39.asp
0
 
LVL 6

Expert Comment

by:VBGuru
ID: 2673085
from the form1s popup menu option open a form2, then in form2 try to execute the popupmenu command.

In form1

Form_Click
popupMenu mnuFile
End Sub

mnuForm2_Click

form2.show vbModal

End sub

In form2

form_Click
popupmenu mnuForm2sfile
end sub


Here the form2's popupmenu doesn't come.
0
 

Author Comment

by:Feres
ID: 2673115
that's exactly what i wanted to know, thanks a lot VBGuru.
just one ask:
where is this 'From the help', isn't at msdn help, right? if so, you just made me feel like a child, cause i didn´t find it.
0
 
LVL 6

Expert Comment

by:VBGuru
ID: 2673147
its in a vb5 help as remarks section

PopupMenu Method

See Also         Example         Applies To         Specifics



Displays a pop-up menu on an MDIForm or Form object at the current mouse location or at specified coordinates. Doesn't support named arguments.

Syntax

object.PopupMenu menuname, flags, x, y, boldcommand



The PopupMenu method syntax has these parts:

Part      Description

object      Optional. An object expression that evaluates to an object in the Applies To list. If object is omitted, the form with the focus is assumed to be object.
Menuname      Required. The name of the pop-up menu to be displayed. The specified menu must have at least one submenu.
Flags      Optional. A value or constant that specifies the location and behavior of a pop-up menu, as described in Settings.
X      Optional. Specifies the x-coordinate where the pop-up menu is displayed. If omitted, the mouse coordinate is used.
Y      Optional. Specifies the y-coordinate where the pop-up menu is displayed. If omitted, the mouse coordinate is used.
boldcommand      Optional. Specifies the name of a menu control in the pop-up menu to display its caption in bold text. If omitted, no controls in the pop-up menu appear in bold.


Settings

The settings for flags are:

Constant (location)      Value      Description

vbPopupMenuLeftAlign      0      (Default) The left side of the pop-up menu is located at x.
vbPopupMenuCenterAlign      4      The pop-up menu is centered at x.
vbPopupMenuRightAlign      8      The right side of the pop-up menu is located at x.


Constant (behavior)      Value      Description

vbPopupMenuLeftButton      0      (Default) An item on the pop-up menu reacts to a mouse click only when you use the left mouse button.
vbPopupMenuRightButton      2      An item on the pop-up menu reacts to a mouse click when you use either the right or the left mouse button.


Note   The flags parameter has no effect on applications running under Microsoft Windows version 3.0 or earlier. To specify two flags, combine one constant from each group using the Or operator.



Remarks

These constants are listed in the Visual Basic (VB) object library in the Object Browser.
You specify the unit of measure for the x and y coordinates using the ScaleMode property. The x and y coordinates define where the pop-up is displayed relative to the specified form. If the x and y coordinates aren't included, the pop-up menu is displayed at the current location of the mouse pointer.
When you display a pop-up menu, the code following the call to the PopupMenu method isn't executed until the user either chooses a command from the menu (in which case the code for that command's Click event is executed before the code following the PopupMenu statement) or cancels the menu. In addition, only one pop-up menu can be displayed at a time; therefore, calls to this method are ignored if a pop-up menu is already displayed or if a pull-down menu is open.

0
 

Author Comment

by:Feres
ID: 2676050
hi, vbguru
just something i couldnt realize:
how do i write code for the menu i created dynamic??
have u tried using the menu of the form to be displayed on popup (i used getmenu, getsubmenu, TrackPopupMenu) but it only works when the menu is set to visible.
thanks
0

Featured Post

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!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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

800 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