Link to home
Start Free TrialLog in
Avatar of Bubbai
Bubbai

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of Vinayak Kumbar
Vinayak Kumbar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vinayak Kumbar
Vinayak Kumbar

Hi,

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;
      dc.GetCharWidth(ch,ch,&Temp);
      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
str.MakeUpper();

//Set The Text
p_main->m_wndStatusBar.SetPaneText(1,str);

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.
VinExpert