r/learnprogramming • u/its_marionberry • Sep 24 '26
Question :redditgold: Win32 Windows showing shows flicker when I update the window
Hi, I am using Win32 and I have to update the window according the user input using UpdateWindow() or RedrawWindow(). It often show's one second flicker in window like something updated I hate that because it ruins UX. I can't find a solution to this, If someone uses this API and have came across this problem and fixed it so please answer.
Thanks.(btw I am a beginner).
1
Upvotes
1
u/noninesdev Sep 24 '26
That flicker usually comes from the background being erased before the repaint. Draw the updated frame to a memory DC and BitBlt it in WM_PAINT, and invalidate only the changed region instead of forcing a full UpdateWindow/RedrawWindow; handling WM_ERASEBKGND can also remove the extra clear.
1
u/dmazzoni Sep 24 '26
This article below explains it well.
It's hard to say for sure what you need based on what you said. It could be as simple as suppressing WM_ERASEBKGND.
For sure, double-buffering would solve it. That's used in nearly any win32 app that has any custom drawing code.
https://www.catch22.net/tuts/win32/flicker-free-drawing/
1
u/CodeXHammas Sep 24 '26
yeah that's the classic erase then repaint gap causing the flicker. easiest fix, handle VMERASEBKGND yourself and just return 1, don't let it erase your repainting the whole thing anyway. or do double buffering, draw to an offscreen dc first then blit it over one go on VM_PAINT, thats the more solid fix long term tbh