Dannz
Dannz

Reputation: 495

MFC How to add toolbar to display changing text

I want to add a toolbar at the bottom that will show my mouse position.

How can I add a read-only that will be constantly updated when I move my mouse?

All I did is make a toolbar and it has a button instead of a read-only style.

Upvotes: 0

Views: 363

Answers (2)

lakeweb
lakeweb

Reputation: 1939

I would add, you should not push your info to the status bar. Let the main message pump deal with it on idle. In your child/main derived frame add a UI handler. Let it pull the information from the view.

ON_UPDATE_COMMAND_UI( ID_STATUSBAR_LABEL, &OnUpdateStatusText )
...
void CADFrame::OnUpdateStatusText( CCmdUI *pCmdUI )
{
    pCmdUI->Enable( );
    CADView* pView= dynamic_cast< CADView* >( GetActiveView( ) );
    ASSERT_VALID( pView );
    pCmdUI->SetText( pView->GetStatusInfo( ) );
...
}

As you are working with mouse positions you will have a last mouse position stored in the view for progressive calculations. So in you view something like, (it depends what you are up to):

const CString& CADView::GetStatusInfo( )
{
    if( bStatusMouseChanged )
    {
        strStatus.Format( _T(" x: %.4f y: %.4f")
            ,(double)( ptLastMouse.x - offsetx ) / winScale
            ,(double)( ptLastMouse.y - offsety ) / winScale
        );
        bStatusMouseChanged= false;
    }
    return strStatus;
}

By keeping a flag you only build the string when you need to. From shameless promo of my project.

Upvotes: 0

Related Questions