Link to home
Start Free TrialLog in
Avatar of graber
graberFlag for United States of America

asked on

difference between CDC & CPaintDC

The following are snips use either the CDC or CPaintDC to draw a bitmap to the screen.  The first example doen't do what I would have expected.

void CBunchesObuttonsDlg::OnPaint()
{
  CPaintDC dc(this);
  CDC cdc;
  cdc.CreateCompatibleDC(&dc);
  m_ilButtonStateList.Draw(&cdc, 0,CPoint(50,50), ILD_SELECTED);
  CDialog::OnPaint();
}

However if I use the CPaintDC it works fine.  Why? what is the difference between CDC and CPaintDC.  What would I have to do to make the CDC work?  Please expand/expound.

void CBunchesObuttonsDlg::OnPaint()
{
  CPaintDC dc(this);
  CDC cdc;
  cdc.CreateCompatibleDC(&dc);
  m_ilButtonStateList.Draw(&dc, 0,CPoint(50,50), ILD_SELECTED);
  CDialog::OnPaint();
}

ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of graber

ASKER

This is useful.  Does that mean that any CDC member function I call against a CPaintDC they will be transparent to the screen until I call onPaint?  How do I take the CDC use it to update the screen?  That is the other half of the question.
In OnPaint, you are responsible for drawing the whole client area of the window. A memory DC is like a buffer. You may draw onto a memory DC and finally copy it to the screen DC by using BitBlt. For more information, see http://members.tripod.com/digitaldawn/section11/section11.html