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

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

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
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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