?
Solved

How to get menu item string when parent menu is not known

Posted on 2006-06-28
3
Medium Priority
?
313 Views
Last Modified: 2012-06-21
I'm quite new to Visual Basic: I'm writing a genealogy program that creates 27 menus ("A"-"Z" and "Others"), reads names from a text file, and assigns them into one of the above menus based on the first character of the name.

Then what I want to do is get the text of the menu item when one of these names is clicked on and carry on with further processing.

The menus are held in an array of Long ("mnuArray(27)"), but I'm not clear how I can get the "name string" of a clicked item without knowing the parent menu ID. I've looked at GetMenuString and GetMenuItemInfo, but these seem to require to know the parent menu ID. Do I have to go through each of the 27 menus in turn and test whether one of the above functions does NOT give me a NULL result?
Any help would be gratefully received.
0
Comment
Question by:chazzzm
[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
  • 2
3 Comments
 
LVL 3

Expert Comment

by:gafoorgk
ID: 16999504
ur question is not very clear.

if the menu u r talking about is the main menu, u can use GetMenu(<window handle of the form>) to get menu handle, which can be used to retrieve sub menu handles or menu items using the function u mentioned in the question.

try downloading APIViewer and APIGuide, which will provide u with lot of examples for using menu related api functions. they r free.
0
 

Author Comment

by:chazzzm
ID: 16999678
I'm sorry I was not clear.  OK ...

The "top level" menu item (in the main menu bar) is called "Names". (There are only 3 main menu items: "File", Names", and "Help".)  I then set up 27 submenus ("A"-"Z" and "Others") which are accessed as submenus via "Names".

The 27 submenus are declared as mnuArray(27) As Long, and generated automatically soon after startup and appended to the "Names" menu using CreatePopupMenu and AppendMenu respectively.

Then I read the various names from the text file and append each name to the appropriate submenu (e.g. if the name is "Anne Smith" it would go under the "A" menu; if the name was "Zebedee Jones" it would go under the "Z" menu).  This all works fine. But then I need to click on one of the names in the 27 submenus and do further processing by reading more data from another file, based on the name that I have clicked on. But I will have a look at APIViewer and APIGuide and see if they help. I hope my explanation is now a bit clearer, and thank you.
0
 
LVL 3

Accepted Solution

by:
gafoorgk earned 500 total points
ID: 16999788
well, it's lot more clearer now. in fact, i did same kind of app before generating complete menu system taking data from database.

u need to know a bit about subclassing for this. since vb doesn't exposes any of menu items which reveals name of clicked item u need to listen to the events sent by clicked menu item to it's owner window, which is your form holding menu.

menu item sends WM_MENUSELECT or WM_COMMAND notification to it's owner windows on each click. u'll know more on these notifications from msdn. u have to intercept these notifications using a technique called subclassing and get information u need and pass this notification again to where it meant to.

it's not a safe to do subclassing in it's normal way. free libraries for subclassing are available from many sites. but the best one i used is from http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=51403&lngWId=1
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

771 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