?
Solved

Problem with MainFrm.h file

Posted on 2005-03-14
34
Medium Priority
?
469 Views
Last Modified: 2013-11-20
Hello,

I created one SDI application through wizard. From the menu of SDI application i am opening "mode less dialog".
This is the code in CMainFrame class.
void CMainFrame::OnGraph()
{
   if (graph == NULL) {
     graph = new CGraph((CWnd*) this);
     BOOL ret=graph->Create(IDD_GRAPH,(CWnd*) this);
     graph->ShowWindow(SW_SHOW);
}

I need to aceess the some methods from other classes(modeless dialogs) in the project. For this i used this statement  "CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();" in CGraph class.
To compile this class with this satement i added  " #include "MainFrm.h" " in CGraph.cpp file.
I am getting this error in debug mode "User break point called from code at 0x77f75a58".

How can i overcome this problem?

Thnaks
0
Comment
Question by:vihar123
[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
  • 15
  • 10
  • 9
34 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 13534568
Stop in the debugger after getting this message and open Stack window. Post here current stack state from your own program line to the exception place.
0
 

Author Comment

by:vihar123
ID: 13534719
Thank you for your reply.

sorry i could't understand properly what you are asking.
After i got the above message, i pressed "Ok", in Disassembly window the arrow is showing the first line of below code
77F75A58   int         3
77F75A59   ret
77F75A5A   mov         edi,edi
77F75A5C   int         3
77F75A5D   ret
77F75A5E   mov         edi,edi
77F75A60   mov         eax,dword ptr [esp+4]
77F75A64   int         3
77F75A65   ret         4
77F75A68   push        268h
77F75A6D   push        77F51A40h
77F75A72   call        77FA5554
77F75A77   xor         ebx,ebx
77F75A79   xor         edi,edi
77F75A7B   cmp         dword ptr [ebp+0Ch],0FFFFFFFFh
77F75A7F   je          77F75A94
77F75A81   push        dword ptr [ebp+10h]
77F75A84   push        dword ptr [ebp+0Ch]

And i opened Call Stack window, i found following code.
 
NTDLL! 77f75a58()
NTDLL! 77f9d959()
NTDLL! 77f83eb1()
NTDLL! 77f589f2()
MSVCRTD! 1020e26c()
MSVCRTD! 10213002()
MSVCRTD! 10212de9()
MSVCRTD! 10212d6f()
operator new(unsigned int 68, int 1, const char * 0x5f4d096c THIS_FILE, int 72) line 373 + 22 bytes
operator new(unsigned int 68, const char * 0x5f4d096c THIS_FILE, int 72) line 65 + 19 bytes
CMapPtrToPtr::InitHashTable(unsigned int 17, int 1) line 72 + 19 bytes
CMapPtrToPtr::operator[](void * 0x060107ab) line 222
CHandleMap::SetPermanent(void * 0x060107ab, CObject * 0x0012f118 {hDC=0x060107ab attrib=0x00000000}) line 183 + 12 bytes
CDC::Attach(HDC__ * 0x060107ab) line 118
CWindowDC::CWindowDC(CWnd * 0x00000000 {CWnd hWnd=???}) line 1013 + 36 bytes
CGraph::CreateFontA() line 222 + 10 bytes
CGraph::CalculateValues() line 1156
CGraph::OnUpdate() line 1147
CGraph::OnInitDialog() line 144
AfxDlgProc(HWND__ * 0x008a06a4, unsigned int 272, unsigned int 1443384, unsigned int 1443384) line 35 + 14 bytes
USER32! 77d486cb()
USER32! 77d536ba()
USER32! 77d53524()
USER32! 77d53733()
USER32! 77d4879f()
USER32! 77d4aafa()
USER32! 77d4add4()
CWnd::DefWindowProcA(unsigned int 272, unsigned int 1443384, long 0) line 1011 + 32 bytes
CWnd::Default() line 258
CDialog::HandleInitDialog(unsigned int 1443384, unsigned int 1443384) line 624 + 8 bytes
CWnd::OnWndMsg(unsigned int 272, unsigned int 1443384, long 0, long * 0x0012f5f8) line 1826 + 17 bytes
CWnd::WindowProc(unsigned int 272, unsigned int 1443384, long 0) line 1596 + 30 bytes
AfxCallWndProc(CWnd * 0x003a6a48 {CGraph hWnd=???}, HWND__ * 0x008a06a4, unsigned int 272, unsigned int 1443384, long 0) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x008a06a4, unsigned int 272, unsigned int 1443384, long 0) line 379
AfxWndProcBase(HWND__ * 0x008a06a4, unsigned int 272, unsigned int 1443384, long 0) line 220 + 21 bytes
USER32! 77d486cb()
USER32! 77d4879f()
USER32! 77d4a37b()
USER32! 77d55f39()
50010000()


Looking forward for your reply..

0
 
LVL 48

Expert Comment

by:AlexFM
ID: 13534768
OK, I guess AfxGetMainWnd call is in one of the following functions:

CGraph::CalculateValues() line 1156
CGraph::OnUpdate() line 1147
CGraph::OnInitDialog() line 144

Please show this function.
One guess: do you try to call AfxGetMainWnd from the worker thread?
0
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 

Author Comment

by:vihar123
ID: 13534825

Thank you, these are the functions. And i did't called AfxGetMainWnd anywhere.
Please look into this.

BOOL CGraph::OnInitDialog()
{
      CDialog::OnInitDialog();
      
      CRect Rect;
      CSize m_size;
      GetClientRect(&Rect);
                Rect.NormalizeRect();
      m_size.cx = Rect.Width();    // zero based
                m_size.cy = Rect.Height();    // zero based
      m_clientRect.left = BORDER_OFFSET;
      m_clientRect.top = BORDER_OFFSET;
      m_clientRect.right = Rect.Width()-BORDER_OFFSET;
      m_clientRect.bottom = Rect.Height()-BORDER_OFFSET;

      m_BGColor = RGB(0,0,255);
                m_AxisColor = RGB(0,0,0);
                m_plotColor[0] = RGB(255,0,0); //Red
      m_plotColor[1] = RGB(0,0,255); //Blue
      m_plotColor[2] = RGB(0,255,0); //Green
      m_plotColor[3] = RGB(0,0,0);   //Black

      isMaxR = FALSE;
      isMaxG = FALSE;
      isMaxB = FALSE;
      bBkNeedToUpdate = TRUE;
      
      strChartTitle[0] = "Area1";
      strChartTitle[1] = "Area2";
      strChartTitle[2] = "Area3";

      strLabelX = "Number of Images" ;
      strLabelY = "Intensity" ;

      SetUserRange(USER_MIN_X,USER_MAX_X,USER_MIN_Y,USER_MAX_Y,0);
      SetUserRange(USER_MIN_X,USER_MAX_X,USER_MIN_Y,USER_MAX_Y,1);
      SetUserRange(USER_MIN_X,USER_MAX_X,USER_MIN_Y,USER_MAX_Y,2);

      max_y = 0;
      min_y = 0;
      max_x = 0;
      min_x = 0;
   
                lowerbound[0] = 0;
      upperbound[0] = 0;
      lowerbound[1] = 0;
      upperbound[1] = 0;
      lowerbound[2] = 0;
      upperbound[2] = 0;

      OnUpdate();

      return TRUE;  // return TRUE unless you set the focus to a control
                 // EXCEPTION: OCX Property Pages should return FALSE
}

void CGraph::CalculateValues()
{
      CreateFont();
      CalcRect() ;
      CalMaxMin(0);
      CalMaxMin(1);
      CalMaxMin(2);
      SetGridValues();
}

void CGraph::OnUpdate()
{
      CalculateValues();
      OnFullscale1();
      OnFullscale2();
      OnFullscale3();
      Invalidate();
}

Thankying you
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 13534960
Where are lines 1156, 1147 and 144? And how it is related with MainFrm.h from your question?
0
 

Author Comment

by:vihar123
ID: 13535040
Sorry i forget to indicate lines.  
If i want work with CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd(); , i have to include MainFrm.h. So the problem is arised.

BOOL CGraph::OnInitDialog()
{
     CDialog::OnInitDialog();
     
     CRect Rect;
     CSize m_size;
     GetClientRect(&Rect);
                Rect.NormalizeRect();
     m_size.cx = Rect.Width();    // zero based
                m_size.cy = Rect.Height();    // zero based
     m_clientRect.left = BORDER_OFFSET;
     m_clientRect.top = BORDER_OFFSET;
     m_clientRect.right = Rect.Width()-BORDER_OFFSET;
     m_clientRect.bottom = Rect.Height()-BORDER_OFFSET;

     m_BGColor = RGB(0,0,255);
                m_AxisColor = RGB(0,0,0);
                m_plotColor[0] = RGB(255,0,0); //Red
     m_plotColor[1] = RGB(0,0,255); //Blue
     m_plotColor[2] = RGB(0,255,0); //Green
     m_plotColor[3] = RGB(0,0,0);   //Black

     isMaxR = FALSE;
     isMaxG = FALSE;
     isMaxB = FALSE;
     bBkNeedToUpdate = TRUE;
     
     strChartTitle[0] = "Area1";
     strChartTitle[1] = "Area2";
     strChartTitle[2] = "Area3";

     strLabelX = "Number of Images" ;
     strLabelY = "Intensity" ;

     SetUserRange(USER_MIN_X,USER_MAX_X,USER_MIN_Y,USER_MAX_Y,0);
     SetUserRange(USER_MIN_X,USER_MAX_X,USER_MIN_Y,USER_MAX_Y,1);
     SetUserRange(USER_MIN_X,USER_MAX_X,USER_MIN_Y,USER_MAX_Y,2);

     max_y = 0;
     min_y = 0;
     max_x = 0;
     min_x = 0;
   
                lowerbound[0] = 0;
     upperbound[0] = 0;
     lowerbound[1] = 0;
     upperbound[1] = 0;
     lowerbound[2] = 0;    // 144 line ********************************************************
     upperbound[2] = 0;

     OnUpdate();

     return TRUE;  // return TRUE unless you set the focus to a control
                 // EXCEPTION: OCX Property Pages should return FALSE
}
void CGraph::OnBtnLoad()
{
      // TODO: Add your control notification handler code here
      char strFilter[] = { "LRN Files (*.lrn)|*.lrn|All Files (*.*)|*.*||" };
      CFileDialog FileDlg(TRUE, "lrn", NULL, 0, strFilter);
      FileDlg.m_ofn.lpstrTitle = "OpenFile";
      char path[_MAX_PATH],initialDir[_MAX_PATH];
      GetCurrentDirectory(_MAX_PATH,path);
      sprintf(initialDir,"%s\\llt",path);
      FileDlg.m_ofn.lpstrInitialDir = initialDir;

      if( FileDlg.DoModal() == IDOK )
      {
            CString fileName = FileDlg.GetPathName(); // This is selected file name with path

            ifstream data_file (fileName);

            data_file >> lowerbound[0] >> upperbound[0]
                        >> lowerbound[1] >> upperbound[1]
                          >> lowerbound[2] >> upperbound[2];

            this->xAxisCoR[0].clear();
            this->xAxisCoR[1].clear();
            this->xAxisCoR[2].clear();
            this->xAxisCoG[0].clear();
            this->xAxisCoG[1].clear();
            this->xAxisCoG[2].clear();
            this->xAxisCoB[0].clear();
            this->xAxisCoB[1].clear();
            this->xAxisCoB[2].clear();
            this->yAxisCoR[0].clear();
            this->yAxisCoR[1].clear();
            this->yAxisCoR[2].clear();
            this->yAxisCoG[0].clear();
            this->yAxisCoG[1].clear();
            this->yAxisCoG[2].clear();
            this->yAxisCoB[0].clear();
            this->yAxisCoB[1].clear();
            this->yAxisCoB[2].clear();

            double gx1, gy1, gx2, gy2, gx3, gy3;

          while(!data_file.eof())
            {
                  data_file >> gx1 >> gy1
                                >> gx2 >> gy2
                                >> gx3 >> gy3;

                  this->xAxisCoR[0].push_back(gx1);
                  this->yAxisCoR[0].push_back(gy1);

                  this->xAxisCoG[0].push_back(gx2);
                  this->yAxisCoG[0].push_back(gy2);

                  this->xAxisCoB[0].push_back(gx3);
                  this->yAxisCoB[0].push_back(gy3);
            }
          data_file.close();
            Invalidate();
      } // 1147 line  ****************************************
}

void CGraph::OnUpdate()
{
     CalculateValues();
     OnFullscale1();
     OnFullscale2();
     OnFullscale3();
     Invalidate();
}  // 1156 line ************************************************

void CGraph::CalculateValues()
{
     CreateFont();
     CalcRect() ;
     CalMaxMin(0);
     CalMaxMin(1);
     CalMaxMin(2);
     SetGridValues();
}

Thanks
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 13535231
I still don't understand. This is call stack:

CWindowDC::CWindowDC(CWnd * 0x00000000 {CWnd hWnd=???}) line 1013 + 36 bytes
CGraph::CreateFontA() line 222 + 10 bytes
CGraph::CalculateValues() line 1156
CGraph::OnUpdate() line 1147
CGraph::OnInitDialog() line 144

Obviously, the problem is that window is not created: CWnd * 0x00000000 {CWnd hWnd=???}

But line numbers are wrong:

lowerbound[2] = 0;    // 144 line *******************************************

This line doesn't call any other function and cannot be in the stack.

void CGraph::OnBtnLoad()
{
 ...
    } // 1147 line  ****************************************
}

