Solved

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

Posted on 2006-06-28
3
299 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
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 125 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

863 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