Anti flicker declare

I remember not so long ago Norman posted a declare that prevents drawing of a control, preventing flicker.

Unfortunately, I did not save it at the time, and now am unable to locate it.

I did search the forum, but there are so many declares with apparently contradictory results, I rather go for something a bit more serious.

What is the most definite way to prevent a window to redraw during changes to avoid flicker ?

I use this code

Sub Freeze(extends w as window)
  Const WM_SETREDRAW = &hB
  call SendMessage( w.Handle, WM_SETREDRAW, 0, 0 )
End Sub

Sub UnFreeze(extends w as window)
  Const WM_SETREDRAW = &hB
  call SendMessage( w.Handle, WM_SETREDRAW, 1, 0 )
End Sub

Superb. Thank you Tim :slight_smile:

Michel, can you post later if it looks like it works for you? I tried one of the declares posted in the forum a couple of years back and I got my only Windows 7 blue screen I have ever had on this machine. The declares look like what I tried, although I am just going on memory.

OK.

First, the declare makes use of a method from WFS, so either drag WFS in the project, or add :

[code]Private Function SendMessage(hwnd as Integer, msg as Integer, wParam as Integer, lParam as Integer) As Integer
#if TargetWin32

Soft Declare Function SendMessageA Lib "User32" ( hwnd as Integer, msg as Integer, wParam as Integer, lParam as Integer ) as Integer
Soft Declare Function SendMessageW Lib "User32" ( hwnd as Integer, msg as Integer, wParam as Integer, lParam as Integer ) as Integer

if System.IsFunctionAvailable( "SendMessageW", "User32" ) then
  return SendMessageW( hwnd, msg, wParam, lParam )
else
  return SendMessageA( hwnd, msg, wParam, lParam )
end if

#else

#pragma unused hwnd
#pragma unused msg
#pragma unused wParam
#pragma unused lParam

#endif
End Function
[/code]

Second, I needed it for a ContainerControl that was flickering like a Christmas tree while controls were drawn. Unfortunately, the magic pill did not do.

The solution I found was to start the ContainerControl invisible, and with a 500 ms single timer, make it visible afterward. Flicker disappeared.

It is quite possible that this works better for straight windows. I’ll keep this in my bag of tricks for future use anyway. I don’t think flicker reduction is simple enough to use only one recipe.

I discovered recently that upon re-open, invisible controls on a webpage became visible (while the property is still invisible). My workaround is to move every affected control outside of the page when I set them to invisible, and to return the controls to their position when setting them visible. Not perfect, but acceptable…

It may not be applicable to all situations, but it works for me in my context. I would assume that it is a usable workaround to reduce flicker also, at least in some situations.

I like this…

[quote=280255:@Tim Hare]Sub Freeze(extends w as window)
Const WM_SETREDRAW = &hB
call SendMessage( w.Handle, WM_SETREDRAW, 0, 0 )
End Sub

Sub UnFreeze(extends w as window)
Const WM_SETREDRAW = &hB
call SendMessage( w.Handle, WM_SETREDRAW, 1, 0 )
End Sub[/quote]

where should i put this code???

Right click App -> Insert+ -> Module, Right click Module add Property -> Paste code
I have tested the code, now my Label doesn’t flicker any more but ListBox does, although it didn’t before.

[quote=308566:@John Walker]Right click App -> Insert+ -> Module, Right click Module add Property -> Paste code
I have tested the code, now my Label doesn’t flicker any more but ListBox does, although it didn’t before.[/quote]

sorry what i mean is where did call these 2 method?

They extend the Windows class, so if you have a Window called Window1 you would just call as Window1.Freeze and Window1.Unfreeze

understand now…

so basically i use it when the is too much flickering in something i was doing and put the freeze at the beginning and then unfreeze when the processing is done.

Pretty much yeah, but as can be seen from my post, which resurrected this thread from the past, its not a guaranteed fix. :frowning: