I'm trying to put a status bar on a dialog based app.

I have the following code in the OnInitDialog():

if (!m_wndStatusBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM) || !m_wndStatusBar.SetIndicators(indicators,
          sizeof(indicators)/sizeof(UINT)))
    {
      TRACE0("Failed to create status bar\n");
      return -1;      // fail to create
    }
    else
      MessageBox("Status bar created", "Debug");
    
  // Show the status bar
  m_wndStatusBar.EnableWindow(TRUE);
  m_wndStatusBar.ShowWindow(SW_SHOW);
  m_wndStatusBar.BringWindowToTop();
  m_wndStatusBar.UpdateWindow();
  if (!m_wndStatusBar.IsWindowVisible())
    MessageBox("Status Bar not visible");
  m_wndStatusBar.SetWindowText("Ready");

Here I get the message "Status bar created". This is good.
And I get the message "Status Bar not visible". This is expected since the Dialog is not yet visible.

Then I put a button on the dialog. This is the code for the button click.

// See if status bar is visible
  if (!m_wndStatusBar.IsWindowVisible())
    MessageBox("Status Bar is not visible");
  else
    MessageBox("Status Bar is visible");
  CString PanelText = m_wndStatusBar.GetPaneText(2);
  UINT PaneID;
  UINT PaneStyle;
  int PaneWidth;
  m_wndStatusBar.GetPaneInfo(2, PaneID, PaneStyle, PaneWidth);

  CString sStatusBarInfo;
  sStatusBarInfo.Format("ID = %d\nStyle = %d\nWidth = %d\nPanelText = %s", PaneID, PaneStyle, PaneWidth, PanelText);

  MessageBox(sStatusBarInfo);

When I click the button I get the message "Status Bar is visible". But I can't see it. And I get the message:

ID = 59138
Style = 0
Width = 25
PanelText = NUM

This says that the Status Bar is truly created and has a width. I don't know how to get the height info. But I believe the height is greater than 0. Where is that status bar?

I figured it out. This code works in the OnInitDialog().

if (!m_wndStatusBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM) ||
    !m_wndStatusBar.SetIndicators(indicators,
    sizeof(indicators)/sizeof(UINT)))
  {
    TRACE0("Failed to create status bar\n");
    return -1;      // fail to create
  }

  // Show the status bar

  m_wndStatusBar.SetWindowText("Ready");

  CClientDC dlgDC(this);
  CWnd* clientWindow = dlgDC.GetWindow();
  RECT MyRect;
 
  clientWindow->GetWindowRect(&MyRect);

  int Status_x, Status_y, Status_cx, Status_cy;
  Status_x = 10;
  Status_y = MyRect.bottom - MyRect.top - 30 - 30;
  Status_cx = MyRect.right - MyRect.left - 20;
  Status_cy = 30;
  m_wndStatusBar.SetWindowPos(clientWindow,Status_x, Status_y,
           Status_cx, Status_cy, SWP_NOZORDER | SWP_SHOWWINDOW);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.