Solved

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

Posted on 2013-11-21
5
1,091 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 31

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 31

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 31

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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…

947 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

22 Experts available now in Live!

Get 1:1 Help Now