n Level deep submenu copy into a Array.....

I would like to make an Array similar to the n-level deep CMenu.

Can anyone suggest me a method to read all the possible sub menus and store them in a array with the same kind of hirearchy the Menu has.

LVL 1
nv3prasadAsked:
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.

Vinayak KumbarSr Program ManagerCommented:
HI,

CMenu menu;
      menu.LoadMenu(IDR_MAINFRAME);

      int ItemCount = menu.GetMenuItemCount();

      for(int Index = 0; Index < ItemCount; Index++)
      {
            CString MenuString;
            CMenu *subMenu = menu.GetSubMenu(Index);
            menu.GetMenuString(Index, MenuString, MF_BYPOSITION);
            AfxMessageBox("Into " + MenuString);
            for(int SubIndex = 0; SubIndex < subMenu->GetMenuItemCount(); SubIndex++)
            {                  
                  int ID = subMenu->GetMenuItemID(SubIndex);
                  subMenu->GetMenuString(ID, MenuString, MF_BYCOMMAND);
                  if(MenuString.IsEmpty())
                        MenuString = "SEPERATOR";
                  AfxMessageBox(MenuString);
            }
      }

This one will give U the required result. It lists all the menu items starting from the main menu item. The top menu items will be displayed by the identifier say "into File" like that. The seperator will be by SEPERATOR. Only thing is u have to store them into a array. may be U can use the CStringArray or a linked list for it. If U want I can give U that code.

Hope this helps.
VinExpert
0

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
nv3prasadAuthor Commented:
It was a nice and simple solution. I apprecitae it. I never thought that getsubmenu will go n level deep.

0
ZoppoCommented:
Hi nv3prasad,

to VinExpert: nv3prasad asks for a solution for n-level menu, so he'll need a recursive solution like this:

--------------------------------------------------------------------------------------------------------
void
CMainFrame::ReadMenus()
{
 CMenu* pMenu = GetMenu();
 ReadMenu( pMenu );
}

void
CMainFrame::ReadMenu( CMenu* pMenu )
{
 static int deep = 1; // just a counter to make the TRACE look fine
 deep++;
 UINT i, num = pMenu->GetMenuItemCount();
 CMenu* pSubMenu;
 CString item;
 for ( i = 0; i < num; i++ )
 {
  pSubMenu = pMenu->GetSubMenu( i );
  if ( pMenu->GetMenuItemID( i ) == 0 )
   item = "------------------------";// Seperator
  else
   pMenu->GetMenuString( i, item, MF_BYPOSITION);
  TRACE( "%*s%s\n", deep, "|-", item );
  if ( pSubMenu )
   ReadMenu( pSubMenu ); // recurse into popup menu
 }
 deep--;
}


hope that helps,

ZOPPO
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

ZoppoCommented:
>I never thought that getsubmenu will go n level deep.
it does not

> It was a nice and simple solution. I apprecitae it.
for n<=2
0
nv3prasadAuthor Commented:
To VinExpert,

Zoppo is exactly right, your solution only works for one level and not a recursive solution but never mind you gave me a start on it.

HiZoppo,

I think you deserve the points and so just let me know what I have to do so that you get them?

My E-mail: pnarahar@hotmail.com

Thank you both
0
Vinayak KumbarSr Program ManagerCommented:
Yes I agree.

VinExpert
0
ZoppoCommented:
Hi nv3prasad,

if you want to give me points you'll have to post a new question like 'Points for Zoppo'...

ZOPPO
0
ZoppoCommented:
But, I think it would be rather fair if VinExpert would offer me 20 points, because I had to pay 20 points to see the comments for this question after you accepted it     :o]
0
Vinayak KumbarSr Program ManagerCommented:
Hi Zoppo,

:-)
:-)
:-)

Why me?

VinExpert

0
ZoppoCommented:
Because you earned the 20 points I had to pay when I opened the question.
Further you agree that your answer wasn't the correct one but you got the point.
Even more I don't think that nv3prasad should have to pay points twice for one question.

Just some thoughts            :)


ZOPPO
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

But How come?. I suggested an answer and prasad accepted, so I got the points. And U saw it so U paid 20 points. But before seeing U knew that U will loosing some points. Is it right?.....

NoNo, I was just joking. If prasad feels that he should give U points, then he will give U.

VinExpert
0
nv3prasadAuthor Commented:
Dear Zoppo,

I appreciate your answer and I will give you whatever points you want me to, just let me know how I have to transfer you the points.

nv3prasad
0
ZoppoCommented:
Hi nv3prasad,

if you want to give me points you'll have to post a new question like 'Points for Zoppo' with the points offered you want to give ...

I don't mind how much points I get, just do what you mean it's worth...

ZOPPO
0
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
System Programming

From novice to tech pro — start learning today.