Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to skip loop 6 62
Best way to parse out a json string in VB6? 10 218
MsgBox 4 68
Problem to line 23 53
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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

808 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