OnBtnLoad is not in the stack but it's line appears in the stack. It looks like you provide wrong information. I need to see your own line (not MFC code), which causes this exception.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 13536992
Could you post the code of CGraph::CreateFont? The error might come from there.

>>>> CGraph::OnUpdate

Are you sure that on any *update* you have to call CreateFont, CalcRect and SetGridValues? I found in Google that CGraph::CreateFont doesn't free old resources. So, beside of the user break point you may get resource problems later.

Regards
0
 

Author Comment

by:vihar123
ID: 13542494
Thank you for your replies.
My code is perfect, if did't work with "MainFrm.h".
#include "MainFrm.h" if i add this in CGraph.cpp, problems are creating.

This is my CreateFont function.
void CGraph::CreateFont()
{
      //Create system font ..
      LOGFONT d_lf ;
      
      // Init desired font
      memset(&d_lf, 0, sizeof(LOGFONT));
      lstrcpy(d_lf.lfFaceName, "Times New Roman") ;

      // Initial font size
      // Get a screen DC
      CWindowDC wdc(NULL) ;
      const int cyPixels = wdc.GetDeviceCaps(LOGPIXELSY);
      d_lf.lfHeight = -1 * MulDiv(7, cyPixels, 72);

      // Create a new font 7 pts.
      pLegendFontY = new CFont() ;
      pLegendFontY->CreateFontIndirect(&d_lf);

      d_lf.lfHeight = -1 * MulDiv(12, cyPixels, 72);
      d_lf.lfWeight = FW_BOLD ;
      pTitleFont = new CFont();
      pTitleFont->CreateFontIndirect(&d_lf);


      d_lf.lfWeight = 0 ;
      d_lf.lfOrientation = 900 ; // Rotate font 90 degree for x axis
      d_lf.lfEscapement = 900 ;  
      d_lf.lfHeight = -1 * MulDiv(7, cyPixels, 72);
      pLegendFontX = new CFont() ;
      pLegendFontX->CreateFontIndirect(&d_lf);

}

