Solved

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

Posted on 2006-06-28
3
297 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
  • 2
3 Comments
 
LVL 3

Expert Comment

by:gafoorgk
Comment Utility
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
Comment Utility
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 125 total points
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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

12 Experts available now in Live!

Get 1:1 Help Now