Solved

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

Posted on 2013-11-21
5
1,193 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
[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
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

687 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