rxraza
asked on
afxcmn.inl debug assertion failure while setting text in a status bar hosted in a Dialog
Hi folks:
I want to display a status bar on a dialog for that reason I have a protected member defined in the class as
CStatusBarCtrl m_status_bar
and creating the status bar by using the following three statements:
int nPos[] = {75,50,75,50,75,50};
const char *text[3] = {"Total:","Attached:","Una ttached:"} ;
CreateStatusBar(6,nPos,tex t,30);
The function to create the status is as follows:
void CImageViewerDlg::CreateSta tusBar(int nPanes,int nRight[],const char *text[],const int STATUS_BAR_HEIGHT){
CRect rect;
GetWindowRect(&rect);
rect.top = rect.bottom - STATUS_BAR_HEIGHT;
if (!m_status_bar.Create(WS_C HILD | WS_BORDER | WS_VISIBLE,rect,this,ID_MY _STATUS_BA R_1))
AfxMessageBox("Error in creating Status Bar");
else
m_status_bar.SetMinHeight( STATUS_BAR _HEIGHT);
// array specifies right edge position of each pane.
//int iWidths[nPanes];
int *iWidths = (int *)malloc(sizeof(int)*nPane s);
int running =0;
for(int i=0;i<nPanes;i++)
{
running += nRight[i];
*(iWidths + i) = rect.right - rect.right + running;
}
// span the last pane to fit the entire area
*(iWidths + i-1) = -1;
m_status_bar.SetParts(nPan es,iWidths );
for(i=0;i<nPanes;i = i+2)
m_status_bar.SetText(text[ i/2],i,0);
free(iWidths);
}
NOTE: THE ID_MY_STATUS_BAR_1 used in the function is a manual entry in the resource file. Following is its definition:
#define ID_MY_STATUS_BAR_1 9998
Now, the first time when I create the status bar on the dialog with the following statement it comes up fine
int nPos[] = {75,50,75,50,75,50};
const char *text[3] = {"Total:","Attached:","Una ttached:"} ;
CreateStatusBar(6,nPos,tex t,30);
When I try to put values for panes 1,3,5 later in the program it is throwing a debug assertion failure afxcmn.inl Line 105
The function to set text for panes is as follows:
void CImageViewerDlg::SetStatus BarText(in t nPanes,const char *text[]){
m_status_bar.SetText("100" ,1,0);
//m_status_bar.SetText("20 0",3,0);
//m_status_bar.SetText("30 0",5,0);
}
For the sake of clearity I have removed the generic coding that sets the text and hard coded the text that need to be set.
Can someone help me find what I am doing wrong:
NOtE: the same code works for a status bar in a different dialog which gets displayed prior to this one which is not setting the text correctly.
I want to display a status bar on a dialog for that reason I have a protected member defined in the class as
CStatusBarCtrl m_status_bar
and creating the status bar by using the following three statements:
int nPos[] = {75,50,75,50,75,50};
const char *text[3] = {"Total:","Attached:","Una
CreateStatusBar(6,nPos,tex
The function to create the status is as follows:
void CImageViewerDlg::CreateSta
CRect rect;
GetWindowRect(&rect);
rect.top = rect.bottom - STATUS_BAR_HEIGHT;
if (!m_status_bar.Create(WS_C
AfxMessageBox("Error in creating Status Bar");
else
m_status_bar.SetMinHeight(
// array specifies right edge position of each pane.
//int iWidths[nPanes];
int *iWidths = (int *)malloc(sizeof(int)*nPane
int running =0;
for(int i=0;i<nPanes;i++)
{
running += nRight[i];
*(iWidths + i) = rect.right - rect.right + running;
}
// span the last pane to fit the entire area
*(iWidths + i-1) = -1;
m_status_bar.SetParts(nPan
for(i=0;i<nPanes;i = i+2)
m_status_bar.SetText(text[
free(iWidths);
}
NOTE: THE ID_MY_STATUS_BAR_1 used in the function is a manual entry in the resource file. Following is its definition:
#define ID_MY_STATUS_BAR_1 9998
Now, the first time when I create the status bar on the dialog with the following statement it comes up fine
int nPos[] = {75,50,75,50,75,50};
const char *text[3] = {"Total:","Attached:","Una
CreateStatusBar(6,nPos,tex
When I try to put values for panes 1,3,5 later in the program it is throwing a debug assertion failure afxcmn.inl Line 105
The function to set text for panes is as follows:
void CImageViewerDlg::SetStatus
m_status_bar.SetText("100"
//m_status_bar.SetText("20
//m_status_bar.SetText("30
}
For the sake of clearity I have removed the generic coding that sets the text and hard coded the text that need to be set.
Can someone help me find what I am doing wrong:
NOtE: the same code works for a status bar in a different dialog which gets displayed prior to this one which is not setting the text correctly.
What is the *exact* ASSERT message?
ASKER
Debug Assertion Failed!
Program: 'path to the exe'
File: afxcmn.inl
Line: 105
For Information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts
(Please, retry to debug the application)
Abort Retry Ignore
Program: 'path to the exe'
File: afxcmn.inl
Line: 105
For Information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts
(Please, retry to debug the application)
Abort Retry Ignore
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Why would that be invalid? It is coming up fine when I display it the first time. Only when I try to set some text in, it is throwing that debug assertion failure.
>>It is coming up fine when I display it the first time. Only when I try to set some text in
There might be something wrong with the state of your object at that time. Is it possible that it went out of scope already or the m_hWnd member was overwritten?
There might be something wrong with the state of your object at that time. Is it possible that it went out of scope already or the m_hWnd member was overwritten?
Could you find out the value of 'm_hWnd' and 'nPane' in the assertion? If 'm_hWnd' is a valid window, you should see the windows class in the Debugger.
void CImageViewerDlg::SetStatus BarText(in t nPanes,const char *text[]){
m_status_bar.SetText("100" ,1,0);
//m_status_bar.SetText("20 0",3,0);
//m_status_bar.SetText("30 0",5,0);
}
Why do you pass a text array but call it using text constants?
Regards, Alex
void CImageViewerDlg::SetStatus
m_status_bar.SetText("100"
//m_status_bar.SetText("20
//m_status_bar.SetText("30
}
Why do you pass a text array but call it using text constants?
Regards, Alex
ASKER
I figured it out. I was setting text without first creating the status bar. Thanks for the help guys.