Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can we allign some text from left side and some text from right side to the statusbar in vc++

What I have tried:

i have added the spaces from left side after spaces i have added another text but when big text coming space is not showing equal for all the time
Posted
Updated 12-Apr-17 23:16pm

You have to get the actual width of the status bar window and then adjust your text to fit. See CWnd::GetWindowRect[^] and CDC::GetTextExtent (MFC)[^].
 
Share this answer
 
You have two options where both requires deriving a class from the CStatusBar Class[^] or the CMFCStatusBar Class[^].

Change the type of m_wndStatusBar in your main frame window class header file to the derived class and include the header file of the derived class. If necessary create and initialise m_wndStatusBar in OnCreate of the main frame class.

The first method is overriding CStatusBar::DrawItem resp. CMFCStatusBar::OnDrawPane to do the drawing as required. This requires that the passed string contains a delimeter that is used to split it into the left and right parts.

The second method would be adding a pane for the right aligned text. The disadvantage of this solution is that the fixed space of the additional pane can't be used by the leftmost pane anymore (assuming using the style SBPS_STRETCH which lets this pane occupy the remaining available space). The advantage of this solution is that you can set the left and right text independently. But to show right aligned text you have to use ownerdraw for that pane too.
 
Share this answer
 
Comments
Member 13089825 13-Apr-17 6:25am    
thank you for your reply.
could you please provide some example if possible
Jochen Arndt 13-Apr-17 6:34am    
I'm sorry, I have no examples.
You can search for "cstatusbar ownerdraw" (or cmfcstatusbar). There are not so many hits.

How to draw the text depends on the used status bar type and the method you choose.

To draw the text get the rectangle for the pane and use DrawText.
Member 13089825 13-Apr-17 9:57am    
here we are using (CMainFrame*)(AfxGetApp()->m_pMainWnd)->setmessagetext(L"string")so using this how can we set on right side
here we are using standard status bar
could you please helm me if you have any idea on this
Jochen Arndt 13-Apr-17 10:06am    
As I wrote:
Derive a class from C[MFC]StatusBar and owner draw there.
When calling SetMessageText() from a window, it will be forwarded to the m_wndStatusBar member. In the status bar derived class draw the message yourself.

This requires some time and testing which is too much for Quick Answers.
It is also inpossible to answer without knowing the type of your status bar and how the strings should be drawn / what is passewd to SetMessageText().
Member 13089825 13-Apr-17 9:57am    
here we are using (CMainFrame*)(AfxGetApp()->m_pMainWnd)->setmessagetext(L"string")so using this how can we set on right side
here we are using standard status bar
could you please helm me if you have any idea on this

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900