Solved

VBA Popup menu???

Posted on 2002-04-11
20
1,100 Views
Last Modified: 2012-05-05
I am using VBA and need to be able to right-click on a form and popup a menu of options. In VB they have the menu editor; however I don't see this in VBA. From what I read, it appears it has to be done programmatically through VBA. If someone knows of how to do this this way or another would you please send me sample code of how to do it? For the record: I'm using VBA inside Esri ArcView 8.1.2 ArcMap. Thanks,

Wayne
0
Comment
Question by:guidway
20 Comments
 
LVL 20

Expert Comment

by:hes
ID: 6934571
0
 
LVL 12

Author Comment

by:guidway
ID: 6934583
thanks for trying, but I just tested it and I don't have the same objects and libraries they do because that is Word and this is ArcMap. VBA is implemented very differently in both. Thanks anyway,

guidway
0
 
LVL 4

Expert Comment

by:RichW
ID: 6934660
http://www.planet-source-code.com/xq/ASP/txtCodeId.14792/lngWId.1/qx/vb/scripts/ShowCode.htm

This zip file has two class module and a regular bas module and a form.  You can use them in VBA.

The module has examples of how to use.

I used this in Excel 97 and VB 6.
RichW
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6934879
0
 
LVL 12

Author Comment

by:guidway
ID: 6935134
Hey fellows,

Thanks for the responses, both of your code work excellent up to a certain point. Now here is my next question (maybe it is already in the code and I'm overlooking it or something.) How would I detect if one of the menu items was checked? Here is what I want to do. Maybe ya'll can give me some more help. I want to right click on a VBA form and pop up a menu that has one value: a checkbox with the phrase "Always on top" that allows the user (when clicked with a check) to make the form stay on top at all times. Else it will be as a normal window. (Same as the Windows NT Task Manager window when you right click on it). Can you show me with one of your code selections (either one) how to do this? Thanks,

guidway
0
 
LVL 12

Author Comment

by:guidway
ID: 6935138
Correction: Same as the Windows NT Task Manager Icon in the taskbar when you right click on it. Sorry,

guidway
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6935287
What do you mean by both?
0
 
LVL 12

Author Comment

by:guidway
ID: 6936624
Meaning that your code and RichW worked as far as showing a menu bar but I don't see how to programmatically check to see if it is checked or unchecked so I can place the window on top or as a normal window. Any clearer now?

guidway
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6936803
I got you!
but... that was not part of primary question :D
I will do a try, anyway...
0
 
LVL 12

Author Comment

by:guidway
ID: 6936855
Richie_Simonetti,

Thanks! You are right about that not being in the primary question. I should have put it. Since it wasn't though (which was my fault) I'm not going to cheat you or RichW out of the points. I'll split it between ya'll even if no one figures out the next thing I asked. I was just wandering if someone knew how to do what I wanted. I can post it as another question if ya'll would like. As long as I get the answer I don't care. ;-) Thanks again,

guidway
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 16

Expert Comment

by:Richie_Simonetti
ID: 6937521
well, at this very moment i can only start the menu checked/not checked and i cannot toggle it but i am trying...
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6937532
Well, to module add a boolean variable:
public FlagChecked as boolean and set it default to false (Just for sure)

In the click event, change the code where you set mii.fState with this

' This item is currently enabled and is the default item.
        If FlagChecked = False Then
            .fState = MFS_ENABLED Or MFS_DEFAULT
            FlagChecked = True
        Else
            .fState = MFS_ENABLED Or MFS_DEFAULT Or M_CHECKED
            FlagChecked = False
        End If

cheers
0
 
LVL 12

Author Comment

by:guidway
ID: 6937534
Thanks, I appreciate you trying. I have been playing with it too for most of today, but not really getting anywhere with it. thanks again,

guidway
0
 
LVL 12

Author Comment

by:guidway
ID: 6937543
I'm trying your code now...

guidway
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 75 total points
ID: 6937600
Sorry, sorry very sorry. It has a little bug:

Change that code to THIS one:
' This item is currently enabled and is the default item.
        If FlagChecked = False Then
            .fState = MFS_ENABLED Or MFS_DEFAULT
        Else
            .fState = MFS_ENABLED Or MFS_DEFAULT Or M_CHECKED
        End If

and in the windowproc fucntion,add the following:
......
......
......
Case ID_ABOUT
            ' Use the VB MsgBox function to display a short message in a dialog
            ' box.  Using the API isn't necessary.
            retval = MsgBox("This example demonstrates how to use the API to " & _
                "display a pop-up menu.", vbOKOnly Or vbInformation, _
                "Windows API Guide")
               FlagChecked = Not FlagChecked    ' this is new code
....
....
....
0
 
LVL 12

Author Comment

by:guidway
ID: 6937652
Excellent! That did it. Thanks. It works very well. Here is what I will do. For Richie_Simonetti I'm giving 75 points total for helping me with this last part and since RichW's code did work (for the question I originally asked anyway) I'm giving you 50 points. RichW, The link to collect your points will be sent on the next comment.

Thanks again for everything!

guidway
0
 
LVL 12

Author Comment

by:guidway
ID: 6937661
RichW,

Here is the link to your points:

http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=visualbasic&qid=20288187

Thanks again,

guidway
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6937688
Thanks for "A" grade!
Then, i can think that it works, can i?
0
 
LVL 12

Author Comment

by:guidway
ID: 6937695
It works for me. :-D
guidway
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6992226
Cool!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

762 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

18 Experts available now in Live!

Get 1:1 Help Now