alan93
asked on
ON_UPDATE_COMMAND_UI_RANGE question
I'm using this to update menu items in a view/doc app and had no problems using it to enable or disable items based on doc data.
But now I'm trying to change the text of an item.
using:
code:--------------------- ---------- ---------- ---------- ---------- ---------- ---------
ON_UPDATE_COMMAND_UI_RANGE (32845, 32916, OnMenuEnableDisable)
void CMyView::OnMenuEnableDisab le(CCmdUI* pCmdUI)
{
.......
if(something)
pMenu-> ModifyMenu(ID_THE_ID_TO_CH ANGE,MF_BY COMMAND|MF _STR
ING,0,"One Text");
else
pMenu-> ModifyMenu(ID_THE_ID_TO_CH ANGE,MF_BY COMMAND|MF _STR
ING,0,"Another Text");
.........
}
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
but this function is not itterating all the items in the set ranges when a menu is accessed. ?
So the menu item I'm trying to change the text to, gets changed only when the view loads.
Is there a reason that this only gets called, like maybe on OnInitialUpdate(), or something.
I thought it is called everytime a menu is accessed.
MSDN is very brief on this.
But now I'm trying to change the text of an item.
using:
code:---------------------
ON_UPDATE_COMMAND_UI_RANGE
void CMyView::OnMenuEnableDisab
{
.......
if(something)
pMenu-> ModifyMenu(ID_THE_ID_TO_CH
ING,0,"One Text");
else
pMenu-> ModifyMenu(ID_THE_ID_TO_CH
ING,0,"Another Text");
.........
}
--------------------------
but this function is not itterating all the items in the set ranges when a menu is accessed. ?
So the menu item I'm trying to change the text to, gets changed only when the view loads.
Is there a reason that this only gets called, like maybe on OnInitialUpdate(), or something.
I thought it is called everytime a menu is accessed.
MSDN is very brief on this.
THe foundation class will not "itterate all the items" in the range. It will call your OnMenuEnableDisable function one time. That function will re responsible for itterating through the range and doing whaterer U/I updating is needed for each command.
Putting these in the CMainFrame, as suggested by roshmon, is and excellent idea becasue if the iew does not handle it, the update will be passed on to the frame anyway, so that is often the best place to catch these.
-- Dan
Putting these in the CMainFrame, as suggested by roshmon, is and excellent idea becasue if the iew does not handle it, the update will be passed on to the frame anyway, so that is often the best place to catch these.
-- Dan
BTW, IMO it's not good to modify the menu in an ON_UPDATE_COMMAND_UI
handler ... these handler functions may even be called at
idle time when no menu is opened if you i.e. have toolbar
buttons with same IDs.
nstead I think it's better to handle WM_INITMENUPOPUP which is
sent whenever a menu is opened or, if you need to modify it
only once when the menu is accessed first, WM_INITMENU.
ZOPPO
handler ... these handler functions may even be called at
idle time when no menu is opened if you i.e. have toolbar
buttons with same IDs.
nstead I think it's better to handle WM_INITMENUPOPUP which is
sent whenever a menu is opened or, if you need to modify it
only once when the menu is accessed first, WM_INITMENU.
ZOPPO
ASKER
ok Zoppo, your explanation seemed the best and the easiest, however, when I put the same code in:
void CMainFrame::OnInitMenuPopu p(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
and change my pMenu to pPopupMenu, it does get called everytime when the menu is opened, and the 'IF' statemnts execute correctly, but the text is only set the first time.
I don't know why the text does not update subsequent times
Have any idea?
void CMainFrame::OnInitMenuPopu
and change my pMenu to pPopupMenu, it does get called everytime when the menu is opened, and the 'IF' statemnts execute correctly, but the text is only set the first time.
I don't know why the text does not update subsequent times
Have any idea?
The problem is the '0' in the call to ModifyMenu (with 0 you
modify the ID from 'ID_THE_ID_TO_CHANGE' to '0'.
So, simply use
pPopupMenu-> ModifyMenu(ID_THE_ID_TO_CH ANGE,MF_BY COMMAND|MF _STRING,ID _THE_ID_TO _CHANGE,"A nother Text");
instead.
ZOPPO
modify the ID from 'ID_THE_ID_TO_CHANGE' to '0'.
So, simply use
pPopupMenu-> ModifyMenu(ID_THE_ID_TO_CH
instead.
ZOPPO
ASKER
ok Zoppo, your explanation seemed the best and the easiest, however, when I put the same code in:
void CMainFrame::OnInitMenuPopu p(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
and change my pMenu to pPopupMenu, it does get called everytime when the menu is opened, and the 'IF' statemnts execute correctly, but the text is only set the first time.
I don't know why the text does not update subsequent times
Have any idea?
void CMainFrame::OnInitMenuPopu
and change my pMenu to pPopupMenu, it does get called everytime when the menu is opened, and the 'IF' statemnts execute correctly, but the text is only set the first time.
I don't know why the text does not update subsequent times
Have any idea?
ASKER
ok great, that did it.
Works now.
I wish the MSDN wasn't so cloudy with the definitions of the parameters because that looks like a duplicate to me and don't understand why.
Works now.
I wish the MSDN wasn't so cloudy with the definitions of the parameters because that looks like a duplicate to me and don't understand why.
ASKER
ok great, that did it.
Works now.
I wish the MSDN wasn't so cloudy with the definitions of the parameters because that looks like a duplicate to me and don't understand why.
Works now.
I wish the MSDN wasn't so cloudy with the definitions of the parameters because that looks like a duplicate to me and don't understand why.
ASKER
Tried to award points but got an internal apache server error:
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperEx ception: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
An error occurred between lines: 1 and 40 in the jsp file: /jsp/../shared/emailCommen tAdded.jsp
I'm just not impressed with servlets.
I'll try again later
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperEx
An error occurred between lines: 1 and 40 in the jsp file: /jsp/../shared/emailCommen
I'm just not impressed with servlets.
I'll try again later
BTW, just a hint to avoid multiple posts of same comment:
Either use link 'Reload Question' (the first link beyond your
login name at the top-left) to reload a question or simply
answer the 'Do you want to re-post your data' dialog with 'No'.
Either use link 'Reload Question' (the first link beyond your
login name at the top-left) to reload a question or simply
answer the 'Do you want to re-post your data' dialog with 'No'.
Maybe you should report the problem with accepting answer at
https://www.experts-exchange.com/Community_Support/
https://www.experts-exchange.com/Community_Support/
Hi Zoppo,
If you select answer instead of comment, alan93 can accept your comment as answer...
Just try.
Good Luck
If you select answer instead of comment, alan93 can accept your comment as answer...
Just try.
Good Luck
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
trying to accept answer
ASKER
I noticed that if I don't type a comment and just select Accept. I got a "Requested page not found" error.
Whats going on with this site.?
Oh well typed in a comment and it worked.
Whats going on with this site.?
Oh well typed in a comment and it worked.
you mapped the UPDATE_COMMAND_UI_RANGE is on View, So the function will fire only the existance of the view,
Try to map in MainFrame...
Roshmon