|
-
February 29th, 2012, 09:30 PM
#1
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.
-
March 1st, 2012, 04:44 AM
#2
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.
-
March 1st, 2012, 05:58 AM
#3
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
-
March 1st, 2012, 06:17 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|