Thanks
Looking forward for your reply.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 13542525
Well, now it is clear.

CWindowDC wdc(NULL) ;

CWindowDC constructor doesn't accept NULL parameter. Replace it with:

CWindowDC wdc(this) ;
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 13542547
Generally, when you have exception, you need to open Stack window in the debugger and find first function which is part of your project. In your case, you see the following stack:

NTDLL! 77f75a58()
NTDLL! 77f9d959()
NTDLL! 77f83eb1()
NTDLL! 77f589f2()
MSVCRTD! 1020e26c()
MSVCRTD! 10213002()
MSVCRTD! 10212de9()
MSVCRTD! 10212d6f()
operator new(unsigned int 68, int 1, const char * 0x5f4d096c THIS_FILE, int 72) line 373 + 22 bytes
operator new(unsigned int 68, const char * 0x5f4d096c THIS_FILE, int 72) line 65 + 19 bytes
CMapPtrToPtr::InitHashTable(unsigned int 17, int 1) line 72 + 19 bytes
CMapPtrToPtr::operator[](void * 0x060107ab) line 222
CHandleMap::SetPermanent(void * 0x060107ab, CObject * 0x0012f118 {hDC=0x060107ab attrib=0x00000000}) line 183 + 12 bytes
CDC::Attach(HDC__ * 0x060107ab) line 118
CWindowDC::CWindowDC(CWnd * 0x00000000 {CWnd hWnd=???}) line 1013 + 36 bytes
CGraph::CreateFontA() line 222 + 10 bytes
...

You can see that fist stack line which belongs to your project is:
CGraph::CreateFontA() line 222 + 10 bytes

Double-click it and it is opened in the text editor. Now you can understand what happens. If you want to ask in the message board, post your code:

void CGraph::CreateFont()
{
     CWindowDC wdc(NULL) ;
     ...
}

and ask why this line throws exception. In this case you will get right answer quickly.
0
 

Author Comment

by:vihar123
ID: 13542620
Thank you.
I followed your steps. Still it raised "User break point called from code at 0x77f75a58".
In the debug window i got this statement  "HEAP: Free Heap block 3a74b8 modified at 3a7530 after it was freed"
And in stack i got this.
NTDLL! 77f75a58()
NTDLL! 77f9d959()
NTDLL! 77f83eb1()
NTDLL! 77f589f2()
MSVCRTD! 1020e26c()
MSVCRTD! 10213002()
MSVCRTD! 10212de9()
MSVCRTD! 10212d6f()
operator new(unsigned int 68, int 1, const char * 0x5f4d096c THIS_FILE, int 72) line 373 + 22 bytes
operator new(unsigned int 68, const char * 0x5f4d096c THIS_FILE, int 72) line 65 + 19 bytes
CMapPtrToPtr::InitHashTable(unsigned int 17, int 1) line 72 + 19 bytes
CMapPtrToPtr::operator[](void * 0xbe010afb) line 222
CHandleMap::SetPermanent(void * 0xbe010afb, CObject * 0x0012f118 {hDC=0xbe010afb attrib=0x00000000}) line 183 + 12 bytes
CDC::Attach(HDC__ * 0xbe010afb) line 118
CWindowDC::CWindowDC(CWnd * 0x003a68a8 {CGraph hWnd=???}) line 1013 + 36 bytes
CGraph::CreateFontA() line 228 + 12 bytes
CGraph::CalculateValues() line 1162
CGraph::OnUpdate() line 1153
CGraph::OnInitDialog() line 149
AfxDlgProc(HWND__ * 0x001102b0, unsigned int 272, unsigned int 1311414, unsigned int 1311414) line 35 + 14 bytes
USER32! 77d486cb()
USER32! 77d536ba()
USER32! 77d53524()
USER32! 77d53733()
USER32! 77d4879f()
USER32! 77d4aafa()
USER32! 77d4add4()
CWnd::DefWindowProcA(unsigned int 272, unsigned int 1311414, long 0) line 1011 + 32 bytes
CWnd::Default() line 258
CDialog::HandleInitDialog(unsigned int 1311414, unsigned int 1311414) line 624 + 8 bytes
CWnd::OnWndMsg(unsigned int 272, unsigned int 1311414, long 0, long * 0x0012f5f8) line 1826 + 17 bytes
CWnd::WindowProc(unsigned int 272, unsigned int 1311414, long 0) line 1596 + 30 bytes
AfxCallWndProc(CWnd * 0x003a68a8 {CGraph hWnd=???}, HWND__ * 0x001102b0, unsigned int 272, unsigned int 1311414, long 0) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x001102b0, unsigned int 272, unsigned int 1311414, long 0) line 379
AfxWndProcBase(HWND__ * 0x001102b0, unsigned int 272, unsigned int 1311414, long 0) line 220 + 21 bytes
USER32! 77d486cb()
USER32! 77d4879f()
USER32! 77d4a37b()
USER32! 77d55f39()
50010000()


