![]() |
OnCreateControl not called for menu items |
Post Reply ![]() |
Author | |
mschumi ![]() Groupie ![]() Joined: 21 May 2007 Location: Germany Status: Offline Points: 12 |
![]() ![]() ![]() ![]() ![]() Posted: 21 May 2007 at 2:28pm |
Hi Oleg and team,
I'm rather new with the Xtreme Toolkit (VisualStudio 2005). What I'm trying to do is hide whole popup menus and also single menu items (depending on the MDI template). To achieve this, I'm handling the ON_XTP_CREATECONTROL message quite similar as is done in the CommandBars sample MDIMenus: int CMainFrame::OnCreateControl(...) { ... ... if (lpCreateControl->strCaption == _T("&Window")) { CXTPControlPopup* pControlPopup = CXTPControlPopup::CreateControlPopup(xtpControlPopup); // Exclude only IDR_MAINFRAME template pControlPopup->ExcludeDocTemplate(IDR_MAINFRAME); // from here AddMenuItem is called for the non-popup menu subitems pControlPopup->SetCommandBar(pPopupMenu); lpCreateControl->pControl = pControlPopup; ... ... } } Hiding of the first-level popup menus works very well, however for the menu's sub-items, OnCreateControl is not called. As far as I could see, SetCommandBar calls CXTPControls::AddMenuItem (via CXTPCommandBar::LoadMenu, CXTPControls::LoadMenu). In AddMenuItem, a CWnd* pSite is determined. That is where the WM_XTP_BEFORECREATECONTROL is sent (should be CMainFrame). However, when AddMenuItem is called for a (non-popup) sub-item, pSite is NULL. The problem is reproducable in the MDIMenus sample also (although there only popup menus are handled). Do you have any suggestions? Thanks a lot, Michael |
|
![]() |
|
Oleg ![]() Admin Group ![]() Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
![]() ![]() ![]() ![]() ![]() |
Hi,
Strange. it have call it for all controls. What toolkit vesrion do you have?
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
mschumi ![]() Groupie ![]() Joined: 21 May 2007 Location: Germany Status: Offline Points: 12 |
![]() ![]() ![]() ![]() ![]() |
Hi,
I'm using Xtreme Toolkit Pro 2006 Q4 (10.4). For reproduction, I inserted the following lines of code at the end of CMainFrame::OnCreateControl (in the CommandBars sample "MDIMenus"). What this code is intended to do is hide the menu items "Print Setup" (in the "File" popup menu) and "Blue" (in the "Color" popup menu). The effect is: only "Print Setup" is hidden, "Blue" is still visible. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl) { ... ... if (lpCreateControl->nID == ID_FILE_PRINT_SETUP) { // exclude only IDR_MDIMENUTYPEHTML template // this code is reached because for the "File" popup menu, SetCommandBar(pPopupMenu) is NOT called CXTPControl *pControl = (CXTPControl*)CXTPControlButton::CreateObject(); pControl->AssignDocTemplate(IDR_MDIMENUTYPEHTML); lpCreateControl->pControl = pControl; return TRUE; } if (lpCreateControl->nID == ID_COLOR_BLUE) { // exclude only IDR_MDIMENUTYPEHTML template // this code is never called because for the "Color" popup menu, SetCommandBar(pPopupMenu) IS called CXTPControl *pControl = (CXTPControl*)CXTPControlButton::CreateObject(); pControl->AssignDocTemplate(IDR_MDIMENUTYPEHTML); lpCreateControl->pControl = pControl; return TRUE; } return FALSE; } I guess that's a bug in the Xtreme Toolkit. Nevertheless, in the meantime I luckily managed to create a work-around. I created a new class MyXTPControlPopup derived from CXTPControlPopup and added a second parameter to the SetCommandBar method: void MyXTPControlPopup::SetCommandBar(CMenu* pMenu, CXTPCommandBars *pCommandBars) { if (!m_pCommandBar) m_pCommandBar = CXTPPopupBar::CreatePopupBar(pCommandBars); m_pCommandBar->LoadMenu(pMenu); } For comparison see the original code below: void CXTPControlPopup::SetCommandBar(CMenu* pMenu) { if (!m_pCommandBar) m_pCommandBar = CXTPPopupBar::CreatePopupBar(m_pParent ? m_pParent->GetCommandBars() : NULL); m_pCommandBar->LoadMenu(pMenu); } In CMainFrame::OnCreateControl, I now can create an instance of type MyXTPControlPopup and call pControlPopup->SetCommandBar(pPopupMenu, GetCommandBars()); instead of pControlPopup->SetCommandBar(pPopupMenu); Now it works because the GetOwnerSite / GetSite now always return the CMainFrame pointer. Perhaps you can try to reproduce. If you are able to reproduce the bug I will make a bug report. Thank you, Michael |
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |