I want to add submenu in Main Menu bar in my MFC app
It has a design as follows,
Main Menu
Menu Item1
Menu Item2
SubMenuItem1
SubMenuItem2
SubMenuItem3
Menu Item3
The sub Menu of Menu item3 must be added progrmatically. How to do it?
There's a fairly comprehensive example of how to create MFC menus dynamically here. As you'll see it's quite involved.
Alternatively you add the item at design time, but hide it, revealing it and assigning function pointers for click events at runtime as required.
Related
I have a menu and it has a number of menu items. Usually when menu is clicked it expands. But in some situations when the menu is clicked its action need to be fired but menu should not be expanded. How can we do this in qt?
I would like to add sub options to the Main Menu at the top of a main frame window in MFC.
For example; File>Open, or Edit>Undo.
Is this possible to do at all? My intention is to replace the function of some buttons in my program with options typically found in the drop down menus
Also after adding an item to the Main Menu how would you use it to call a function?
Here I have added an entry to the View menu called Test:
When I build and runt he program it shows disabled:
This is because I still have to create an event handler. In the resource editor you right-click the menu item and select Add Event handler:
This brings up the class wizard:
On the dialogue there are a couple of menu event handlers to choose from. Select the one you need (as in the screen shot) but don't forget to choose the right class on the right. Then click Add and Edit.
Now you can add your event handler functionality. Example:
void CMainFrame::OnViewTest()
{
AfxMessageBox(_T("Hello!"), MB_OK | MB_ICONINFORMATION);
}
When I compile and run this:
Hopefully this will help you get up and running.
I'm working in windev and I made a dynamic Menu using the menu control from information in my anylisis, now I'm trying to achieve the same using buttons in a ribbon, or just buttons but got stuck when creating the submenus for these buttons.
In the description of a button you can attach a menu to it. You can always edit the menu dynamically. Is it what you're looking for ?
Attach a menu to a button
I am Making an Application which will make a dialog as system tray icon after some button press. it is working fine but also i need to open the menu same as dialog contains on Right Click and have written following Code:
CMenu pMenu;
pMenu.LoadMenu(IDR_MENU1);
POINT pointCursor;
::GetCursorPos( &pointCursor );
pMenu.TrackPopupMenu(TPM_BOTTOMALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON, pointCursor.x, pointCursor.y, this);
It is Creating the menu but the width of the menu is very thin as shown following:(Yellow highlighted area is menu)
if I add only first submenu of main menu then it works well as following code:
CMenu *pMenu = GetMenu();
POINT pointCursor;
CMenu *pMenu = GetMenu();
::GetCursorPos( &pointCursor );
pMenu->GetSubMenu(0)->TrackPopupMenu(TPM_BOTTOMALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON,pointCursor.x,pointCursor.y,this);
On applying this code i get following output
Actually I need the Following menu:
Kindly Suggest Where i am doing it wrong
TrackPopupMenu cannot display the menu bar as part of it's work. The menu bar itself is not displayed because TrackPopupMenu requires a handle to a menu, submenu, or shortcut menu. So, given that, if you really want the same menu structure including the menu bar you've shown, you'll need to create that structure dynamically using CMenu methods. Or, simply create a new menu resource with a different name that includes the menu bar items as submenus.
In MFC featurepack i create a standard menu and set the ID of sub menu to the same command of toolbar button to take that button's image that toolbar is the one sent to this method
CMFCToolBar::AddToolBarForImageCollection
and also I use the
GetContextMenuManager()->AddMenu(L"Mymenu", IDR_ContextMenu1);
in the application and
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_ContextMenu1,rect.left,rect.top,button);
in the show menu event
I need to know how to add a menu item with a specified icon at the run-time dynamically
See the documentation about OnInitMenuPopup of your CMainFrame.