How can i implement the dynamic menus in MFC plz give the
code

Answers were Sorted based on User's Feedback



How can i implement the dynamic menus in MFC plz give the code..

Answer / surendra mishra

Create a CMenu object on the stack frame as a local, then
call CMenu’s member functions to manipulate the new menu as
needed. Use the following function to create the same
1. LoadMenu,SetMenu or TrackPopupMenu function

Is This Answer Correct ?    6 Yes 0 No

How can i implement the dynamic menus in MFC plz give the code..

Answer / igor polivanyi

The code would look like this:

BEGIN_MESSAGE_MAP(CSomeCtrl, COleControl)
//{{AFX_MSG_MAP(CSomeCtrl)
//}}AFX_MSG_MAP
ON_COMMAND(IDM_MENU_ITEM, OnPopupMenuItem)
END_MESSAGE_MAP()

LRESULT CSomeCtrl::OnPopupMenuItem(WORD wNotifyCode, WORD
wID, HWND hWndCtl, BOOL& bHandled)
{
// Implementation of the menu command handler...
return S_OK;
}


{
// Dynamic creation...
CMenu mnuZoomOutPopUp;
mnuZoomOutPopUp.CreatePopupMenu();

CString strMenuItem;
strMenuItem.LoadString(IDM_MENU_ITEM);
mnuZoomOutPopUp.AppendMenu( MF_STRING | MF_ENABLED,
IDM_MENU_ITEM, strMenuItem );
mnuZoomOutPopUp.AppendMenu( MF_SEPARATOR, 0, "" );
// nLeftPos, nTopPos -- screen coordinates of pop-up menu
placement ...
mnuZoomOutPopUp.TrackPopupMenu( TPM_LEFTALIGN, nLeftPos,
nTopPos, this );
mnuZoomOutPopUp.DestroyMenu();
}

Is This Answer Correct ?    3 Yes 1 No

Post New Answer

More MFC Interview Questions

What?s the difference between Modal and Modeless Dialog?

12 Answers   Jekson, Usl India,


I want recent paper pattern for HP company?

0 Answers   HP,


What is the difference between OnInitialUpdate and OnUpdate?

5 Answers  


Tell me the different controls in MFC ?

5 Answers  


is there any class which is not derived from Cobject

11 Answers   Patni,






How to update all the views whenver document got updated ?

1 Answers  


1)how to Display the File Dialog Box, in MFC ?

1 Answers  


Tell us something about MFC?

7 Answers   Microsoft,


what is message loop how mfc does it internally?

4 Answers   Aspire,


Does the application have more than one object? If no, then what is the reason?

5 Answers  


1)To Remove WS_MINIMIZEBOX in a Frame ?

1 Answers  


Will there be any difference in the image buffer size if it is loaded in from CString to LPTSTR using GetBuffer()? lptstr = string.GetBuffer(0);

2 Answers  


Categories