These are my functions, which are belongs to stack lines
void CGraph::CreateFont()
{
      //Create system font ..
      LOGFONT d_lf ;
      
      // Init desired font
      memset(&d_lf, 0, sizeof(LOGFONT));
      lstrcpy(d_lf.lfFaceName, "Times New Roman") ;

      // Initial font size
      // Get a screen DC
      //CWindowDC wdc(NULL) ;
      CWindowDC wdc(this) ;  // ***********line 228 + 12 bytes**************
      const int cyPixels = wdc.GetDeviceCaps(LOGPIXELSY);
      d_lf.lfHeight = -1 * MulDiv(7, cyPixels, 72);

      // Create a new font 7 pts.
      pLegendFontY = new CFont() ;
      pLegendFontY->CreateFontIndirect(&d_lf);

      d_lf.lfHeight = -1 * MulDiv(12, cyPixels, 72);
      d_lf.lfWeight = FW_BOLD ;
      pTitleFont = new CFont();
      pTitleFont->CreateFontIndirect(&d_lf);


      d_lf.lfWeight = 0 ;
      d_lf.lfOrientation = 900 ; // Rotate font 90 degree for x axis
      d_lf.lfEscapement = 900 ;  
      d_lf.lfHeight = -1 * MulDiv(7, cyPixels, 72);
      pLegendFontX = new CFont() ;
      pLegendFontX->CreateFontIndirect(&d_lf);

}

BOOL CGraph::OnInitDialog()
{
      CDialog::OnInitDialog();
      
      CRect Rect;
      CSize m_size;
      GetClientRect(&Rect);
    Rect.NormalizeRect();
      m_size.cx = Rect.Width();    // zero based
    m_size.cy = Rect.Height();    // zero based
      m_clientRect.left = BORDER_OFFSET;
      m_clientRect.top = BORDER_OFFSET;
      m_clientRect.right = Rect.Width()-BORDER_OFFSET;
      m_clientRect.bottom = Rect.Height()-BORDER_OFFSET;

      m_BGColor = RGB(0,0,255);
    m_AxisColor = RGB(0,0,0);
    m_plotColor[0] = RGB(255,0,0); //Red
      m_plotColor[1] = RGB(0,0,255); //Blue
      m_plotColor[2] = RGB(0,255,0); //Green
      m_plotColor[3] = RGB(0,0,0);   //Black

      isMaxR = FALSE;
      isMaxG = FALSE;
      isMaxB = FALSE;
      bBkNeedToUpdate = TRUE;
      
      strChartTitle[0] = "Area1";
      strChartTitle[1] = "Area2";
      strChartTitle[2] = "Area3";

      strLabelX = "Number of Images" ;
      strLabelY = "Intensity" ;

      SetUserRange(USER_MIN_X,USER_MAX_X,USER_MIN_Y,USER_MAX_Y,0);
      SetUserRange(USER_MIN_X,USER_MAX_X,USER_MIN_Y,USER_MAX_Y,1);
      SetUserRange(USER_MIN_X,USER_MAX_X,USER_MIN_Y,USER_MAX_Y,2);

      max_y = 0;
      min_y = 0;
      max_x = 0;
      min_x = 0;
   
    lowerbound[0] = 0;
      upperbound[0] = 0;
      lowerbound[1] = 0;
      upperbound[1] = 0;
      lowerbound[2] = 0;
      upperbound[2] = 0;

      OnUpdate();

      return TRUE;  // return TRUE unless you set the focus to a control    // ***********line 149**********************
                 // EXCEPTION: OCX Property Pages should return FALSE
}

void CGraph::OnUpdate()
{
      CalculateValues();
      OnFullscale1();    // **************line 1153*****************
      OnFullscale2();
      OnFullscale3();
      Invalidate();
}

void CGraph::CalculateValues()
{
      CreateFont();
      CalcRect() ;  //************line 1162***************
      CalMaxMin(0);
      CalMaxMin(1);
      CalMaxMin(2);
      SetGridValues();
}

void CGraph::OnFullscale1()
{
  CButton *check1 = (CButton*)GetDlgItem(IDC_FULLSCALE1);
      AddBounds();
      if(check1->GetCheck() == TRUE)
      {
            CalMaxMin(0);
            isMaxR = TRUE;
      }
      else
      {
            SetRange(user_min_x[0],user_max_x[0],user_min_y[0],user_max_y[0],0);
            isMaxR = FALSE;
      }

      Invalidate();      
}

void CGraph::CalcRect()
{
      int offsetX , offsetY;
      offsetY   = OFFSETY;
      offsetX   = OFFSETX;

      m_axisRect[0].left = m_clientRect.left + (offsetX);
      m_axisRect[0].top = m_clientRect.top + (offsetY);
      m_axisRect[0].right = m_clientRect.right - (offsetX/2);
      m_axisRect[0].bottom = (int)(m_clientRect.bottom/3) - (offsetY);

      m_axisRect[1].left = m_clientRect.left + (offsetX);
      m_axisRect[1].top = m_axisRect[0].bottom + 2*offsetY + offsetY/5 ;
      m_axisRect[1].right = m_clientRect.right - (offsetX/2);
      m_axisRect[1].bottom = (int)((2*m_clientRect.bottom)/3) - (offsetY)  ;

      m_axisRect[2].left = m_clientRect.left + (offsetX);
      m_axisRect[2].top = m_axisRect[1].bottom + 2*offsetY + offsetY/5;
      m_axisRect[2].right = m_clientRect.right - (offsetX/2);
      m_axisRect[2].bottom = (3*m_clientRect.bottom)/3 - (offsetY);

}


I did't understand what is the problem. Please help me.

Thanks
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 13542638
>>>>    pTitleFont = new CFont();    
>>>>   pLegendFontX = new CFont() ;

