-3

I need to know if it is safe to store some calculated non-client area RECT (not the window rect neither the client one, it is a based on some calculation) from the WM_NCCALCSIZE message and use it later in the WM_NCPAINT without the need to do the whole recalculation process again in WM_NCPAINT!?

i.e. is WM_NCPAINT always called immediately after WM_NCCALCSIZE?

I need to save the hassle of doing the recalculation process in WM_NCPAINT message, because DefWindowProc from WM_NCCALCSIZE already does all what I need to start my calculations based on what it does.

TIA.

Tomay
  • 35
  • 5
  • 1
    I don't think you could guarantee it. Why not move your calculations to a function, then you can call it from both places. – Jonathan Potter Aug 07 '20 at 22:03
  • @JonathanPotter I read the question as being an issue with the *performance* of doing the same calculation multiple times. So moving the calculation to a function for both messages to call won't solve that. – Remy Lebeau Aug 08 '20 at 03:45
  • I have not tested this, but it seems logical that the non-client area would have to be sized before it can be painted, so it would make sense for `WM_NCCALCSIZE` to always precede `WM_NCPAINT`. Should be easy to verify with some test code. – Remy Lebeau Aug 08 '20 at 03:47

1 Answers1

0

i.e. is WM_NCPAINT always called immediately after WM_NCCALCSIZE?

I test this sample which provided by krsi, we can find that WM_NCCALCSIZE is always called before WM_NCPAINT, but this does not mean that no other messages were called in the middle. For example, when testing, after receiving WM_NCCALCSIZE, WM_PAINT will be called first, and then WM_NCPAINT will be called.

You seem to be customizing the non-client area, I think you can first read Nonclient Area.

In general, processing these messages for standard windows is not recommended, because the application must be able to draw all the required parts of the nonclient area for the window. For this reason, most applications pass these messages to DefWindowProc for default processing.

An application that creates custom nonclient areas for its windows must process these messages. When doing so, the application must use a window device context to carry out drawing in the window. The window device context enables the application to draw in all portions of the window, including the nonclient area. An application retrieves a window device context by using the GetWindowDC or GetDCEx function and, when drawing is complete, must release the window device context by using the ReleaseDC function.

If you just consider whether the size of the custom client area will change when WM_NCPAINT is called, I can't give a suitable answer because I haven't seen your code and I don't know what kind of project you need to complete.

I just tested the sample in another link, the non-client area will always maintain the border size of 4pixel, and the calculation is also performed in WM_NCCALCSIZE.

Strive Sun
  • 5,988
  • 1
  • 9
  • 26