c++winapigdi+wm-paint

Gdi+ Graphics(HDC) vs Graphics(HWND) - reason to use which one?


In my WM_PAINT handler, I create a Gdiplus::Graphics object and I can make it from either an HWND or the HDC supplied by BeginPaint(). Is there any reason to choose one over the other?


Solution

  • Use the HDC that BeginPaint() gives you. That HDC is what you are supposed to be drawing on.

    If you use the HWND instead, the Graphics object will have to retrieve a new HDC from it, ignoring the HDC you already have.