In the child window i can successfully do a MouseRight click and popup of some menu with its submenus from the main menu bar.
So you are using a popup (context) menu here and not the menu of the main frame (only the menu items / resources are re-used).
Then you should handle enabling/disabling when opening the popup menu and pass AfxGetMainWnd() as the owner window (see code comments):
CMenu *pMenu = new CMenu;
// Get the pop-up menu.
CMenu *pPopupMenu = pMenu->GetSubMenu(0);
// Enable disable an item by ID.
pPopupMenu->EnableMenuItem(CM_VIEW_OPTION1, CMViewOption1Enabled ? 0 : MF_GRAYED);
// Show context menu and wait for selection.
// Advantages of passing AfxGetMainWnd():
// - Calls provided OnUpdate() functions to determine state of items.
// NOTE: Items can be only disabled using the OnUpdate handlers!
// So there must be handlers for those items that may be disabled!
// If no update handlers are present, items are enabled by default
// (by existance of command handlers).
// - Shows short info about items in status bar
// - Processes F1 help
pPopupMenu->TrackPopupMenuEx(flags, x, y, AfxGetMainWnd(), NULL);
A dynamic update is not necessary here when the popup menu closes with the first click. Otherwise make pPopupMenu a member of your child view so that it can be used to change items and/or their state dynamically.
I am using version C++ 6.0 (and ported another application to VS2008 and I have the same problem). I have multiple dialogs in my application. It has been in use for years and now it has been noticed that if a edit box, checkbox, etc. is changed and then the dialog is dragged to more than 1/2 off the monitor's screen, that the data is reset. This is confusing to me. It seems like it has something to do with Paint, but I am not able to figure it out. Any assistance would be appreciated.
I have a bizarre problem with a dialog. I created a dialog to move items between two lists. The left list box has the pool of possible items that are unused on the left and the items being used on the right. In between the two are a bunch of buttons to move selected items left or right, or move the entire list from one box to the other.
The code for loading and handling the boxes is the same with just the names of the boxes changed. For example the move right button handling code extracts an item from the left box and puts in the the right and the move left button does the opposite.
Moving an item from the left box to the right works as expected. The code to get the item from the left box is:
for(i=0; i<nCount; i++)
idx = aryListBoxSel.GetAt(i);
val = (float)m_lstLeft.GetItemData(idx);
// does stuff with val here
If idx 2, the third item in the list ends up in val as expected.
However, moving from right to left, using a mirror image of the same code:
idx = aryListBoxSel.GetAt(i);
val = (float)m_lstRight.GetItemData(idx);
val is always the last item in the list, no matter what idx is.
I compared the code and everything is a mirror image of the other. The two lists are defined the same way, loaded the same way, and accessed the same way.
What could possibly be wrong? As far as I can tell, I am setting up two identical list boxes and getting two different results.
Sorry about the formatting, it was the first time I posted anything with code here.
The value is not always the same, it's whatever is last on the list. If the right list has the following strings:
Selecting "2" and clicking on the move left button will get the "11" and it will be moved to the left. If you then select the "2" again (or anything else on the list) and click on the move left button, the "10" will be selected and moved.
What gets selected is whatever is last on the list. The code for moving from the left box to the right is identical except for the control name and selecting the "2" would actually fetch the "2" from index 1 and move it.
The index fetched in both cases is correct. What isn't working is the code that gets the value for the index.
I'm completely baffled. The two are coded the same.
Why are you casting string values to floats in your code? You should use your debugger to step through the code and see exactly what values are being stored in your array (and why is it declared with two int fields?), and how they are matching the items in the lists.
SetItemData allows you to associate a 32 bit value with the index and GetitemData retrieves that data. When I do the AddString to put the strings in the list box, if successful I load a float value associated with the string with SetItemData. When retrieved it has to be cast back to float because GetItemData returns a DWORD.
In this particular dialog the data is stored as a float, but is always an integer. The program does this because the same data space can be used for float values too, but if you're in this dialog, the data will always be integers stored as floats.
Last Visit: 28-May-20 3:00 Last Update: 28-May-20 3:00