Could you check if pTitleFont and pLegendFontX are members of class CGraph? Also, if they got deleted in the destructor of CGraph?

In any case, if you are calling CGraph::CreateFont more than once, you'll get memory leaks as the old pointers were not deleted. You should do the following changes:

    if (pTitleFont != NULL)
         delete pTitleFont;
    pTitleFont = new CFont();    
    ....    
    if (pLegendFontX != NULL)
         delete pLegendFontX;
    pLegendFontX = new CFont();    
    ...

>>>> CWindowDC wdc(NULL) ;

The parameter should be the current dialog window. It seems that CGraph is derived from CDialog. If so, you could change the statement by

     CWindowDC wdc(this) ;

I hope for you that the rest of this class isn't as buggy as the CreateFont function.

Regards
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 13542750
Do you use threads in your program?
Make the following test: instead of creating modeless dialog call it using DoModal. Do you have the same exception or not?

The problem is in the following line:
CWindowDC::CWindowDC(CWnd * 0x003a68a8 {CGraph hWnd=???}) line 1013 + 36 bytes

hWnd=??? - this means that window is not created yet. But I don't understand why.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 13542867
>>>> hWnd=??? - this means that window is not created yet.

As CreateFont was called from OnUpdate and OnUpdate from OnInitDialog, there must be a valid window handle. OnInitDialog is a handler of the WM_INITDIALOG message that only could be sent to valid dialog windows. You should add a breakpoint to the beginning of OnInitDialog. Then watch the this pointer. It should always show a valid hwnd handle.

Could you post your final version of CGraph::CreateFont?

Another idea: Do you work with PreCompiled Header Files? Does the cpp file from above include the same precompiled header file than all other cpp files? Or is the file excluded from Precompiled Header option? Did you include mainfrm.h below or above Precompiled Header include?

Regards
0
 

Author Comment

by:vihar123
ID: 13542914
Thank you for your reply.
First i tried by doing  
if (pLegendFontX != NULL)
         delete pLegendFontX;
    pLegendFontX = new CFont();    

But i am getting this error "0xC0000005: Access Violation".

Please look into this.
0
 

Author Comment

by:vihar123
ID: 13542941
Thank you for your reply.

In other class i am using threds. From that thread i am upadating the points in this CGraph class.
And i tried by using  DoModal, but i am getting same problem.
This is the stack when i use DOModal()
NTDLL! 77f75a58()
NTDLL! 77f9d959()
NTDLL! 77f83eb1()
NTDLL! 77f589f2()
MSVCRTD! 1020e26c()
MSVCRTD! 10213002()
MSVCRTD! 10212de9()
MSVCRTD! 10212d6f()
operator new(unsigned int 68, int 1, const char * 0x5f4d096c THIS_FILE, int 72) line 373 + 22 bytes
operator new(unsigned int 68, const char * 0x5f4d096c THIS_FILE, int 72) line 65 + 19 bytes
CMapPtrToPtr::InitHashTable(unsigned int 17, int 1) line 72 + 19 bytes
CMapPtrToPtr::operator[](void * 0xa7010e98) line 222
CHandleMap::SetPermanent(void * 0xa7010e98, CObject * 0x0012f154 {hDC=0xa7010e98 attrib=0x00000000}) line 183 + 12 bytes
CDC::Attach(HDC__ * 0xa7010e98) line 118
CWindowDC::CWindowDC(CWnd * 0x003a6a48 {CGraph hWnd=???}) line 1013 + 36 bytes
CGraph::CreateFontA() line 231 + 12 bytes
CGraph::CalculateValues() line 1172
CGraph::OnUpdate() line 1163
CGraph::OnInitDialog() line 152
AfxDlgProc(HWND__ * 0x002603fc, unsigned int 272, unsigned int 1311656, unsigned int 1311656) line 35 + 14 bytes
USER32! 77d486cb()
USER32! 77d536ba()
USER32! 77d53524()
USER32! 77d53733()
USER32! 77d4879f()
USER32! 77d4aafa()
USER32! 77d4add4()
CWnd::DefWindowProcA(unsigned int 272, unsigned int 1311656, long 0) line 1011 + 32 bytes
CWnd::Default() line 258
CDialog::HandleInitDialog(unsigned int 1311656, unsigned int 1311656) line 624 + 8 bytes
CWnd::OnWndMsg(unsigned int 272, unsigned int 1311656, long 0, long * 0x0012f634) line 1826 + 17 bytes
CWnd::WindowProc(unsigned int 272, unsigned int 1311656, long 0) line 1596 + 30 bytes
AfxCallWndProc(CWnd * 0x003a6a48 {CGraph hWnd=???}, HWND__ * 0x002603fc, unsigned int 272, unsigned int 1311656, long 0) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x002603fc, unsigned int 272, unsigned int 1311656, long 0) line 379
AfxWndProcBase(HWND__ * 0x002603fc, unsigned int 272, unsigned int 1311656, long 0) line 220 + 21 bytes
USER32! 77d486cb()
USER32! 77d4879f()
USER32! 77d4a37b()
USER32! 77d55f39()
50020000()

Thanks
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 13542963
Is this dialog created in main thread or in other thread?
0
 

Author Comment

by:vihar123
ID: 13543057

Dialog i am not creating in my own thread. Creating dialog is in CMainFrm class. I am just updating some values needed to plot graph.

Thanks

0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 13543124
>>>> But i am getting this error "0xC0000005: Access Violation".

It seems that the members were not initialized in the constructor what is a further evidence of the poor quality. Initialize all pointer members to NULL in CGraph::CGraph.

Regards

0
 
LVL 48

Expert Comment

by:AlexFM
ID: 13543177
I have no idea why this happens, there is no enough information. Maybe you can make your project availavle for download, in this case I can do something.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 13543236
Did you debug the this pointer of CGraph?

Is there a valid hWnd handle in OnInitDialog? Or does it show hWnd=??? as well? You could watch the m_hWnd member of CGraph::CDialog::CWnd. It should be the valid window handle we are looking for?

What is with Precompiled Header files?

Where did you insert the #include "mainfrm.h" ?

0
 

Author Comment

by:vihar123
ID: 13543509
I initialized these pointer variables in OnInitDialog() function
pLegendFontX = NULL;
pLegendFontY = NULL;
pTitleFont = NULL;
Still i am getting this error "0xC0000005: Access Violation".

Yes i have valid m_hWnd handle in OnInitDialog(),  m_hWnd = 0x0012039e.

Here i kept  "MainFrm.h" file.
#include "stdafx.h"
#include "OplsSel.h"
#include "MainFrm.h"
#include "Graph.h"
#include "math.h"
#include "Bounds.h"
#include <fstream>
#include "vsSup.h"  

Thanks
Looking forward for your reply.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 13543810
>>>> if (pLegendFontX != NULL)
>>>>         delete pLegendFontX;
>>>>    pLegendFontX = new CFont();    

>>>> But i am getting this error "0xC0000005: Access Violation".

If you initialized the pointers to NULL (in OnInitDialog before call OnUpdate), you couldn't crash at the delete statement cause the if condition must be false. If pLegendFontX is not NULL when coming here, there are only two explanations:

1. There is a second thread that runs parallel and does the same OnUpdate.
2. The CGraph object is corrupted because of a previous bug.

As you contradicted having more than one thread, I would assume the second cause is true. That would also fit to the corrupted hWnd handle.

You should be able to find out what statement is corrupting the object by debugging step by step always watching the 'this' pointer still having a valid hWnd and the pointer pLegendFontX still being NULL.

Regards, Alex

BTW, as an additional test you should change includes of mainfrm.h and graph.h. I wonder if that had any impact.


0
 

Author Comment

by:vihar123
ID: 13544206
Yes you are right.
There is a second thread that runs parallel and does the same OnUpdate.
This is happening in OnSize() function.
void CGraph::OnSize(UINT nType, int cx, int cy)
{
      CDialog::OnSize(nType, cx, cy);
      
      // TODO: Add your message handler code here
      CRect Rect;
      CSize m_size;
      GetClientRect(&Rect);
                Rect.NormalizeRect();
      m_size.cx = Rect.Width();    // zero based
                m_size.cy = Rect.Height();    // zero based
      m_clientRect.left = BORDER_OFFSET;
      m_clientRect.top = BORDER_OFFSET;
      m_clientRect.right = Rect.Width()-BORDER_OFFSET;
      m_clientRect.bottom = Rect.Height()-BORDER_OFFSET;

      CWnd* btn1 = GetDlgItem(IDC_BUTTON1);
      CWnd* btn2 = GetDlgItem(IDC_BUTTON2);
      CWnd* btn3 = GetDlgItem(IDC_BUTTON3);
      CWnd* load_btn = GetDlgItem(IDC_BTN_LOAD);
      CWnd* save_btn = GetDlgItem(IDC_BTN_SAVE);
      CWnd* cb1 = GetDlgItem(IDC_FULLSCALE1);
      CWnd* cb2 = GetDlgItem(IDC_FULLSCALE2);
      CWnd* cb3 = GetDlgItem(IDC_FULLSCALE3);

    if(btn1 != NULL)
        btn1->SetWindowPos(NULL, cx-BORDER_OFFSET-65,20, cx, cy, SWP_SHOWWINDOW | SWP_NOSIZE);
      if(btn2 != NULL)
        btn2->SetWindowPos(NULL, cx-BORDER_OFFSET-65,cy/3+20, cx, cy, SWP_SHOWWINDOW | SWP_NOSIZE);
      if(btn3 != NULL)
        btn3->SetWindowPos(NULL, cx-BORDER_OFFSET-65,2*cy/3+20, cx, cy, SWP_SHOWWINDOW | SWP_NOSIZE);

      if(load_btn!= NULL)
        load_btn->SetWindowPos(NULL, cx/3,BORDER_OFFSET+5, cx, cy, SWP_SHOWWINDOW | SWP_NOSIZE);
      if(save_btn != NULL)
        save_btn->SetWindowPos(NULL, 2*cx/3,BORDER_OFFSET+5, cx, cy, SWP_SHOWWINDOW | SWP_NOSIZE);

      if(cb1 != NULL)
        cb1->SetWindowPos(NULL, BORDER_OFFSET+5,20, cx, cy, SWP_SHOWWINDOW | SWP_NOSIZE);
      if(cb2 != NULL)
        cb2->SetWindowPos(NULL, BORDER_OFFSET+5,cy/3+20, cx, cy, SWP_SHOWWINDOW | SWP_NOSIZE);
      if(cb3 != NULL)
        cb3->SetWindowPos(NULL, BORDER_OFFSET+5,2*cy/3+20, cx, cy, SWP_SHOWWINDOW | SWP_NOSIZE);


      strChartTitle[0] = "Area1";
      strChartTitle[1] = "Area2";
      strChartTitle[2] = "Area3";
      strLabelX = "Number of Images" ;
      strLabelY = "Intensity" ;
    m_BGColor = RGB(0,0,255);
    m_AxisColor = RGB(0,0,0);

      if(isDialogConstructed == TRUE){
            CalculateValues();

            if(isMaxR == TRUE)  
            {
                  CalMaxMin(0);
            }
            else
            {
                  SetRange(user_min_x[0],user_max_x[0],user_min_y[0],user_max_y[0],0);
            
            }

            if(isMaxG == TRUE)  
            {
                  CalMaxMin(1);
            }
            else
            {
                  SetRange(user_min_x[1],user_max_x[1],user_min_y[1],user_max_y[1],1);
            }

            if(isMaxB == TRUE)  
            {
                  CalMaxMin(2);
            }
            else
            {
                  SetRange(user_min_x[2],user_max_x[2],user_min_y[2],user_max_y[2],2);
            }
      
            Invalidate();
      }      
}

In OnSize() function i kept break point and i watched m_hWnd.
If i include MainFrm.h file in CGraph.cpp, until the end of OnSize() function m_hWnd control is available.
After finishes this OnSize() function it is calling some windows code, at some point m_hWnd is loosing.

If i did't include MainFrm.h, there is no problem.

Thanks
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 13544695
Actually, I couldn't see any second thread that is invoked in the OnSize function.

Note, your dialog runs an own message infinite message loop that simplified has code like that:

    while(GetMessage(Msg))
          DispatchMessage(Msg);

That loop is infinite until a WM_QUIT message was generated. The DispatchMessage calls all your On... handlers, e. g. as response of a WM_INITDIALOG message posted after the dialog was created, the OnInitDialog member function was called. If you leave a handler function, e. g. OnSize(), you'll get out of the class context as CGraph::OnSize has been called via function pointer. That means after OnSize function all your class member cannot be watched but that isn't an evidence of a corrupted object.

To verify what goes wrong - after including mainfrm.h - you need to debug from OnInitDialog up to CreateFont but not in OnSize() as we should minimize the efforts. You said the program crashes when first deleting one of the font pointers, though you set the pointer to NULL some steps before. If that observation of yours is true, you should do the following:

- set a breakpoint at the beginning of CGraph::OnInitDialog, say at the last line where
   you initialized the font pointers.
