Solved

Forcing status bar message to update after settext

Posted on 1998-10-20
7
528 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 22
fizzArray2 challenge 1 61
has77  challenge 9 68
how to split multiple lines delimiter : 8 54
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 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

17 Experts available now in Live!

Get 1:1 Help Now