Dynamic StatusBar pane...

I have status bar and I need to display various information on a pane.
I need to set the pane's size according to the displayed string's length.

How can I know which size to give to the pane in the "SetPaneInfo" function, so it will fit exactly to the displayed string's length.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vinayak KumbarSr Program ManagerCommented:

Do this

TEXTMETRIC txtmat;    
CClientDC dc(this);

CString str("df5656");
int Len = str.GetLength();
Len *= txtmat.tmMaxCharWidth;
CMainFrame *p_main = (CMainFrame *)AfxGetMainWnd();
p_main->m_wndStatusBar.SetPaneInfo(1, IDS_MYPANE, SBPS_NORMAL, Len);

Here IDS_MYPANE is indicator ID, inserted at first place. Its length varias on the lenght of string. Then u can set that string to that pane

Hope this helps.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vinayak KumbarSr Program ManagerCommented:

Here is One More Method.

//Get the DC
CClientDC dc(this);

//Have the string
CString str("xwiz");

//Get the length of string
int Len = str.GetLength();
int PaneWidth = 0;

//Calculate pane width from each char width
for(int Index = 0; Index < Len; Index++)
      char ch = str[Index];
      int Temp = 0;
      PaneWidth += Temp;
CMainFrame *p_main = (CMainFrame *)AfxGetMainWnd();

//Set The Width
p_main->m_wndStatusBar.SetPaneInfo(1, IDS_MYPANE, SBPS_NORMAL, PaneWidth);

//Make it Upper To Fit the Pane

//Set The Text

To achive from both the methods from any class other than CMainFrame, u may have to include mainfrm.h(if not included) and go to mainframe.h and declare m_wndStatusBar as public.

Try it out.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.