[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1350
  • Last Modified:

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

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
robear7nt
Asked:
robear7nt
  • 3
  • 2
1 Solution
 
ZoppoCommented:
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
 
robear7ntAuthor Commented:
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
 
ZoppoCommented:
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
 
robear7ntAuthor Commented:
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
 
ZoppoCommented:
Greate, you're welcome, I'm glad I could help ...

Have a nice day,

best regards,

ZOPPO
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now