How to make this function work?
Dear Friends,
The function void CMyWnd::DrawGrid(CPaintDC* pDC) draws a
grid in a CWnd derived window inside a dialog. But DrawGrid(..)
doesn't work outside its own class because of the CPaintDC
pointer. If I use CDC* the grid gets erased when the dialog
needs a repaint.I did the folowing:
void CMyDialog::OnButton1()
{
CGraph* m_Graph;
CPaintDC* dc(m_Graph); // Can't use 'this' pointer here, can I ?
m_Graph->DrawGrid(dc); // Doesn't work!
}
Can anybody please throw some light?
Thank You!
# 1 Re: How to make this function work?
Use OnPaint() to draw anything on your dialog. And here's the some "light"
void CMyDialog::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
CPaintDC dc(this); //add this 2 lines in you dialog class's OnPaint() method
m_Graph->DrawGrid(&dc)//
}
}
Please - rate answer if it helped you
It gives me inspiration when I see myself in the top list =)
Best regards,
----
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor@soukhov.com | ICQ:57404554 | http://soukhov.com