Menus (WinAPI and Handles)

I have such situation..
I need to access other application's menu from my program.. get an entire list of it's items, rebuild the menu in tree, and then modify the other application menu's item's text..
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try the APIs GetMenu, GetMenuItemCount, GetMenuItemInfo and SetMenuItemInfo.

I don't know, though, whether these APIs work for menus of other applications. You'll have to try that. If that doesn't work, you'll have to put it all into a little DLL and load it into the other applications (e.g. by calling SetWindowsHookEx). This would be quite complicated stuff...

Regards, Madshi.
Using the winAPI this is not too dificult here are the steps:

1) get a window handle for the other application.  
2) get the handle for the menu of the window handle you just got.
3) modify the menu items

If you want code for these three steps just let me know.
pbibergalAuthor Commented:
to Calvinrsmith: what is the code for modifying items?
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Use ModifyMenu.  here are the paramaters:

hmenu - the handle to the menu
uposition - what item you want to change
uflags - use MF_STRING for a text menu
uidnewitem - the id for the new menu
lpnewtiem - if a text menu then this is a null-terminated string.

Also don't forget to call DrawMenuBar after you make the change!
pbibergalAuthor Commented:
to Calvinrsmith..
i need a code to fullscan the menu and create a copy in treeview.. how to do it?
OK I'll give complete code.  but first what do you mean by treeview?
pbibergalAuthor Commented:
to Calvintsmith:
treeview = TTreeview object placed in win32 page of component pallete..

I don't have my copy of delphi with me right now so here is complete code as far as my memory goes:

   HWND thewindow;
   HEMNU themenu;
   HMENU thesubmenu;
   MenuItemInfo mii;
   // menu text will go here use
   // a size big enough for longest
   // menu item
   PChar themenutext[100];
   boolean (or is it bool?) done;
   integer i;

// Find the window handle of the other
// application
thewindow := findwindow("class name","window name");

// Find the handle for the menu
themenu := GetMenu(thewindow);
// get what sub menu ie. file, edit...
// the zero is for first menu
// 1 would be for edit etc...
thesubmenu := GetSubMenu(themenu,0);

// loop through each item in the menu
done := false;
i := 0;
while not done do
// scan the menu
mii.cbsize := sizeof(MenuItemInfo);
mii.fmask := MIIM_STRING;
mii.dwTypeData := themenutext;
mii.cch := 100;
if(GetMenuItemInfo(thesubmenu,i,true,mii) = false)
   done := true;
// next time though the loop get
// next item.
i := i + 1;
// now themenutext contains the text
// of the first item in the file menu
// so place it into the treeview control
// i'm guessing you know how to do this

// that's all!!!

This is the basic idea.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.