Solved

Forcing status bar message to update after settext

Posted on 1998-10-20
7
557 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
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 Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

689 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