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 Tech Support » Status Bar button problem Collapse All
Subject Author Date
Ernest Peters Sep 14, 2005 - 10:06 PM

Hi,
I am trying to place a button in a status bar. the status bar belongs to a CExtResizableDialog dialog with only a grid on it. The button is on the context menu of the grid ctrl (and that part works fine), just the button on the status bar is ALWAYS disabled.

I have tried all manual methods of enabling it (SetPaneStyle, EnableWindow etc). each enabling the control for an instant, then it gets disabled again.

Apart from the fact the control is in the context menu, my code is a direct replication of that in your examples
StatusPanes-nd.exe and ProfUIS_Controls-nd.exe

BEGIN_MESSAGE_MAP(CGridLogDlg, CBaseGridDlg)
ON_WM_LBUTTONDOWN()
ON_WM_CONTEXTMENU()
    ON_COMMAND_RANGE(IDS_LOGLIST_NAME_0, IDS_LOGLIST_NAME_255, OnShowNewList)
ON_COMMAND(ID_ECULOGGING_VIEWLOGLISTS, OnShowLogLists)
ON_WM_TIMER()
ON_BN_CLICKED(ID_LOGWINDOW_STARTSTOP, OnLogwindowStartStop)
ON_UPDATE_COMMAND_UI(ID_LOGWINDOW_STARTSTOP, OnUpdateLogwindowStartStop)
END_MESSAGE_MAP()

BOOL CGridLogDlg::OnInitDialog()
{
__super::OnInitDialog();

    static UINT indicators[] =
    {
        ID_SEPARATOR, // status line indicator
    };

// setup the status bar and anchor it to the window
    if ((false == this->m_StatusBar.Create(this)) || (false == this->m_StatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))))
    {
// TODO: log something..is this the end of the world for this dialog?
    }
else
{
     this->m_StatusBar.GetStatusBarCtrl().SetMinHeight(20);
     this->m_StatusBar.SetPaneWidth(0, 150);
     CWnd::RepositionBars(0,0xFFFF,0);
this->AddAnchor(this->m_StatusBar.m_hWnd, __RDA_LT, __RDA_LB);
}

if (false == this->m_StartStopLogging_btn.Create(_T("Start"), WS_CHILD|WS_VISIBLE|WS_TABSTOP, CRect(0,0,0,0), &this->m_StatusBar, ID_LOGWINDOW_STARTSTOP))
    {
// TODO: log something..is this the end of the world for this dialog and its ability to log?
}
else
{
        this->m_StartStopLogging_btn.SetFlat();
        this->m_StartStopLogging_btn.SetDrawBorder(true);
        
        bool bRet = this->m_StatusBar.AddPane(IDS_PANE_BUTTON, 1);
        if(!bRet)
{
            AfxMessageBox(_T("Pane index out of range\nor pane with same ID already exists in the status bar"), MB_ICONERROR);
            return (false);
        }
        
        int nIndex = this->m_StatusBar.CommandToIndex(IDS_PANE_BUTTON);
        if (nIndex == -1)
{
            return (false);
}

        this->m_StatusBar.SetPaneWidth(nIndex, 50);
this->m_StatusBar.SetPaneControl(this->m_StartStopLogging_btn, IDS_PANE_BUTTON, true);

this->m_StatusBar.EnableControl(nIndex);
}

    if (!m_LoggingRate_edit.Create(WS_CHILD|WS_VISIBLE|WS_TABSTOP, CRect(0,0,0,0), &m_StatusBar, 0))
    {
        TRACE(_T("Failed to create edit control.\n"));
        return (false);
    }
else
{    
     m_LoggingRate_edit.SetFont(CFont::FromHandle((HFONT)::GetStockObject(DEFAULT_GUI_FONT)));
    
     m_LoggingRate_edit.SetWindowText(_T("Type text here..."));
    
     bool bRet = m_StatusBar.AddPane(IDS_PANE_EDIT, 2);
     if(!bRet)
{
         AfxMessageBox(_T("Pane index out of range\nor pane with same ID already exists in the status bar"), MB_ICONERROR);
         return (false);
     }
    
     int nIndex = m_StatusBar.CommandToIndex(IDS_PANE_EDIT);
     if (nIndex == -1)
     {
         return (false);
     }
    
     m_StatusBar.SetPaneWidth(nIndex, 100);
     m_StatusBar.SetPaneControl(m_LoggingRate_edit, IDS_PANE_EDIT, true);
}

// Fixed Columns and rows
    this->m_Grid.OuterRowCountTopSet(2L, false);
    this->m_Grid.OuterColumnCountLeftSet(1L, false);
    this->m_Grid.OuterColumnWidthSet(true, 0L, 60);

// show the log list
this->ShowLogListItems();

return (true); // return TRUE unless you set the focus to a control
}

void CGridLogDlg::OnLogwindowStartStop()
{
AfxMessageBox("About to log");
}

// TODO: If we were to restrict users being able to log..this would be the place
void CGridLogDlg::OnUpdateLogwindowStartStop(CCmdUI *pCmdUI)
{
pCmdUI->Enable();

this->m_StartStopLogging_btn.EnableWindow();
}

Technical Support Sep 20, 2005 - 8:27 AM

Your source code looks OK, but you should not use the anchor mechanism for the status bar window. Just use the CWnd::RepositionBars( 0, 0xFFFF,0 ) API instead. The button in the status pane should be enabled without any conditions. So, we may guess the problem hides somewhere outside the source code snippet porvided in your message. To clear the issue, we coded a very simple dialog-based application. Please take a look at it and compare it with your real project. Of course, you can send us your project so we can fix it. Alternatively, we can connect to your desktop remotely and find out what’s wrong.

Ernest Peters Sep 22, 2005 - 3:31 AM

Hi, your example works (obviously :)). The problem i am having is that the button i am inserting is part of a context menu as well. maybe send me a sample that has a context menu that is creatd both at run time and one with a dialog that creates the context menu from a resource.

with regards to the anchoring, i have to anchor it , as the reposition leaves it in the centre of the screen. and if i dont call reposition the status doesnt even get drawn.
thanks again
ernest.

Technical Support Sep 22, 2005 - 10:27 AM

It’s not completely clear what you need to implement in the status bar with reagard to the button. Are you talking about the drop-down button, which fires a pop-up menu when clicking its right part?

Ernest Peters Sep 26, 2005 - 7:27 PM

No, you are misunderstanding me.
What i have is a button in the main menu called ’Start’ (to start a comms logging session with id ID_LOGWINDOW_START). In the context menu for the grid i have the same button ’Start’ also using id ID_LOGWINDOW_START. I also want the ’Start’ button in the status bar (using id ID_LOGWINDOW_START).

Basically, i need to locate the same functionality for ’Start’ in three different places all updated with ON_UPDATE_COMMAND_UI.

Technical Support Sep 28, 2005 - 7:29 AM

Please take a look at the StatusPanes sample in which you can find how to insert a button to the status bar pane and implement the ON_UPDATE_COMMAND_UI handler.