Link to home
Start Free TrialLog in
Avatar of John500
John500Flag for United States of America

asked on

How To Insert An Executeable In An MFC Application Menu Item

Greetings,

I want to insert an executable in my application as a submenu item from the main menu bar.  What code is necessary to do this?

This is what I know so far:

In the 'Docked Window' under the 'Rescource' tab and the subfolder marked 'Menu' are two IDR objects.  One is the default IDR_MAINFRAME, the other is the IDR_PROJECTNAME.

If the project IDR is selected, the current available menu items are displayed in the workspace.  From here on, I need help.  What steps make it possible to launch an exe from the menu item I select?

I'm guessing that I should select the menu item in which the exe should appear as a submenu item.  Then, from that dropdown list, select the blank box listed as the last submenu item, choose properties, select an 'ID:' from the dropdown box, type in a caption in the Caption Box.  Even if I'm correct in these steps, I'm sure some code needs to be inserted somewhere.

This is where I need help, can you help me with these steps?  

Thanks!




 

ASKER CERTIFIED SOLUTION
Avatar of lif081199
lif081199

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

For example about ShellExecute, here is how to launch the windows calc.exe :

HWND ParentWindow = NULL;
char *FileName = "c:\\windows\\calc.exe";
ShellExecute(ParentWindow,"open",FileName,NULL,NULL,SW_SHOWNORMAL);

Bye,
Lionel.
Avatar of John500

ASKER

Lionel,

Thanks for the response.  I have 'zilch' MFC experience.  This task will be my first introduction to Windows/MFC programming.

Up until now, I've had two courses in data structures and one operating systems course which got my feet wet to programming, but that's it.

Some of the terms you mentioned left me in the dust.

Starting from:

"Create in your frame a member function to handle the menu message from this item."

Can you define 'frame' or how I access it?  Does this have anything to do with the ClassWizard, or can I access the 'frame' using the ClassWizard?  I can see from within the ClassWizard that a block of empty space/code has already been allotted for this menu item and it looks like this:

void CProjectHelpMenu::OnProjecthelp()
{
      // Call Help file
      ShellExecute("Projecthelp.hlp", SW_SHOW);

}

I think the above code satisfies the portion you define as:

// in the .CPP"

But I still have questions.  Should the full file path of 'Projecthelp.hlp' be displayed like "C:\Help\ProjectHelp.hlp", SW_SHOW)

How do I access the .h file you mentioned to perform the following:

// in the .H of your frame
afx_msg void OnMyMenuSelected();

After I knock that out, I'll just need help on assigning my function to the menu item message.

Thanks!


In a MFC non Dialog-box based application, the main window is called a Frame window. In a MDI application, a child window is called a Child Frame.

The class of a frame is CFrameWnd, which herits from the classical CWnd.

The wizard create a CMainFrame class for you, which herits from a CFrameWnd.

You can of course use the wizard to add this function.

BUT It seems that the wizard has already add the function to your project. So, you just have to add the ShellExecute function, as you mentionned it.


For the ShellExecute function, if the "slave" application is with you own app (in the same dir, for example), you don't need to give the full path. Only "slave.exe" is needed.

To access to the .H file, just double-clic on the name of the CMainFrame class, in the Project window of Visual Studio (the tree on the left of your screen)

This will open the .H.
Just ask for more details. You can also send me your code (only .CPP and .H files !!!!) here : lfumery@nordnet.fr
in order I see exactly your situation.

Good luck !
Lionel.
Avatar of John500

ASKER

Thanks, that did the trick