G
Guest
I've encountered a strange problem with GDI/GDI+ and windows forms/win32. To
explain it shortly: I've a user control with a NC area. When painting the NC
area I ask for a window DC using GetDCEx with parameters DCX_WINDOW |
DCX_CACHE. I also use the wParam of the WM_NCPAINT message which contains the
update region for the NC area (or 1 to update the whole NC area). After
creating the graphics object and painting the NC area (if necessary) the hDC
is released. Next, the WM_ERASEBKGND message arrives which contains an OS
supplied hDC in the wParam. Using this hDC, which is used automatically by
the WmEraseBkgnd method in the System.Windows.Forms.Control class if
UserPaint is true and AllPaintingInWmPaint is false, causes the problem: the
window background is NOT erased due to the fact that the system region of the
supplied hDC is NULL. This is even more strange while the update region of
the window is NOT null. The erase problem occurs when an external window
obscured the NC area of the form hosting my user control. To solve this
problems I've several workarounds: (1) set ControlStyles.AllPaintingInWmPaint
is true (forcing the control the handle background painting in the WmPaint
handler not using the OS supplied hDC for the WM_ERASEBKGND message, (2) not
using the hClipRgn parameter of GetDCEx (and neglecting the OS supplied
update region for the NC area) and (3) reinvalidate the window after handling
of the WM_NCPAINT event (the latter solution is not nice of course). Please
let someone me know if there is a better solution and if this is a bug in
win32 GDI. Thanks in advance.
explain it shortly: I've a user control with a NC area. When painting the NC
area I ask for a window DC using GetDCEx with parameters DCX_WINDOW |
DCX_CACHE. I also use the wParam of the WM_NCPAINT message which contains the
update region for the NC area (or 1 to update the whole NC area). After
creating the graphics object and painting the NC area (if necessary) the hDC
is released. Next, the WM_ERASEBKGND message arrives which contains an OS
supplied hDC in the wParam. Using this hDC, which is used automatically by
the WmEraseBkgnd method in the System.Windows.Forms.Control class if
UserPaint is true and AllPaintingInWmPaint is false, causes the problem: the
window background is NOT erased due to the fact that the system region of the
supplied hDC is NULL. This is even more strange while the update region of
the window is NOT null. The erase problem occurs when an external window
obscured the NC area of the form hosting my user control. To solve this
problems I've several workarounds: (1) set ControlStyles.AllPaintingInWmPaint
is true (forcing the control the handle background painting in the WmPaint
handler not using the OS supplied hDC for the WM_ERASEBKGND message, (2) not
using the hClipRgn parameter of GetDCEx (and neglecting the OS supplied
update region for the NC area) and (3) reinvalidate the window after handling
of the WM_NCPAINT event (the latter solution is not nice of course). Please
let someone me know if there is a better solution and if this is a bug in
win32 GDI. Thanks in advance.