When can (or should) I call DeleteObject on a region handle?

  gdi, handle, region, windows

I’m resizing a window that has an associated region.

I initially call CreateEllipticRgn, then call SetWindowRgn with the returned hRgn.

When I resize, my instinct is to call DeleteObject on the region handle, then create another region at the new size. But the docs for SetWindowRgn say:

After a successful call to SetWindowRgn, the system owns the region
specified by the region handle hRgn. The system does not make a copy
of the region. Thus, you should not make any further function calls
with this region handle. In particular, do not delete this region
handle. The system deletes the region handle when it no longer
needed.

So, when is the region handle ‘no longer needed’? Am I going to leak if I keep creating regions without deleting the old ones?

Source: Windows Questions

LEAVE A COMMENT