This Question have 3 answers right now.

Why does a call to BeginPaint() always generate a WM_NCPAINT message?

Question!

I'm facing a problem on the Win32 API. I have a program that, when it handles WM_PAINT messages, it calls BeginPaint to clip the region and validate the update region, but the BeginPaint function is always generating a WM_NCPAINT message with the same update region, even if the touched part that needs repainting is only inside the client region.

Do anyone has any clue why this is happening? It's on child windows with the WS_CHILD style.



Answers

I guess the WM_NCPAINT message is always sent with the assumption that the border needs to be repainted as well!

By : prakash


What happens if you call SetWindowPos and pass SWP_DEFERERASE as argument for the uFlags parameter?

This should prevent generation of the WM_SYNCPAINT message, which would indirectly cause the WM_NCPAINT message to be sent.

By : prakash


The MSDN entry for WM_PAINT says:

The function may also send the WM_NCPAINT message to the window procedure if the window frame must be painted and send the WM_ERASEBKGND message if the window background must be erased.

I'm trying to figure out why it is always sending even if the border isn't touched. I test that opening a small Notepad inside the control and minimizing. It doesn't touch the borders of the control, just inside and BeginPaint() generates a WM_NCPAINT.



Video about Why does a call to BeginPaint() always generate a WM_NCPAINT message?