.NET
  Home arrow .NET arrow Page 3 - Working with the Statusbar in MFC
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

Working with the Statusbar in MFC
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2009-10-07

    Table of Contents:
  • Working with the Statusbar in MFC
  • Before the MFC Feature Pack
  • Changing the text
  • Extra information

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Working with the Statusbar in MFC - Changing the text


    (Page 3 of 4 )

    We have three ways to change the text. I will use the extra space we have to display the current clock and the name of the current day of the week. For this first, I will set up a timed event. Let us trigger it every second to update the clock as the seconds pass by. I have used the WM_TIMER event message. Just add it into the main frame via the class view and properties method. After this, we will set up the timed event as soon as we are ready with the window. The end of the OnCreate() method is perfect. Add the following line:

    this->SetTimer(1,1000,NULL);

    The first part is the ID of the timed event. Given that we will have only one timed event, any number will do. The second argument states after how many milliseconds the timer should be triggered. To find out the time format, I have used the CTime class and the following lines:

    CTime today = CTime::GetCurrentTime();

    time = today.Format(_T("%A - %H:%M:%S"));

    First, we ask for the local time from the system with the static GetCurrentTime function. The time variable is just a string to store the value. The formatting characters used in the extraction of the current time are the same as for the strftime function. Now that we have the text, we can show it on the Statusbar.

    The easiest and most straightforward method is to set the new text in the corresponding text. In my case, the m_wndStatusBar is the CMFCStatusBar declared in the Mainframe class.

    m_wndStatusBar.SetPaneText(

    m_wndStatusBar.CommandToIndex(ID_STATUS_TEXT),

    time );

    The panes after the addition are numbered in an increasing order, starting from zero. However, sometimes we might not exactly know in what position that specific text is. For these situations, you can use the CommandToIndex function that will return the current index number of the allocated resource ID. The first argument is the index of the pane, while the second is the text to set. Once you've added this line after finding out the time, when you run the application, success is at hand:

     

    The second option is to assign to it an update controller. This function will be called every time an update is required for the assigned pane. Look at it as an OnDraw function of the pane. To start, assign the corresponding pane to a function as follows:

    ON_UPDATE_COMMAND_UI(ID_STATUS_TEXT, &CMainFrame::OnUpdateStatusText)

    Finally, add to the mainframe class function:

    afx_msg void OnUpdateStatusText(CCmdUI *pCmdUI);

     

    void CMainFrame::OnUpdateStatusText( CCmdUI *pCmdUI )

    {

    pCmdUI->Enable();

    pCmdUI->SetText(time);

     

    }

    To make sure that the refresh will be made no matter what, we could force an update by calling the InvalidatePaneContent function with the corresponding index as a parameter. Here you also have the option to enable or disable the text in the message text. I am talking about using the gray or the black font (as you can observe in the case of the caps pane). Of course, you can use this function to perform various other tasks as well:

    More .NET Articles
    More By Gabor Bernat


     

    .NET ARTICLES

    - Introducing .NET
    - Building Business Objects for an Application
    - Methods for an Application`s Business Logic ...
    - Properties of an Application`s Business Logi...
    - Classes and Properties in an Application`s B...
    - Organizing Code for the Business Logic Layer...
    - Building the Business Logic Layer
    - Completing a Business Layer with Windows Wor...
    - Building Applications with Windows Workflow ...
    - Building the Data and Business Layers Using ...
    - The Transformed XML Explorer in MFC
    - List Control and Property Grid with the MFC ...
    - Font, Shell and Masked Edit Controls for MFC
    - Color, Link and Image Editor Controls for M...
    - New Controls for MFC





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek