Link to home
Start Free TrialLog in
Avatar of nv3prasad
nv3prasad

asked on

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.

ASKER CERTIFIED SOLUTION
Avatar of Vinayak Kumbar
Vinayak Kumbar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nv3prasad
nv3prasad

ASKER

It was a nice and simple solution. I apprecitae it. I never thought that getsubmenu will go n level deep.

Avatar of Zoppo
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
>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
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
Yes I agree.

VinExpert
Hi nv3prasad,

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

ZOPPO
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]
Hi Zoppo,

:-)
:-)
:-)

Why me?

VinExpert

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
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
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
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