0
votes

Images in MFC are created in the OnDraw function. We have to give "pDC->m_hDC" as the parameter if we want to draw an image...

The problem is that we can get pDC only in our OnDraw function. Now if we want to draw images outside that OnDraw then we need to create a pointer to "CDC" type to get "m_hDC" from it.

Some people said use this code:

CDC * dc = getDC();

But it says getDC() is undefined. What should I do?

The main point is that I want an initialized pointer to CDC in order to use it anywhere.

3
or if any one can define getDC() functionrepoleved
GetDC()? C++ is a case-sensitive languagecha

3 Answers

1
votes

Outside of the OnDraw function you can create a CDC with

CClientDC dc;

You very rarely need the m_hDC because CDC encapsulates almost all of the drawing functions. Like

dc.DrawIcon(x, y, m_hIcon);
0
votes

I commonly do something like this :

void CMyView::ForceRedraw()
{
    CClientDC pDC(this);
    OnDraw(&pDC);
}
0
votes

Another a solution is to use:

CClientDC* pDC = new CClientDC(this);

If you wish to use CDC pointer.