• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

Dynamicaly Execute a menu Item.

I want to create a menu item dynamicaly and assign code to execute a report file (.rpt) under this menu item. So that if user click on that menu it will execute that report file. For any further clarification please leave comments.
Thanks in advance
0
majorjohn
Asked:
majorjohn
  • 4
  • 3
1 Solution
 
lif081199Commented:
Step 1 - Adding dynamicaly to the menu.

CWnd *P            = GetParentFrame();
CMenu *M      = NULL;
CMenu *SM      = NULL;

M = GetMenu();
if (P)      M      = P->GetMenu(); // Main menu of your frame or wnd.
if (M)      SM      = M->GetSubMenu(2); // The Submenu in which you want to add an item
if (SM)
{
SM->AppendMenu(MF_STRING, 6001+NbDynamicalyAddedMenus,"String of the menu");
}

the 6001+NbDynamicalyAddedMenus value is needed to give to the new item an unique ID value.

Step2 : Process the message.

In the message map of you wnd/frame, add this :

BEGIN_MESSAGE_MAP(CMyView, CView)
   ...
   ON_COMMAND_RANGE(6000, 7999, OnProcessDynamicMenu)
   ...
END_MESSAGE_MAP()

Add to your frame/wnd the member function :
// declaration in .H
afx_msg void OnProcessDynamicMenu(UINT MenuID);

And the write the function :

void CMyView::OnProcessDynamicMenu(UINT MenuID)
{
    // Do something, for example retrieve the menu name :
CWnd *P            = GetParentFrame();
CMenu *M      = NULL;
CMenu *SM      = NULL;
CString Name;

M = GetMenu();
if (P)      M      = P->GetMenu();
if (M)      SM      = M->GetSubMenu(2);
if (SM)
{
SM->GetMenuString(MenuID, Name, MF_BYCOMMAND);
SM->CheckMenuItem(MenuID, MF_CHECKED|MF_BYCOMMAND);
}

Good luck,
Lionel.
0
 
majorjohnAuthor Commented:
Thanks for ur answer. Exactly correct for dynamicaly creating menu and Catch hold of it. Now my only query is how do I assign Report File(.RPT) execution code to the related ID.
0
 
lif081199Commented:
-Within the OnProcessDynamicMenu, you know the name of the menu item selected (read above, the lne with SM->GetMenuString(...))

-From this menu item name, find the file name of your RPT file. (just a concatenation, I guess ?)

-Use the ShellExecute function to read it.

Lionel.
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
majorjohnAuthor Commented:
Your answer is to the point. I will check and award you positively.

Thanks for reply.
0
 
lif081199Commented:
ok ok
Lionel.
0
 
majorjohnAuthor Commented:
Can u leave ur email no. So to contact u later for any further query.
0
 
lif081199Commented:
you can join me here :

lfumery@nordnet.fr
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now