[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

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

Posted on 2000-02-08
13
Medium Priority
?
268 Views
Last Modified: 2013-11-20
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.

0
Comment
Question by:nv3prasad
  • 6
  • 4
  • 3
13 Comments
 
LVL 8

Accepted Solution

by:
Vinayak Kumbar earned 800 total points
ID: 2502741
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
 
LVL 1

Author Comment

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

0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2504161
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 31

Expert Comment

by:Zoppo
ID: 2504169
>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
 
LVL 1

Author Comment

by:nv3prasad
ID: 2505042
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
 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 2506425
Yes I agree.

VinExpert
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2506894
Hi nv3prasad,

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

ZOPPO
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2506900
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
 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 2507077
Hi Zoppo,

:-)
:-)
:-)

Why me?

VinExpert

0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2507088
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
 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 2507115
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
 
LVL 1

Author Comment

by:nv3prasad
ID: 2510319
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
 
LVL 31

Expert Comment

by:Zoppo
ID: 2510673
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

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Suggested Courses

608 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