Forcing status bar message to update after settext

Posted on 1998-10-20
Last Modified: 2013-11-20
I have overridden the idle status bar message ("Ready") with my own text by subclassing the CStatusBar object and overriding the OnSetText function.  This is the code:

LRESULT CmStatusBar::OnSetText(WPARAM wParam, LPARAM lParam)
  CString strMessage = (LPCTSTR)lParam;
     if (strMessage == "Ready")
        return StatusBar::OnSetText(wParam,
        return CStatusBar::OnSetText(wParam, lParam);

where m_sIdleMesg is a CString member variable that is previously set.  This function works fine, but doesn't force a redraw so the status bar text doesn't change until something else triggers it, such as tooltips coming on and going off.  I've tried UpdateWindow, Invalidate, etc. but how do you actually make the paint happen?
Question by:appleby

Expert Comment

ID: 1323574
Use the CWnd::SetWindowText to set the status bar message instead!  The StatusBar should immediately update.  

Why did you have to override with the OnSetText?  What couldn't you do with the default?


Author Comment

ID: 1323575
Using CWnd::SetWindowText changed and updated the text, but then set it right back to "Ready" again immediately.  It didn't stick.  I want a permanent override so it never says "Ready" but always says something that the program dictates according to its current state.

Expert Comment

ID: 1323576
The 'Ready' and the toolbar messages should always update depending on the position of the mouse.  You might want to consider adding another pane to the status bar and manually changing that one, especially if it is state driven.

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.


Author Comment

ID: 1323577
That is an option but I'd really like to continue doing it this way if there is just a way to force the window to update afterwards.

Expert Comment

ID: 1323578
OnSetText is only called when somebody does SetWindowText (or similar) - i.e. the text of the bar is changed.   This is why you can't find another way to get this function called.

The trick relates to AFX_IDSIDLEMESSAGE and I think WM_SETMESSAGE, but I'm still thinking on this

Accepted Solution

stefanr earned 50 total points
ID: 1323579
You may try this (a member function of CMainFrame is assumed):

int nIndex = m_wndStatusBar.CommandToIndex(ID_SEPARATOR);
if (-1 != nIndex)
   m_wndStatusBar.SetPaneText(nIndex, _T("Some other text"));

The main function here is CStatusBar::SetPaneText. You may call it directly from your derived CStatusBar class if you wish. It seems to update the text immediately.

Author Comment

ID: 1323580
Thank you - it was actually a combination of stefanr's answer and Answer2000's comment that gave me what I needed.  I have a function that sets the variable m_sIdleMesg of course.  And so I called the SetWindowText() function right after setting my idle text within the function that does so.  Voila, OnSetText() is called and it is updated immediately.  I didn't try it but I assume SetPaneText() would have acted the same way as SetWindowText()used here.  Thanks both of you.

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 176
mixString challenge 36 120
unable to delete all specified values regedit 38 385
mapBully challenge 6 127
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now