CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2007
    Location
    Bangalore,India
    Posts
    164

    Unhappy create statusBar in dialog problem

    I am trying to create a statusBar in the dialog but it's returning false. not creating the status bar please tell me whats going wrong in this. Thanks for any help. I am creating the status bar in the OnInitDialog() function

    Code:
    
    CStatusBar  m_wndStatusBar; // member variable in the dialog header.
    
    
    
    BOOL CDlgsViewDlg::OnInitDialog()
    {
    	CDialog::OnInitDialog();
    		if (!m_wndStatusBar.Create(this) ||
    		!m_wndStatusBar.SetIndicators(indicators,
    		  sizeof(indicators)/sizeof(UINT)))
    	{
    		TRACE0("Failed to create status bar\n");
    		return FALSE;      // fail to create
    	}
    
    	m_wndStatusBar.SetPaneText(0,L"MainWindow Initialized");
    }
    it's returning false. please help me.

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: create statusBar in dialog problem

    I've observed from your topics that you are trying to use CStatusBar, CToolBar as well as CView-derived classes in a dialog.
    Although it's not impossible, you may have noticed that normally, they are not working as expected.
    That's because they are designed to work in a frame window of an SDI/MDI framework and not in dialogs.

    So, in a dialog use CStatusBarCtrl, CToolBarCtrl and not CControlBar-derved like CStatusBar or CToolBar.
    Also, avoid CView-derived in dialogs.
    That may look a little bit more complicated but it's the easier way to prevent further headaches.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  3. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: create statusBar in dialog problem

    Here is an example of using CStatusBarCtrl in a dialog.

    Code:
    class CMyDialog : public CDialog
    {
       CStatusBarCtrl m_sbCtrl;
       void _CreateStatusBar();
       // ...
    };
    Code:
    BOOL CMyDialog::OnInitDialog()
    {
       CDialog::OnInitDialog();
    
       _CreateStatusBar();
       m_sbCtrl.SetText(_T("Baba Safta is ready"), 0, SBT_NOBORDERS);
       // ...
    }
    
    void CMyDialog::_CreateStatusBar()
    {
       DWORD dwStyle = WS_CHILD|WS_VISIBLE|CCS_BOTTOM|SBARS_SIZEGRIP;
       BOOL bRet = m_sbCtrl.Create(dwStyle, CRect(0,0,0,0), this, AFX_IDW_STATUS_BAR);
       ASSERT(bRet);
    
       m_sbCtrl.SetSimple(FALSE);
       const int nParts = 4;
       int pWidts[nParts] = {300, 350, 400, -1};
       m_sbCtrl.SetParts(nParts, pWidts);
    }
    
    void CMyDialog::OnSize(UINT nType, int cx, int cy) 
    {
       CDialog::OnSize(nType, cx, cy);
       if(NULL != m_sbCtrl.m_hWnd)
       {
          m_sbCtrl.SendMessage(WM_SIZE, (WPARAM)nType, MAKELPARAM(cx, cy));
       }
    }
    Note: this is just a brief example.
    You may want to modify/improve it, then have a look in MSDN Library: Using CStatusBarCtrl.
    Last edited by ovidiucucu; March 1st, 2012 at 06:33 AM. Reason: typo
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  4. #4
    Join Date
    Sep 2007
    Location
    Bangalore,India
    Posts
    164

    Re: create statusBar in dialog problem

    now it's working fine thanks for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured