Solved

Updating an application's main frame's status bar text

Posted on 2013-11-21
5
1,055 Views
Last Modified: 2013-11-25
I'm building a C++ SDI application using document/view. In the program I need the document to change the application's main frame's status bar text from "Ready" to a specified text.

I have searched the web for a solution, but they discuss adding a new status pane and how to modify it. I have tried several different modifications on these to have it apply to ID_SEPARATOR but they didn't work, it stays "Ready".

Can someone show me a simple code sniplet on how to do this properly.

Thanks,
Robert
0
Comment
Question by:robear7nt
  • 3
  • 2
5 Comments
 
LVL 30

Expert Comment

by:Zoppo
ID: 39668311
Hi robear7nt,

could you please tell what you want to display there? Usually in a SDI application the status bar shows text-info about menu items and toolbar buttons selected with the mouse, Ready is only shown when no such item is beneath the mouse.

So, do you want to keep this default behavior but just want to show another text than Ready. Or do you want to implement a completeley different behavior, i.e. as simple sample a text which dynamically displays the current date/time no matter where the mouse is?

ZOPPO
0
 
LVL 1

Author Comment

by:robear7nt
ID: 39669945
When there is no text-info about menu items or toolbar buttons selected with the mouse, I would like to have the ability to show a dynamic text instead of Ready. That dynamic text would be shown anytime Ready would normally be shown.

The client area is showing a graphic representations of items that the user can manipulate by selecting the appropriate image and perform an action on it. When the user has an item selected, I would like the status bar to show dynamic information about that item. When an item is not selected, it might be "Select an item to perform an action on." or something more appropriate. I really do not want to waste status bar real estate with the Ready.

Is there pointer to the "Ready" string that be changed to point to another string? Seems to me it would be that simple ... lol

Robert
0
 
LVL 30

Accepted Solution

by:
Zoppo earned 500 total points
ID: 39673968
Hi robear7nt,

well, there's not simply a pointer to that string, usually this string is loaded from the string table resources (ID is AFX_IDS_IDLEMESSAGE). You can change the Ready there to any default text you like, but you can't use it to display dynamic texts.

So you have to do it manually. Here's a very simple sample how you can set a dynamic text depending on the mouse position in the view:
// Implement this function in CMainFrame to allow accessing it from the view
void CMainFrame::SetStatusBarText( LPCTSTR pszText, int nPaneId = 0 )
{
	m_wndStatusBar.SetPaneText( nPaneId, pszText );
}

// In the view class  add a WM_MOUSEMOVE handler (i.e. with ClassWizard)
void CTestView::OnMouseMove(UINT nFlags, CPoint point)
{
	CView::OnMouseMove(nFlags, point);

	CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();

	if ( point.x >= 100 && point.x <= 200 && point.y >= 100 && point.y <= 200 )
	{
		pMainFrame->SetStatusBarText( "Item selected!!!" );
	}
	else
	{
		pMainFrame->SetStatusBarText( "Select an item ..." );
	}
}

Open in new window

This will show the text Item selected!!! when the mouse is within the rect 100,100x200,200, otherwise Select an item ... is shown.

Of course this code is not very good because it will set the text again and again with every mousemove even if the text doesn't change. A better way would be to store some kind of item ID and store the last selected to compare it with a current selected to see if text needs to be changed.

Hope this helps,

ZOPPO
0
 
LVL 1

Author Comment

by:robear7nt
ID: 39675954
Awesome solution ZOOPO! Using the mouse movement to keep the status bar's text current is ingenious, and was the missing piece to the puzzle.

I modified your solution to fit my application. In the CMainFrame class, I created a CString to store the current text to show in the status bar and a public method, SetStatusBarText, to set the CString's value & immediately call SetPaneText. OnMouseMove simply calls SetPaneText. The application, frame, view, or document can call SetStatusBarText as needed. It works exactly as I needed it to :-)

Thank you so much, ZOOPO!

Robert
0
 
LVL 30

Expert Comment

by:Zoppo
ID: 39676768
Greate, you're welcome, I'm glad I could help ...

Have a nice day,

best regards,

ZOPPO
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

708 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