Solved

afxcmn.inl debug assertion failure while setting text in a status bar hosted in a Dialog

Posted on 2004-08-04
7
1,358 Views
Last Modified: 2007-12-19
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:","Unattached:"};
CreateStatusBar(6,nPos,text,30);

The function to create the status is as follows:

void CImageViewerDlg::CreateStatusBar(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_CHILD | WS_BORDER |  WS_VISIBLE,rect,this,ID_MY_STATUS_BAR_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)*nPanes);
      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(nPanes,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:","Unattached:"};
CreateStatusBar(6,nPos,text,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::SetStatusBarText(int nPanes,const char *text[]){
      
      m_status_bar.SetText("100",1,0);
      //m_status_bar.SetText("200",3,0);
      //m_status_bar.SetText("300",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.



0
Comment
Question by:rxraza
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 11717395
What is the *exact* ASSERT message?
0
 

Author Comment

by:rxraza
ID: 11717480
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
0
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 11717521
Line 105 reads

ASSERT(::IsWindow(m_hWnd)); ASSERT(nPane < 256);

It seems that the status bar's window handle is invalid.
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

Author Comment

by:rxraza
ID: 11717562
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.
0
 
LVL 86

Expert Comment

by:jkr
ID: 11718351
>>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?
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 11718672
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::SetStatusBarText(int nPanes,const char *text[]){
     
     m_status_bar.SetText("100",1,0);
     //m_status_bar.SetText("200",3,0);
     //m_status_bar.SetText("300",5,0);
}

Why do you pass a text array but call it using text constants?

Regards, Alex






0
 

Author Comment

by:rxraza
ID: 11720797
I figured it out. I was setting text without first creating the status bar. Thanks for the help guys.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question