I'm sorry ,I missed one line code .
"Joseph M. Newcomer" <newcomer@flounder.com>
See below...
On Tue, 13 Feb 2007 17:55:37 +0800, "zhang" <makefriend8@163.com> wrote:
what your said is right if all coding is written by me.
no matter the code written by your ways or by my ways,It works very well
in
a simple MDI.
but I found my programe used a class
class AFX_EXT_CLASS CXPMenu : public CMenu
of course,I do not find any code about that in CMainFrame
****
Not sure why any code for CXPMenu would be in CMainFrame; they're
different classes and
completely unrelated. I don't know what a CXPMenu is, but without that
knowledge it is
hard to tell what is going on.
*****
what I really puzzled is:
why m_Menu.ModifyMenu(1,MF_BYPOSITION,0,view);
m_Menu.ModifyMenu(ID_FILE_OPEN,MF_BYCOMMAND,ID_FILE_OPEN,file_open.);
works ok. (all have the same position to the menu in the resources)
*****
Generally, you can assume that using MF_BYPOSITION with a compile-time
constant is going
to eventually do the wrong thing, and such a practice should be avoided.
If you need to
use MF_BYPOSITION, you should only do this if you have computed the
position in the lines
immediately preceding the usage of the index, and the index will not be a
compile-time
constant.
What is the second modification doing? What is file_open? Do not give
examples with
variable names where we are supposed to guess what the variable name
represents.
*****
but a popup menu modified can not have the same position to the menu in
the
resources
****
Not sure what this means.
****
if I delete following code and modified int the resources, all is ok.but I
need to change it .!!and when I added following codes ,the the menu's
position can not be correctly typed......................................I
want to know how can I dynamic loading a popup menu and do not destroy the
other part of the coding .
CMenu* pSubMenu;
pSubMenu = m_Menu.GetSubMenu(0);
pSubMenu->ModifyMenu(3,MF_BYPOSITION,0,file_delete);
****
I don't know what you mean by "cannot be correctly typed". Also, what I
showed in the
code below was how to dynamically load a popup menu; I'm not sure what is
being destroyed
here.
****
"Joseph M. Newcomer" <newcomer@flounder.com>
??????:mvqus2197skmsurpibss9gdhfetccl5qe2@4ax.com...
First, why are you not just modifying the menu in the resources?
Second, is this a dialog-based, SDI or MDI app? In MDI, it probably
won't
work because
the menus are reloaded dynamically.
So I'm presuming that you start out with a menu that has the appearance
File View Tools
[Open...]
[Save as...]
[Delete]
----
[Exit]
where Delete is a "placeholder" item, e.g., it looks initially like an
ordinary menu item.
So what I'd do is a piece of code like this (and this actually works; I
tried it). This
is called once from the OnInitDialog handler of a dialog-based app with
a
menu)
void Cst2Dlg::SetDeleteMenu()
{
CMenu * menu = GetMenu();
UINT state = menu->GetMenuState(ID_FILE_DELETE, MF_BYCOMMAND);
if(state == ~0)
return; // already set or some error occurred
CString text;
menu->GetMenuStringW(ID_FILE_DELETE, text, MF_BYCOMMAND);
CMenu deleteMenu;
deleteMenu.LoadMenu(IDR_DELETE);
CMenu * popup = deleteMenu.GetSubMenu(0);
menu->ModifyMenuW(ID_FILE_DELETE, MF_BYCOMMAND | MF_POPUP,
(UINT_PTR)(HMENU)(*popup),
text);
}
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm