Edwin Jarvis
Edwin Jarvis

Reputation: 6140

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

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.

Upvotes: 2

Views: 2499

Answers (3)

prakash
prakash

Reputation: 59719

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

Upvotes: 0

prakash
prakash

Reputation: 59719

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.

Upvotes: 0

Edwin Jarvis
Edwin Jarvis

Reputation: 6140

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.

Upvotes: 1

Related Questions