How do I get rid of "Ready" in Status Bar
Where do I put this,
StatusBar->SetPaneText(0,"My Message");
(StatusBar is a pointer to a CStatusBar object),
to automatically overwrite "Ready" message that appears when a menu closes. Or, alternatively, how do I prevent that "Ready" message from overwriting "My Message?"
BTW, I could never figure out what that "Ready" message is for.
If the cursor isn't an hourglass, the program is ready.
Re: How do I get rid of "Ready" in Status Bar
I know this is an ancient thread, but I had some similar issues in an old MFC application and solved it this way.
Window class private members and method defined in header file:
Code:
void setStatusBarText(const std::string& sbT); // call this to set the statusbar text
bool timerRunning; // is the timer running
std::string statusBarText; // the status bar text that needs to be set
Implementation in the cpp file:
Code:
#define IDT_STATUSBAR_UPDATE_TIMER 0
.
.
.
CChildView::CChildView()
{
timerRunning = false; // initially the timer is not running
.
.
.
}
// See comments on setStatusBarText method
void CChildView::OnTimer(UINT_PTR nIDEvent)
{
CWnd::OnTimer(nIDEvent);
// Try getting the status bar control and update the text
CStatusBar* p = (CStatusBar*)AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR);
if (p == NULL)
return;
p->SetPaneText(0, statusBarText.c_str());
timerRunning = false; // signal that the timer is no longer running
KillTimer(nIDEvent); // kill the timer
}
// Due to some strange behaviour of the statusbar text, a timer is fired, when
// the status bar text needs to be update. The timer is killed, when the status
// bar text has actually been updated.
void CChildView::setStatusBarText(const std::string& sbT)
{
statusBarText = sbT;
if (timerRunning)
return; // the timer is already running, bail out
timerRunning = true;
SetTimer(IDT_STATUSBAR_UPDATE_TIMER, 333, NULL);
}
With the above implementation, one can set the statusbar text anywhere in the code, simply by calling setStatusBarText method.
Code:
setStatusBarText("This is a new message for the statusbar");
Calling setStatusBarText will start a timer, that eventually will set the StatusBar text.
Re: How do I get rid of "Ready" in Status Bar
Quote:
Originally Posted by
rudibr
I know this is an ancient thread, but I had some similar issues in an old MFC application and solved it this way.
Window class private members and method defined in header file:
Code:
void setStatusBarText(const std::string& sbT); // call this to set the statusbar text
bool timerRunning; // is the timer running
std::string statusBarText; // the status bar text that needs to be set
Implementation in the cpp file:
Code:
#define IDT_STATUSBAR_UPDATE_TIMER 0
.
.
.
CChildView::CChildView()
{
timerRunning = false; // initially the timer is not running
.
.
.
}
// See comments on setStatusBarText method
void CChildView::OnTimer(UINT_PTR nIDEvent)
{
CWnd::OnTimer(nIDEvent);
// Try getting the status bar control and update the text
CStatusBar* p = (CStatusBar*)AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR);
if (p == NULL)
return;
p->SetPaneText(0, statusBarText.c_str());
timerRunning = false; // signal that the timer is no longer running
KillTimer(nIDEvent); // kill the timer
}
// Due to some strange behaviour of the statusbar text, a timer is fired, when
// the status bar text needs to be update. The timer is killed, when the status
// bar text has actually been updated.
void CChildView::setStatusBarText(const std::string& sbT)
{
statusBarText = sbT;
if (timerRunning)
return; // the timer is already running, bail out
timerRunning = true;
SetTimer(IDT_STATUSBAR_UPDATE_TIMER, 333, NULL);
}
With the above implementation, one can set the statusbar text anywhere in the code, simply by calling setStatusBarText method.
Code:
setStatusBarText("This is a new message for the statusbar");
Calling setStatusBarText will start a timer, that eventually will set the StatusBar text.
Well, why reinvent the wheel? :rolleyes::confused:
Why not just use the WM_SETMESSAGESTRING?
Re: How do I get rid of "Ready" in Status Bar
Quote:
Originally Posted by
VictorN
Well, in my specific case, I am already setting the status bar text before the status bar is even created ;-)
That's why I need the timer to wait for the status bar to be ready.
Once the application is fully up and running, I could simply use the build in SetPaneText, but since the statusbar isn't instantiated, it doesn't work in my case.
Code:
CStatusBar* p = (CStatusBar*)AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR);
if (p != NULL)
p->SetPaneText(0, "What ever text needs to be set");
So my implementation is a kind of delayed mechanism. Would WM_SETMESSAGESTRING also be able to handle this? Will the message stay in the queue untill the statusbar is created?
Re: How do I get rid of "Ready" in Status Bar
Quote:
Originally Posted by
rudibr
...
So my implementation is a kind of delayed mechanism. Would WM_SETMESSAGESTRING also be able to handle this? Will the message stay in the queue untill the statusbar is created?
Just test it!
Re: How do I get rid of "Ready" in Status Bar
Quote:
Originally Posted by
VictorN
Just test it!
Ok. I’ll try that. Just thought that since You suggested it you might know something about it.
Re: How do I get rid of "Ready" in Status Bar
Quote:
Originally Posted by
VictorN
Just test it!
I tried this:
Code:
CHAR* msg = "This is a test";
AfxGetApp()->m_pMainWnd->SendMessage(WM_SETMESSAGESTRING, 0, (LPARAM)msg);
This doesn't set the status text, if called before the status bar is created, but works fine afterwards.
So I'll stick with my timer solution that actually works.
Why did you suggest using WM_SETMESSAGESTRING? Just guessing?
Re: How do I get rid of "Ready" in Status Bar
Quote:
Originally Posted by
rudibr
I tried this:
Code:
CHAR* msg = "This is a test";
AfxGetApp()->m_pMainWnd->SendMessage(WM_SETMESSAGESTRING, 0, (LPARAM)msg);
This doesn't set the status text, if called before the status bar is created, but works fine afterwards.
I never needed to set the status bar text before status bar has been created.
Quote:
Originally Posted by
rudibr
So I'll stick with my timer solution that actually works.
Yes! If it is already developed/created and does work, then why not? ;)
Quote:
Originally Posted by
rudibr
Why did you suggest using WM_SETMESSAGESTRING? Just guessing?
Because it worked for me since decades without any problem! :)
Re: How do I get rid of "Ready" in Status Bar
;-)
If it works, don’t fix it!
🤪
Re: How do I get rid of "Ready" in Status Bar
Quote:
Originally Posted by
rudibr
;-)
If it works, don’t fix it!
🤪
:thumb::thumb::thumb: