Solved

Forcing status bar message to update after settext

Posted on 1998-10-20
7
547 Views
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,
            (LPARAM)m_sIdleMesg.GetBuffer(25));
     else
     {
        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?
0
Comment
Question by:appleby
7 Comments
 
LVL 7

Expert Comment

by:psdavis
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?

Phillip
0
 

Author Comment

by:appleby
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.
0
 
LVL 7

Expert Comment

by:psdavis
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.

Phillip
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:appleby
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.
0
 
LVL 8

Expert Comment

by:Answers2000
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
0
 
LVL 3

Accepted Solution

by:
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.
0
 

Author Comment

by:appleby
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.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sumNumber challenge 16 139
isEverywhere  challenge 19 82
haveThree challenge 22 121
Modbus - whats the maximum I can store in one register? 4 80
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

838 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