Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - OnCreateControl not called for menu items
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

OnCreateControl not called for menu items

 Post Reply Post Reply
Author
Message
mschumi View Drop Down
Groupie
Groupie


Joined: 21 May 2007
Location: Germany
Status: Offline
Points: 12
Post Options Post Options   Thanks (0) Thanks(0)   Quote mschumi Quote  Post ReplyReply Direct Link To This Post Topic: OnCreateControl not called for menu items
    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

Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 22 May 2007 at 1:03am
Hi,
 
Strange. it have call it for all controls. What toolkit vesrion do you have?
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
mschumi View Drop Down
Groupie
Groupie


Joined: 21 May 2007
Location: Germany
Status: Offline
Points: 12
Post Options Post Options   Thanks (0) Thanks(0)   Quote mschumi Quote  Post ReplyReply Direct Link To This Post Posted: 22 May 2007 at 8:09am
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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.063 seconds.