Hi,
So I’ve got a problem with my code.
There’s what I do:
I’ve got a class which inherits of the CMDIFrameWnd class and a variable of
the
CExtStatusBarButton* type (as in StatusPane).
The button is created in OnCreate:
m_pWndButton = new CExtStatusBarButton;
if (!m_pWndButton->Create(_T("Button"), WS_CHILD | WS_VISIBLE | WS_TABSTOP,
CRect(0, 0, 0, 0), &m_pMainFrame->m_wndStatusBar,
IDC_STATUS_BAR_BUTTON))
{
TRACE(_T("Failed to create button control.\n"));
return -1;
}
m_pWndButton->SetFlat();
m_pWndButton->SetDrawBorder();
bool bRet = m_pMainFrame->m_wndStatusBar.AddPane(IDS_MYBUTTON, 2);
nIndex = m_pMainFrame->m_wndStatusBar.CommandToIndex(IDS_MYBUTTON);
m_pMainFrame->m_wndStatusBar.SetPaneWidth(nIndex, 150);
m_pMainFrame->m_wndStatusBar.SetPaneControl(m_pWndButton, IDS_MYBUTTON,
true);
The dynamic menu is initialized :
CMenu _MyMenu;
_MyMenu.CreatePopupMenu();
// 12 elements are created as below:
// (the menu has to be dynamic because it depends of the data in the
application).
_MyMenu.AppendMenu(MF_STRING | MF_POPUP, (UINT)ID_MYITEM_1, "Some text");
At last; I assign the menu to the button :
m_pWndButton->m_dwMenuOpt |= TPMX_OWNERDRAW_FIXED;
if (!m_pWndButton->m_menu.Attach(_MyMenu.Detach()))
TRACE("m_pWndButton->m_menu.Attach failed.\n");
m_pWndButton->EnableWindow(TRUE);
The button appears deactivated (grayed) !
All the dynamically created menu commands are implemented via:
ON_COMMAND_RANGE(ID_MYITEM_1, ID_MYITEM_12, OnCurrentItemClicked)
Can you tell me where my problem comes from ?