Solved

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

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

690 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