Your problem has NOTHING to do with Graphics, or even with with Windows programming. It is simple basic flaws in your logic.

For example, given the posted code (btw: you should ALWAYS post a minimal yet complete - compilable, runnable - that duplicates the error...)

Your class has an m_pWnd which you are using, but I do not see any place where it is initialized.

Then later you try to treat your object as if it WAS a CWnd, but it clearly is not.