Is there a function that will freeze window repainting for some time, while I do changes to the layout of my dialog?
If you find that you actually need to do this, you should send the window a WM_SETREDRAW
message with the wParam
set to FALSE. This indicates that the window should not be redrawn after its contents are changed.
When you want to re-enable drawing, send another WM_SETREDRAW
message, this time with the wParam
set to TRUE.
Sample code:
// Disable window updates
SendMessage(hWnd, WM_SETREDRAW, FALSE, 0);
// Perform your layout here
// ...
// Re-enable window updates
SendMessage(hWnd, WM_SETREDRAW, TRUE, 0);
For more information, Raymond Chen's blog article on the subject is a great read.
WM_SETREDRAW
isn't documented as making the window pseudo-invisible and/or having any effect on child windows. Second, it assumes the default implementation, which is a mistake because you generally should provide a custom handler for WM_SETREDRAW
that could work differently. –
Soppy WM_SETREDRAW
false can leave the app along with the NC controls unresponsive. So yeah, check all routines where it is required to be true again, or better, just add relevant conditions in WM_PAINT
. –
Frivolity You should do the repositioning in a single swoop; use BeginDeferWindowPos et al.
The way Windows paints is that the system posts your window WM_PAINT
messages instructing you to paint. You can elect to ignore these messages if you so wish, whilst you are modifying the layout, and then force a paint cycle once you have finished modifying the layout.
However, my experience of writing UI on Windows is that you usually don't need to take such steps. Since you are in charge of pumping your message queue, if the window is being refreshed whilst you are in the middle of modifying the layout, then you must have taken action that led to the message queue being pumped.
Put simply, stop pumping the queue whilst modifying the layout and your problems will vanish.
© 2022 - 2024 — McMap. All rights reserved.
WM_PAINT
messages while you adjust your dialog's layout? Windows won't send aWM_PAINT
message to the window procedure unless there are no other messages available for processing. – SoppyWM_PAINT
messages, rather it posts them. Quite an important distinction. – Sthenic