Click here to Skip to main content
15,900,461 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: WM_MENUDRAG Problem. Pin
Iain Clarke, Warrior Programmer6-May-04 5:13
Iain Clarke, Warrior Programmer6-May-04 5:13 
GeneralRe: WM_MENUDRAG Problem. Pin
Roger Allen6-May-04 5:37
Roger Allen6-May-04 5:37 
GeneralRe: WM_MENUDRAG Problem. Pin
Iain Clarke, Warrior Programmer6-May-04 5:25
Iain Clarke, Warrior Programmer6-May-04 5:25 
GeneralRe: WM_MENUDRAG Problem. Pin
Iain Clarke, Warrior Programmer7-May-04 1:52
Iain Clarke, Warrior Programmer7-May-04 1:52 
QuestionBest Approach? Pin
monrobot135-May-04 10:18
monrobot135-May-04 10:18 
AnswerRe: Best Approach? Pin
Christian Graus5-May-04 10:35
protectorChristian Graus5-May-04 10:35 
AnswerRe: Best Approach? Pin
Antti Keskinen5-May-04 10:37
Antti Keskinen5-May-04 10:37 
GeneralDynamic Menus w/ MDI Pin
BAmity5-May-04 9:26
BAmity5-May-04 9:26 
I'm trying to create dynamic menus with MFC's MDI interface. I've used CMenu's AppendMenu() or InsertMenu() function to insert a popup menu at the end of another menu in the MainFrame. The problem is that this works when the ChildFrame is first expanded when I create the menus, but if I try to create the menus when the ChildFrame is not expanded, they are not created properly. I read in the MSDN documentation that this is because the offsets of the menus are shifted by one when the MDI window is expanded. Therefore, I attempted to fix the code so it isn't position dependant, but this didn't seem to work. I think I don't understand the menu placement quite right. If anyone knows more about this, could you see where I'm going wrong in this code below and let me know?

Here's where I create the dynamic menu:

void CDoc::AddMenuUpdate()

{
CString sAddChan;
CMenu* pConfMenu = NULL;
CMenu* pTopMenu = AfxGetMainWnd()->GetMenu(); // Will this get the right top-level menu?

// Locate the configuration submenu to put the popup menu under
for (int iPos = pTopMenu->GetMenuItemCount()-1; iPos >= 0; iPos--)
{
CMenu* pMenu = pTopMenu->GetSubMenu(iPos);
if (pMenu && pMenu->GetMenuItemID(0) == ID_PROJECT_PROJECTSETUP)
{
pConfMenu = pMenu;
break;
}
}
ASSERT(pConfMenu != NULL);

// If a popup menu already exists, remove it to replace it with an updated one.
for (int iAddPos = pConfMenu->GetMenuItemCount()-1; iAddPos >= 0; iAddPos--) {
CMenu* pAddMenu = pConfMenu->GetSubMenu(iAddPos);
if(pAddMenu && pAddMenu->GetMenuItemID(0) == ID_CHANOFFSET) {
if(!pConfMenu->DeleteMenu(iAddPos, MF_BYPOSITION)) {
TRACE(_T("Error removing the existing popup menu..."));
}
break;
}
}
mAddCmds.clear(); // clear out the old command to hierarchy mappings

// And then create and add the new popup menu
CMenu addMenu;
VERIFY(addMenu.CreatePopupMenu());

VERIFY(pConfMenu->AppendMenu(MF_POPUP, (UINT)addMenu.m_hMenu, _T("Add Channel")));

// Get the list of items to add to the menu...
int iLoc = 0;
for(int i = 0; i < NEW_MENU_CMDS; i++) {
mAddCmds.insert(std::make_pair(ID_CHANOFFSET + iLoc, i));
// For each heirarchy, add an item to the popup menu
addMenu.AppendMenu(MF_STRING | MF_ENABLED, ID_CHANOFFSET + iLoc, "Genero Menu Cmd");
++iLoc;
}
HMENU hMenu = addMenu.Detach(); // Do I need to detach this here? Will it make a copy when I insert it into the pConfMenu?

}

GeneralRe: Dynamic Menus w/ MDI Pin
Roger Allen6-May-04 4:30
Roger Allen6-May-04 4:30 
GeneralWM_COPYDATA Pin
Anonymous5-May-04 8:12
Anonymous5-May-04 8:12 
GeneralRe: WM_COPYDATA Pin
David Crow5-May-04 8:49
David Crow5-May-04 8:49 
QuestionMemory leaks? Pin
jonsson_845-May-04 7:53
jonsson_845-May-04 7:53 
AnswerRe: Memory leaks? Pin
David Crow5-May-04 7:57
David Crow5-May-04 7:57 
GeneralRe: Memory leaks? Pin
jonsson_845-May-04 8:07
jonsson_845-May-04 8:07 
GeneralRe: Memory leaks? Pin
David Crow5-May-04 8:52
David Crow5-May-04 8:52 
GeneralRe: Memory leaks? Pin
jonsson_845-May-04 10:45
jonsson_845-May-04 10:45 
AnswerRe: Memory leaks? Pin
Johan Rosengren5-May-04 8:23
Johan Rosengren5-May-04 8:23 
GeneralRe: Memory leaks? Pin
jonsson_845-May-04 8:42
jonsson_845-May-04 8:42 
QuestionActiveX C++ component for printing? Pin
TigerNinja_5-May-04 7:43
TigerNinja_5-May-04 7:43 
GeneralProper way to define global class objects Pin
georgiek505-May-04 7:34
georgiek505-May-04 7:34 
GeneralRe: Proper way to define global class objects Pin
David Crow5-May-04 7:55
David Crow5-May-04 7:55 
GeneralRe: Proper way to define global class objects Pin
georgiek505-May-04 8:38
georgiek505-May-04 8:38 
GeneralRe: Proper way to define global class objects Pin
Rick York5-May-04 10:40
mveRick York5-May-04 10:40 
GeneralRe: Proper way to define global class objects Pin
Antti Keskinen5-May-04 10:49
Antti Keskinen5-May-04 10:49 
GeneralRe: Proper way to define global class objects Pin
Anonymous5-May-04 11:40
Anonymous5-May-04 11:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.