sunshine737
asked on
Problem with MainFrm.h file
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_GRAP H,(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
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_GRAP
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
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
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.
ASKER
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::InitHashTabl e(unsigned int 17, int 1) line 72 + 19 bytes
CMapPtrToPtr::operator[](v oid * 0x060107ab) line 222
CHandleMap::SetPermanent(v oid * 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(unsig ned 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..
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::InitHashTabl
CMapPtrToPtr::operator[](v
CHandleMap::SetPermanent(v
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(unsig
CWnd::Default() line 258
CDialog::HandleInitDialog(
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..
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?
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?
ASKER
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_OFFSE
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,US
SetUserRange(USER_MIN_X,US
SetUserRange(USER_MIN_X,US
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
Where are lines 1156, 1147 and 144? And how it is related with MainFrm.h from your question?
ASKER
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_OFFSE T;
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,US ER_MAX_X,U SER_MIN_Y, USER_MAX_Y ,0);
SetUserRange(USER_MIN_X,US ER_MAX_X,U SER_MIN_Y, USER_MAX_Y ,1);
SetUserRange(USER_MIN_X,US ER_MAX_X,U SER_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_P ATH,path);
sprintf(initialDir,"%s\\ll t",path);
FileDlg.m_ofn.lpstrInitial Dir = 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_bac k(gx1);
this->yAxisCoR[0].push_bac k(gy1);
this->xAxisCoG[0].push_bac k(gx2);
this->yAxisCoG[0].push_bac k(gy2);
this->xAxisCoB[0].push_bac k(gx3);
this->yAxisCoB[0].push_bac k(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
If i want work with CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd
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_OFFSE
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,US
SetUserRange(USER_MIN_X,US
SetUserRange(USER_MIN_X,US
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
GetCurrentDirectory(_MAX_P
sprintf(initialDir,"%s\\ll
FileDlg.m_ofn.lpstrInitial
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_bac
this->yAxisCoR[0].push_bac
this->xAxisCoG[0].push_bac
this->yAxisCoG[0].push_bac
this->xAxisCoB[0].push_bac
this->yAxisCoB[0].push_bac
}
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
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.
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.
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
>>>> 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
ASKER
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(LOGPIXEL SY);
d_lf.lfHeight = -1 * MulDiv(7, cyPixels, 72);
// Create a new font 7 pts.
pLegendFontY = new CFont() ;
pLegendFontY->CreateFontIn direct(&d_ lf);
d_lf.lfHeight = -1 * MulDiv(12, cyPixels, 72);
d_lf.lfWeight = FW_BOLD ;
pTitleFont = new CFont();
pTitleFont->CreateFontIndi rect(&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->CreateFontIn direct(&d_ lf);
}
Thanks
Looking forward for your reply.
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(LOGPIXEL
d_lf.lfHeight = -1 * MulDiv(7, cyPixels, 72);
// Create a new font 7 pts.
pLegendFontY = new CFont() ;
pLegendFontY->CreateFontIn
d_lf.lfHeight = -1 * MulDiv(12, cyPixels, 72);
d_lf.lfWeight = FW_BOLD ;
pTitleFont = new CFont();
pTitleFont->CreateFontIndi
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->CreateFontIn
}
Thanks
Looking forward for your reply.
Well, now it is clear.
CWindowDC wdc(NULL) ;
CWindowDC constructor doesn't accept NULL parameter. Replace it with:
CWindowDC wdc(this) ;
CWindowDC wdc(NULL) ;
CWindowDC constructor doesn't accept NULL parameter. Replace it with:
CWindowDC wdc(this) ;
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::InitHashTabl e(unsigned int 17, int 1) line 72 + 19 bytes
CMapPtrToPtr::operator[](v oid * 0x060107ab) line 222
CHandleMap::SetPermanent(v oid * 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.
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::InitHashTabl
CMapPtrToPtr::operator[](v
CHandleMap::SetPermanent(v
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.
ASKER
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::InitHashTabl e(unsigned int 17, int 1) line 72 + 19 bytes
CMapPtrToPtr::operator[](v oid * 0xbe010afb) line 222
CHandleMap::SetPermanent(v oid * 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(unsig ned 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(LOGPIXEL SY);
d_lf.lfHeight = -1 * MulDiv(7, cyPixels, 72);
// Create a new font 7 pts.
pLegendFontY = new CFont() ;
pLegendFontY->CreateFontIn direct(&d_ lf);
d_lf.lfHeight = -1 * MulDiv(12, cyPixels, 72);
d_lf.lfWeight = FW_BOLD ;
pTitleFont = new CFont();
pTitleFont->CreateFontIndi rect(&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->CreateFontIn direct(&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_OFFSE T;
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,US ER_MAX_X,U SER_MIN_Y, USER_MAX_Y ,0);
SetUserRange(USER_MIN_X,US ER_MAX_X,U SER_MIN_Y, USER_MAX_Y ,1);
SetUserRange(USER_MIN_X,US ER_MAX_X,U SER_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_F ULLSCALE1) ;
AddBounds();
if(check1->GetCheck() == TRUE)
{
CalMaxMin(0);
isMaxR = TRUE;
}
else
{
SetRange(user_min_x[0],use r_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.bott om)/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
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::InitHashTabl
CMapPtrToPtr::operator[](v
CHandleMap::SetPermanent(v
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(unsig
CWnd::Default() line 258
CDialog::HandleInitDialog(
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(LOGPIXEL
d_lf.lfHeight = -1 * MulDiv(7, cyPixels, 72);
// Create a new font 7 pts.
pLegendFontY = new CFont() ;
pLegendFontY->CreateFontIn
d_lf.lfHeight = -1 * MulDiv(12, cyPixels, 72);
d_lf.lfWeight = FW_BOLD ;
pTitleFont = new CFont();
pTitleFont->CreateFontIndi
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->CreateFontIn
}
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_OFFSE
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,US
SetUserRange(USER_MIN_X,US
SetUserRange(USER_MIN_X,US
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_F
AddBounds();
if(check1->GetCheck() == TRUE)
{
CalMaxMin(0);
isMaxR = TRUE;
}
else
{
SetRange(user_min_x[0],use
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/
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.bott
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
>>>> 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
>>>> 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
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.
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.
>>>> 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
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
ASKER
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.
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.
ASKER
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::InitHashTabl e(unsigned int 17, int 1) line 72 + 19 bytes
CMapPtrToPtr::operator[](v oid * 0xa7010e98) line 222
CHandleMap::SetPermanent(v oid * 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(unsig ned 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
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::InitHashTabl
CMapPtrToPtr::operator[](v
CHandleMap::SetPermanent(v
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(unsig
CWnd::Default() line 258
CDialog::HandleInitDialog(
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
Is this dialog created in main thread or in other thread?
ASKER
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
>>>> 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
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
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.
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" ?
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" ?
ASKER
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.
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.
>>>> 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.
>>>> 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.
ASKER
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_OFFSE T;
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+2 0, 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(NUL L, cx/3,BORDER_OFFSET+5, cx, cy, SWP_SHOWWINDOW | SWP_NOSIZE);
if(save_btn != NULL)
save_btn->SetWindowPos(NUL L, 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],use r_max_x[0] ,user_min_ y[0],user_ max_y[0],0 );
}
if(isMaxG == TRUE)
{
CalMaxMin(1);
}
else
{
SetRange(user_min_x[1],use r_max_x[1] ,user_min_ y[1],user_ max_y[1],1 );
}
if(isMaxB == TRUE)
{
CalMaxMin(2);
}
else
{
SetRange(user_min_x[2],use r_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
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_OFFSE
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+2
if(btn3 != NULL)
btn3->SetWindowPos(NULL, cx-BORDER_OFFSET-65,2*cy/3
if(load_btn!= NULL)
load_btn->SetWindowPos(NUL
if(save_btn != NULL)
save_btn->SetWindowPos(NUL
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,
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],use
}
if(isMaxG == TRUE)
{
CalMaxMin(1);
}
else
{
SetRange(user_min_x[1],use
}
if(isMaxB == TRUE)
{
CalMaxMin(2);
}
else
{
SetRange(user_min_x[2],use
}
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
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
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
ASKER
These are the header files for four classes.
// MainFrm.h : interface of the CMainFrame class
//
////////////////////////// ////////// ////////// ////////// ////////// ////////// /
#if !defined(AFX_MAINFRM_H__CA 971C67_46B C_4D8F_98A 2_5B0E6277 9FBD__INCL UDED_)
#define AFX_MAINFRM_H__CA971C67_46 BC_4D8F_98 A2_5B0E627 79FBD__INC LUDED_
#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(CMainFra me)
// Attributes
public:
CROIImage *img;
CGraph *graph;
CVSPropertySheet* m_vsPSheet;
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMainFrame )
public:
virtual BOOL PreCreateWindow(CREATESTRU CT& 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__CA 971C67_46B C_4D8F_98A 2_5B0E6277 9FBD__INCL UDED_)
************************** ********** ********** ********** ********** ********** **********
// 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__468 A9B05_7576 _41B8_B3A5 _64EE13B55 ECC__INCLU DED_)
#define AFX_STDAFX_H__468A9B05_757 6_41B8_B3A 5_64EE13B5 5ECC__INCL UDED_
#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__468 A9B05_7576 _41B8_B3A5 _64EE13B55 ECC__INCLU DED_)
************************** ********** ********** ********** ********** ********** ********** *******
// OplsSel.h : main header file for the OPLSSEL application
//
#if !defined(AFX_OPLSSEL_H__10 764282_245 A_44ED_BD0 B_89783540 98A6__INCL UDED_)
#define AFX_OPLSSEL_H__10764282_24 5A_44ED_BD 0B_8978354 098A6__INC LUDED_
#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(COplsSelAp p)
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__10 764282_245 A_44ED_BD0 B_89783540 98A6__INCL UDED_)
************************** ********** ********** ********** ********** ********** ********** **********
#if !defined(AFX_GRAPH_H__D19C 70D4_931C_ 47FE_96E8_ 9B69929A2C C3__INCLUD ED_)
#define AFX_GRAPH_H__D19C70D4_931C _47FE_96E8 _9B69929A2 CC3__INCLU DED_
#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<doub le> &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(CDataExchan ge* 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__D19C 70D4_931C_ 47FE_96E8_ 9B69929A2C C3__INCLUD ED_)
Thanks
// MainFrm.h : interface of the CMainFrame class
//
//////////////////////////
#if !defined(AFX_MAINFRM_H__CA
#define AFX_MAINFRM_H__CA971C67_46
#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(CMainFra
// Attributes
public:
CROIImage *img;
CGraph *graph;
CVSPropertySheet* m_vsPSheet;
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMainFrame
public:
virtual BOOL PreCreateWindow(CREATESTRU
//}}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__CA
**************************
// 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__468
#define AFX_STDAFX_H__468A9B05_757
#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__468
**************************
// OplsSel.h : main header file for the OPLSSEL application
//
#if !defined(AFX_OPLSSEL_H__10
#define AFX_OPLSSEL_H__10764282_24
#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(COplsSelAp
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__10
**************************
#if !defined(AFX_GRAPH_H__D19C
#define AFX_GRAPH_H__D19C70D4_931C
#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<doub
// 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(CDataExchan
//}}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
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__D19C
Thanks
ASKER
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
I am getting exception in CreateFont() function
At this CWindowDC wdc(this) statement , symbol m_hWnd is not found.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
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
>>>> 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
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
Regards, Alex
ASKER
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->SendMessa ge(UM_ROIR ESET, 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
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->SendMessa
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
ASKER
Thank you very much
I used the forward declerations in MainFrm.h, its worked well.
I used the forward declerations in MainFrm.h, its worked well.