madenai
June 8th, 2007, 06:09 AM
Hi,
I have this small MFC project which displays a grid on a dialog box.
//////////////////////////////////////////////////////////////////////////////////
// SimplePlotDlg.h
//
class CSimplePlotDlg : public CDialog
{
.
.
.
public:
CBrush Brush;
CPen m_GridPen;
CPen m_PlotPen;
CRect m_PlotRect;
CDC* m_dcArea;
public:
void Grid();
.
.
.
///////////////////////////////////////////////////////////////////////////////
// SimplePlotDlg.cpp
//
BOOL CSimplePlotDlg::OnInitDialog()
{
.
.
.
// TODO: Add extra initialization here
m_dcArea = m_Plot.GetDC();
m_PlotPen.CreatePen(PS_SOLID,1,RGB(255,0,0));
m_GridPen.CreatePen(PS_SOLID,1,RGB(0,120,0));
Brush.CreateSolidBrush(RGB(0,0,0));
m_Plot.GetClientRect(&m_PlotRect);
return TRUE; // return TRUE unless you set the focus to a control
}
.
.
.
///////////////////////////////////////////////////////////////////////////
void CSimplePlotDlg::Grid()
{
int i;
m_dcArea->SelectObject(Brush);
m_dcArea->SelectObject(m_GridPen);
m_dcArea->FillRect(&m_PlotRect,&Brush);
for (i = 1;i<(m_PlotRect.Width()/10);i++)
{
m_dcArea->MoveTo(i*((double)m_PlotRect.Width()/10),0);
m_dcArea->LineTo(i*((double)m_PlotRect.Width()/10),m_PlotRect.Height());
}
for (i = 1;i<(m_PlotRect.Height()/10);i++)
{
m_dcArea->MoveTo(0,m_PlotRect.Height()-i*((double)m_PlotRect.Height()/10));
m_dcArea->LineTo(m_PlotRect.Width(),m_PlotRect.Height()-i*((double)m_PlotRect.Height()/10));
}
}
///////////////////////////////////////////////////////////////////////////////
void CSimplePlotDlg::OnPlot()
{
// TODO: Add your control notification handler code here
Grid();
}
A button click from the dialog execute OnPlot and generate the grid.
I would like to generate this grid in the call of InitDialog() with the previous lines of code .
BOOL CSimplePlotDlg::OnInitDialog()
{
.
.
.
// TODO: Add extra initialization here
m_dcArea = m_Plot.GetDC();
m_PlotPen.CreatePen(PS_SOLID,1,RGB(255,0,0));
m_GridPen.CreatePen(PS_SOLID,1,RGB(0,120,0));
Brush.CreateSolidBrush(RGB(0,0,0));
m_Plot.GetClientRect(&m_PlotRect);
Grid(); <-------- HERE !
return TRUE; // return TRUE unless you set the focus to a control
}
.
.
.
However it doesn't work and works only on the button click !!(the above structure).
PS Project is attached
Regards
madenai
I have this small MFC project which displays a grid on a dialog box.
//////////////////////////////////////////////////////////////////////////////////
// SimplePlotDlg.h
//
class CSimplePlotDlg : public CDialog
{
.
.
.
public:
CBrush Brush;
CPen m_GridPen;
CPen m_PlotPen;
CRect m_PlotRect;
CDC* m_dcArea;
public:
void Grid();
.
.
.
///////////////////////////////////////////////////////////////////////////////
// SimplePlotDlg.cpp
//
BOOL CSimplePlotDlg::OnInitDialog()
{
.
.
.
// TODO: Add extra initialization here
m_dcArea = m_Plot.GetDC();
m_PlotPen.CreatePen(PS_SOLID,1,RGB(255,0,0));
m_GridPen.CreatePen(PS_SOLID,1,RGB(0,120,0));
Brush.CreateSolidBrush(RGB(0,0,0));
m_Plot.GetClientRect(&m_PlotRect);
return TRUE; // return TRUE unless you set the focus to a control
}
.
.
.
///////////////////////////////////////////////////////////////////////////
void CSimplePlotDlg::Grid()
{
int i;
m_dcArea->SelectObject(Brush);
m_dcArea->SelectObject(m_GridPen);
m_dcArea->FillRect(&m_PlotRect,&Brush);
for (i = 1;i<(m_PlotRect.Width()/10);i++)
{
m_dcArea->MoveTo(i*((double)m_PlotRect.Width()/10),0);
m_dcArea->LineTo(i*((double)m_PlotRect.Width()/10),m_PlotRect.Height());
}
for (i = 1;i<(m_PlotRect.Height()/10);i++)
{
m_dcArea->MoveTo(0,m_PlotRect.Height()-i*((double)m_PlotRect.Height()/10));
m_dcArea->LineTo(m_PlotRect.Width(),m_PlotRect.Height()-i*((double)m_PlotRect.Height()/10));
}
}
///////////////////////////////////////////////////////////////////////////////
void CSimplePlotDlg::OnPlot()
{
// TODO: Add your control notification handler code here
Grid();
}
A button click from the dialog execute OnPlot and generate the grid.
I would like to generate this grid in the call of InitDialog() with the previous lines of code .
BOOL CSimplePlotDlg::OnInitDialog()
{
.
.
.
// TODO: Add extra initialization here
m_dcArea = m_Plot.GetDC();
m_PlotPen.CreatePen(PS_SOLID,1,RGB(255,0,0));
m_GridPen.CreatePen(PS_SOLID,1,RGB(0,120,0));
Brush.CreateSolidBrush(RGB(0,0,0));
m_Plot.GetClientRect(&m_PlotRect);
Grid(); <-------- HERE !
return TRUE; // return TRUE unless you set the focus to a control
}
.
.
.
However it doesn't work and works only on the button click !!(the above structure).
PS Project is attached
Regards
madenai