- set a breakpoint to the beginning of any other CGraph::On... handler function
- put all font pointers to watch window and verify that all are NULL
- add the this pointer to watch window
- step to OnUpdate call (always verify the pointers and hwnd)
- step into OnUpdate
- step into CreateFont
- step to the if condition regarding the first font pointer.
- verify that the delete statement wasn't executed
- step by step til it crashes or til the pointers or hwnd get invalid

If one of the crashes actually happens at the first call of OnInitDialog you should be able to spot the invalid statement this way. If a second thread comes to play (???) your debug session suddenly should switch to one of the other On... handler function. As the code I saw above isn't thread-safe that shortly would corrupt your dialog object.


>>>> If i did't include MainFrm.h, there is no problem.

That is still very strange as mainfrm.h isn't very special. It has no includes but simply declares two wizard-generated derivations of MFC classes. Actually it isn't a recommendable sample of a C++ header file as any C++ header should include all baseclass header files and *not* expect that these have been included before.

Could you post stdafx.h, oplsels.h, mainfrm.h and graph.h? I have some suspicion that one of these header files isn't unique, so you should open the files by right-clicking on the filename in the include statement and choose 'Open Document "stdafx.h"' option. After opening the file you should verify that you opened the file you wanted to open by verifying the path name in the Properties popup (ALT+ENTER).

Regards, Alex

0
 

Author Comment

by:vihar123
ID: 13545109
These are the header files for four classes.

// MainFrm.h : interface of the CMainFrame class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_MAINFRM_H__CA971C67_46BC_4D8F_98A2_5B0E62779FBD__INCLUDED_)
#define AFX_MAINFRM_H__CA971C67_46BC_4D8F_98A2_5B0E62779FBD__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "ROIImage.h"
#include "Graph.h"
#include "PropertyFrame.h"
#include <fstream>

class CMainFrame : public CFrameWnd
{

protected: // create from serialization only
      CMainFrame();
      DECLARE_DYNCREATE(CMainFrame)

// Attributes
public:
      CROIImage *img;
      CGraph *graph;
      CVSPropertySheet* m_vsPSheet;
      
// Operations
public:

// Overrides
      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(CMainFrame)
      public:
      virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
      //}}AFX_VIRTUAL

// Implementation
public:
      void GenerateValues();
      void OnBounds(WPARAM wparam,LPARAM lparam);
      
      virtual ~CMainFrame();
#ifdef _DEBUG
      virtual void AssertValid() const;
      virtual void Dump(CDumpContext& dc) const;
#endif

protected:  // control bar embedded members
      CStatusBar  m_wndStatusBar;
      CToolBar    m_wndToolBar;

// Generated message map functions
protected:
      CPropertyFrame* m_pPropFrame;
      //{{AFX_MSG(CMainFrame)
      afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
      afx_msg void OnRoiimage();
      afx_msg void OnRoiimageClose();
      afx_msg void OnGraph();
      afx_msg void OnGraphClose();
      afx_msg void OnTimer(UINT nIDEvent);
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MAINFRM_H__CA971C67_46BC_4D8F_98A2_5B0E62779FBD__INCLUDED_)


**************************************************************************************

// stdafx.h : include file for standard system include files,
//  or project specific include files that are used frequently, but
//      are changed infrequently
//
#if !defined(AFX_STDAFX_H__468A9B05_7576_41B8_B3A5_64EE13B55ECC__INCLUDED_)
#define AFX_STDAFX_H__468A9B05_7576_41B8_B3A5_64EE13B55ECC__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define VC_EXTRALEAN            // Exclude rarely-used stuff from Windows headers

#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions
#include <afxdisp.h>        // MFC Automation classes
#include <afxdtctl.h>            // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>                  // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT


//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_STDAFX_H__468A9B05_7576_41B8_B3A5_64EE13B55ECC__INCLUDED_)

*********************************************************************************************

// OplsSel.h : main header file for the OPLSSEL application
//

#if !defined(AFX_OPLSSEL_H__10764282_245A_44ED_BD0B_8978354098A6__INCLUDED_)
#define AFX_OPLSSEL_H__10764282_245A_44ED_BD0B_8978354098A6__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
      #error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h"       // main symbols

/////////////////////////////////////////////////////////////////////////////
// COplsSelApp:
// See OplsSel.cpp for the implementation of this class
//

class COplsSelApp : public CWinApp
{
public:
      COplsSelApp();

// Overrides
      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(COplsSelApp)
      public:
      virtual BOOL InitInstance();
      //}}AFX_VIRTUAL

// Implementation
      //{{AFX_MSG(COplsSelApp)
      afx_msg void OnAppAbout();
            // NOTE - the ClassWizard will add and remove member functions here.
            //    DO NOT EDIT what you see in these blocks of generated code !
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()
};


/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_OPLSSEL_H__10764282_245A_44ED_BD0B_8978354098A6__INCLUDED_)

************************************************************************************************

#if !defined(AFX_GRAPH_H__D19C70D4_931C_47FE_96E8_9B69929A2CC3__INCLUDED_)
#define AFX_GRAPH_H__D19C70D4_931C_47FE_96E8_9B69929A2CC3__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Graph.h : header file
//
#include <vector>
#include "Bounds.h"      // Added by ClassView
using namespace std;


#define BORDER_OFFSET 10
#define MAX 1
#define MIN 0
#define OFFSETX 50
#define OFFSETY 50

#define USER_MIN_X 0
#define USER_MAX_X 1000
#define USER_MIN_Y 0
#define USER_MAX_Y 300

/////////////////////////////////////////////////////////////////////////////
// CGraph dialog

class CGraph : public CDialog
{
// Construction
public:
      CBounds m_boundsDlg;

      CGraph(vsSupport* vsUIS, CWnd* pParent = NULL);   // standard constructor
      ~CGraph();

      vsSupport* vsUIS;
      vs* vs;

      BOOL SetUserRange(double minX, double maxX, double minY, double maxY,int graphno);   // Sets user defined minimum and maximum values for x and y axes
      void SetPoints(std::vector<double> &x_coordinate, std::vector<double> &y_coordinate,int index);   // Sets new points to be drawn
      

// Dialog Data
      //{{AFX_DATA(CGraph)
      enum { IDD = IDD_DLG_BOUNDS };
      //}}AFX_DATA


// Overrides
      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(CGraph)
      protected:
      virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
      //}}AFX_VIRTUAL

// Implementation
protected:

      // Generated message map functions
      //{{AFX_MSG(CGraph)
      virtual void OnOK();
      virtual void OnCancel();
      afx_msg void OnClose();
      virtual BOOL OnInitDialog();
      afx_msg void OnPaint();
      afx_msg void OnSize(UINT nType, int cx, int cy);
      afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
      afx_msg void OnFullscale1();
      afx_msg void OnFullscale2();
      afx_msg void OnFullscale3();
      afx_msg void OnButton1();
      afx_msg void OnButton2();
      afx_msg void OnButton3();
      afx_msg void OnBtnSave();
      afx_msg void OnBtnLoad();
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()
private:

      CRect  m_clientRect;
      CRect m_axisRect[3];
      COLORREF m_BGColor;
      COLORREF m_AxisColor ;
      COLORREF m_plotColor[4] ;
      CString strLabelX, strLabelY ;
      CString strChartTitle[3];
      CFont *pLegendFontY ;
      CFont *pLegendFontX ;
      CFont *pTitleFont;
      int nGridY, nGridX ;
      double dResY[3], dResX[3] ;
      double dRangeY[2][3], dRangeX[2][3];
      double min_x,min_y,max_x,max_y;
      double user_min_x[3],user_min_y[3],user_max_x[3],user_max_y[3];
    BOOL bBkNeedToUpdate;
      BOOL isMaxR,isMaxG,isMaxB;
      int lowerbound[3],upperbound[3];
      BOOL isDialogConstructed;

      CDC memBkDC;
      CBitmap m_BkBitmap;
      CBitmap *m_pOldBkBitmap;
            
      vector<double> xAxisCoR[3];
      vector<double> yAxisCoR[3];
      vector<double> xAxisCoG[3];
      vector<double> yAxisCoG[3];
      vector<double> xAxisCoB[3];
      vector<double> yAxisCoB[3];


      void CalculateValues();  //Caculates when all values when new data wants to draw.
      void DrawBackGround(CDC *pDC);  // Draws back ground
      CPoint Corrdinate(double x, double y,int graphno); //Calulates point to be drawn .
      void SetGridValues();   //Computes the number of divisions on Both axes
      void CreateFont();  // Get system font for label draw
      void ResCalc(int graphno);  // Compute resolution per dot
      void CalcRect();   // Compute rectangle
      void DrawBorder(CDC *pDC);     //Draws border for dialog
      void DrawChartTitle(CDC *pDC); //Draws chart title
      void DrawAxis(CDC *pDC);       //Draws axes
      void DrawGridLabel(CDC *pDC); //Draws labels for grid
      void Plot(CDC *pDC);          //Draws graph
      void OnUpdate(WPARAM wparam, LPARAM lparam);      //Calls when new points wants to draw
      void CalMaxMin(int graphno);   // Computes the maximum and minimum values for each graph
      void SetBounds(int lowerbound,int upperbound,int graphno);   //Sets lower and upper bounds  
      void AddBounds();   // Updates data with new bounds
      BOOL SetRange( double dMinX, double dMaxX, double dMinY, double dMaxY,int graphno); // Sets min and maximum values for x and y axes
      BOOL SetXYValue(double x, double y, int index);
      
};



//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.



#endif // !defined(AFX_GRAPH_H__D19C70D4_931C_47FE_96E8_9B69929A2CC3__INCLUDED_)


Thanks
0
 

Author Comment

by:vihar123
ID: 13545192
And i checked in debug mode.
I am getting exception in CreateFont() function
At this CWindowDC wdc(this)  statement , symbol m_hWnd is not found.


Thanks
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 1500 total points
ID: 13546140
>>>> mainfrm.h

You should remove all includes from mainfrm.h and use forward declarations instead of these

// forward declarations
class CGraph;
class CROIImage;
class CVSPropertySheet;

You only need the includes in mainfrm.cpp and put them below #include "mainfrm.h".

>>>> At this CWindowDC wdc(this) , symbol m_hWnd is not found

I never used CWindowDC before. It's a DC (device context) that covers both client area and non-client area. Maybe it has problems because mainframe and chart dialog have different message loops. If the change of mainfrm.h doesn't help you could replace CWindowsDC by CClientDC that only covers the client area (dialog). The dc should be valid for the following GetDeviceCaps as well (though I don't believe that there is the problem).

Regards, Alex


0
 

Author Comment

by:vihar123
ID: 13546561
Thank you.

If i use forward declerations its not working.
I gave this in CMainFrm.h
class CROIImage;

Like below many compilation errors are coming.
 'CROIImage' : class has no constructors.
Actually the of constructor of CROIImage is   " CROIImage(vsSupport* vsUIS, CWnd* pParent = NULL);"

Is there any special rules or locations to use forward declerations?


Thanks in advance.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 13546821
As I told you, you have to include #include "ROIImage.h" in mainfrm.cpp as well as the other #include statements you removed from mainfrm.h. After that you need a "Rebuild All" because of header file changes.

>>>> Is there any special rules or locations to use forward declerations?

Yes, you may use forward declarations in a header file instead of including the class header where the class is defined if and only if the the header uses only pointers or references of that class( ROIImage* or ROIImage&). If you have a baseclass or an object member or a function argument  that passes a class variable by value, forward declarations are not sufficient and you need to include the appropriate header file. But the latter does not apply to mainfrm.h as only pointer members are used.

Regards, Alex

0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 13546857
The compile errors you get are because not all cpp files that are needing one or more of these headers actually include the needed header files. Instead, these cpp files - where you get compile errors - only included mainfrm.h where you removed the #include statements. Check the compile errors on which classes are involved and add the corresponding header include to the include list.

Regards, Alex
0
 

Author Comment

by:vihar123
ID: 13553806
Thank you very much for your replies.

First i tried with CClientDC instead of CWindowsDC. But still i got the same runtime error.
Then i tried with forward declerations.
But with forward declerations, i have one problem.
I am sending messages from one dialog to another dialog, by using CMainFrm class.
This is the code in "CPropertyPage1.cpp", I am sending message from this dialog to CROIImage.cpp dialog through CMainFrm class.
CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
    if ( pMainFrame->img )
       pMainFrame->img->SendMessage(UM_ROIRESET, 0,0);  // img is the pointer CROIImage *img;  in CMainFrm.h

If i declared forward decleration "class CROIImage" in "CMainFrm.h" and i declared #include "ROIImage.h" in "CMainFrm.cpp".
But i am getting errors like
"error C2227: left of '->SendMessageA' must point to class/struct/union"
"error C2027: use of undefined type 'CROIImage'"

Please look into my problem.

Thanks
0
 

Author Comment

by:vihar123
ID: 13556042
Thank you very much

I used the forward declerations in MainFrm.h, its worked well.

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

764 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