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 » CExtStatusBar and CExtButton with menu Collapse All
Subject Author Date
Moby Dick Dec 13, 2004 - 3:25 AM

Hi,


My application uses the CExtStatusBar methods explained in the StatusPane sample. I want to add a CExtButton in my status bar with a menu. When the user click on the button, the popup menu will appear.


I’ve successfully added the button and the menu to the button, but the button is shown disabled. All my menu items command are implemented.


If I add the ON_CLICK event for the button, it will appear enabled but any action on the button will cause an exception.


Where does the problem come from and how can I solve it ?


Thanks a lot.

Technical Support Dec 13, 2004 - 9:31 AM

We just added the following code to assign a menu to the button in the StatusPanes sample and all works fine:

CMenu _menu;
VERIFY( _menu.LoadMenu(IDR_POPUP_MENU) );
m_pWndButton->m_menu.Attach( _menu.Detach() );




You may send us your test project so that we can help you.

Moby Dick Dec 14, 2004 - 2:29 AM

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 ?

Technical Support Dec 15, 2004 - 1:07 AM

First, register your commands in the global command manager (somewhere in the CMainFrame::OnCreate method):

for( int i=0; i<12; i++ )
{
   g_CmdManager->CmdAllocPtr(
      g_CmdManager->ProfileNameFromWnd( GetSafeHwnd() ),
      ID_MYITEM_1 + i
   );
}
The code that creates and assigns the popup menu to the status bar button may look like:
CMenu *pSubMenu = new CMenu;
pSubMenu->CreatePopupMenu();
 
for( int i=0; i<12; i++ )
{
   CString sText;
   sText.Format( _T("Menu Item %d"), i );
   pSubMenu->AppendMenu(
      MF_STRING, 
      (UINT)ID_MYITEM_1 + i, 
      sText 
   );
}
 
CMenu popupMenu;
popupMenu.CreatePopupMenu();
popupMenu.AppendMenu(
   MF_POPUP, 
   (UINT)pSubMenu->GetSafeHmenu()
   );
 
if( !m_pWndButton->m_menu.Attach( popupMenu.Detach() ) )
   TRACE("m_pWndButton->m_menu.Attach failed.\n");

Moby Dick Dec 23, 2004 - 3:03 AM

Dear Sir,


I’m very sorry but this don’t work properly.


The button still be disabled.


Please, can you tell me where the problem can come from ?


Thanks.

Technical Support Dec 23, 2004 - 5:34 AM

It seems we need to take a look at the source code? Could you send us a sample project that demonstrates the problem?