Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » CExtPopupMenuWnd problem Collapse All
Subject Author Date
Jean Michel Nov 10, 2005 - 5:37 PM

Hello,

First of all I would like to thank you very much for your very nice library.

Today I have a problem with popup menus.
Here is my code :

CMenu* menu_bar = ((CMainFrame*)AfxGetMainWnd())->GetMenu();
CMenu* file_menu = menu_bar->GetSubMenu(filterMenuIndex);    
ASSERT(file_menu);
GetCursorPos(&cpoint);
file_menu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, cpoint.x, cpoint.y, this);

This code works well but it’s MFC and I would like to display a ProfUIs popup menu so here is how I replaced the last line of the previous code:
CExtPopupMenuWnd * pPopup = new CExtPopupMenuWnd;
pPopup->UpdateFromMenu(AfxGetMainWnd()->m_hWnd, file_menu);
pPopup->TrackPopupMenu(0, cpoint.x, cpoint.y);

Well, this makes my program to crash.
Any idea ?

Regards

Pix

Technical Support Nov 11, 2005 - 12:29 PM

The main frame window in an MFC project (that does not use without Prof-UIS ) really has HMENU. You can access it, get its submenu and use it. This is safe in SDI applications, in which the HMENU of the main frame window exists persistently. This menu is changed on-the-fly in MDI applications when toggling the active MDI child frame window, opening the first MDI child frame or closing the last one. So, universally you should not access HMENU of the main frame window. Just load the menu resource instead.

The HMENU of the main frame window is always NULL() in the application written with Prof-UIS by using CExtMenuControlBar() window because the menu bar hooks the main frame and operates with its menu. The menu bar prevents the main frame window from displaying the classic menu bar. You can get the captured copy of main frame’s menu by invoking the CExtMenuControlBar::GetMenu() method. This method returns the same HMENU as in the main frame window of the MFC application written without Prof-UIS. So, we recommend the same: it is safe only in SDI applications where HMENU exists persistently. This technique cannot be used at all in Prof-UIS customizable applications which are based on the command tree nodes (the CExtCustomizeCmdTreeNode() class) and do not use HMENU at all.

Finally, in any case you need to code your context menu only once if you load it from the menu resource.

Jean Michel Nov 12, 2005 - 1:38 PM

You are true, but I forgot to say that I had this method in my code

CMenu* CMainFrame::GetMenu() 
{
	return m_wndMenuBar.GetMenu();
}


Actually, I found the problem. It happends because the menu I gave to my CExtPopupMenuWnd was not a popup menu (the first item was not an entry with a submenu).
So I fixed my code like this:
        // Create the popup menu
	CMenu *menu = new CMenu();
	MENUITEMINFO mi;
	ZeroMemory(&mi, sizeof(MENUITEMINFO));
	mi.cbSize = sizeof(MENUITEMINFO);
	mi.fMask = MIIM_SUBMENU;
	mi.hSubMenu = file_menu->m_hMenu;
	menu->CreatePopupMenu();
	menu->InsertMenuItem(0, &mi, 0);

        // Track the popup menu
	CExtPopupMenuWnd * pPopup = new CExtPopupMenuWnd;
	pPopup->UpdateFromMenu(AfxGetMainWnd()->m_hWnd, menu);
	pPopup->TrackPopupMenu(TPMX_LEFTALIGN,//|TPMX_DO_MESSAGE_LOOP,//TPM_LEFTALIGN|TPM_RIGHTBUTTON, 
		cpoint.x, cpoint.y);

	// Clean
        menu->RemoveMenu(0, MF_BYPOSITION);
	menu->DestroyMenu();


Thanks anyway :)