# TIP: removing flicker on windows

**URL:** <https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256>\
**Category:** Windows\
**Created:** [November 12, 2013, 9:24am UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256 "2013-11-12T09:24:21Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Russ\_Lunn](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@Russ\_Lunn](https://forum.xojo.com/u/Russ_Lunn)\
**Post date:** [November 19, 2013, 2:19pm UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/21 "2013-11-19T14:19:32Z")

</div>

I’ve just found that when i call these functions the part of the container control that overlaps the locked window (or allow redraw)  
doesn’t work correctly, it is not receiving mouse events as far as i can tell.

this is really annoying because i need to be able to see which row in my listbox is clicked!

---

<div class="post-metadata">

**Author:** ![Russ\_Lunn](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@Russ\_Lunn](https://forum.xojo.com/u/Russ_Lunn)\
**Post date:** [November 22, 2013, 12:15pm UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/22 "2013-11-22T12:15:28Z")

</div>

I’ve got it nearly sorted now!

you need to make the overlaying controls top left be inside the control you are locking. then it seems to work just fine.

in fact I’m really quite pleased with the results!

---

<div class="post-metadata">

**Author:** ![KarenA](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/c89c15/32.png) [@KarenA](https://forum.xojo.com/u/KarenA)\
**Post date:** [November 26, 2013, 4:39pm UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/23 "2013-11-26T16:39:09Z")

</div>

[quote=45550:@Russ Lunn]

btw this is in the pro channel because thats where I’ve been asking questions about the listbox lately[/quote]

Just noticed this thread… Not all the listbox experts are Xojo Pro 😉

---

<div class="post-metadata">

**Author:** ![Russ\_Lunn](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@Russ\_Lunn](https://forum.xojo.com/u/Russ_Lunn)\
**Post date:** [November 26, 2013, 4:49pm UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/24 "2013-11-26T16:49:30Z")

</div>

I am sorry, oh wise one. It was not my intention to anger the listbox gods. 😉

I only posted it there because I happened to be in that Chanel at the time.  
It wasn’t meant to be elitist.

Also, it’s not just about list boxes but any layered containercontrols.

---

<div class="post-metadata">

**Author:** ![KarenA](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/c89c15/32.png) [@KarenA](https://forum.xojo.com/u/KarenA)\
**Post date:** [November 26, 2013, 5:03pm UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/25 "2013-11-26T17:03:35Z")

</div>

And issues with layered container controls are of general interest too…

One more reason what I wish there was only the NUG… I learned a lot from the discussions there … here on average (at least outside of the Pro channel) the questions seem to trend more ‘basic’ than the NUG at it’s height. Oh well…

In any case I’m glad this got moved here, as I added it to my copy of the WFS.

Thanks

---

<div class="post-metadata">

**Author:** ![Russ\_Lunn](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@Russ\_Lunn](https://forum.xojo.com/u/Russ_Lunn)\
**Post date:** [November 26, 2013, 5:14pm UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/26 "2013-11-26T17:14:33Z")

</div>

Well. I agree about the nug. I used to get some good stuff on there but I think the forum is better now that I’m used to it.

I think that container controls, are probably a feature used by more advanced users but that’s not the same set as pro users. Maybe there should be a special case for people who have contributed a lot to the community, to be allowed into the pro forum. I know one of the things I learned from you was that what I thought was a pretty basic control could be made to sing.

---

<div class="post-metadata">

**Author:** ![DerkJ](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DerkJ](https://forum.xojo.com/u/DerkJ)\
**Post date:** [November 26, 2013, 8:14pm UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/27 "2013-11-26T20:14:56Z")

</div>

Why isn’t this in the framework?

---

<div class="post-metadata">

**Author:** ![Russ\_Lunn](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@Russ\_Lunn](https://forum.xojo.com/u/Russ_Lunn)\
**Post date:** [November 26, 2013, 8:17pm UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/28 "2013-11-26T20:17:46Z")

</div>

Lol… Just, lol.

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [November 26, 2013, 9:13pm UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/29 "2013-11-26T21:13:50Z")

</div>

> [@49048:@Derk Jochems](#):
>
> Why isn’t this in the framework?

WM\_REDRAW you mean ?

---

<div class="post-metadata">

**Author:** ![KarenA](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/c89c15/32.png) [@KarenA](https://forum.xojo.com/u/KarenA)\
**Post date:** [November 26, 2013, 11:07pm UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/30 "2013-11-26T23:07:04Z")

</div>

> [@49071:@Norman Palardy](#):
>
> WM\_REDRAW you mean ?

I think he means as a high level API to freeze updates to deal with flicker on Windows without having to deal with/ know about declares and be sure you are not messing with Xojo framework operations using it.

---

<div class="post-metadata">

**Author:** ![Russ\_Lunn](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@Russ\_Lunn](https://forum.xojo.com/u/Russ_Lunn)\
**Post date:** [November 26, 2013, 11:16pm UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/31 "2013-11-26T23:16:50Z")

</div>

Sorry for my sarcastic reply. Been a very long day.

I agree that it would make sense. There is a refresh so why not a lock refresh.  
Its 20 lines of code and some lines in the LR and it makes a MASSIVE difference.

Control.blockredraw  
Control.allowredraw

---

<div class="post-metadata">

**Author:** ![DerkJ](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@DerkJ](https://forum.xojo.com/u/DerkJ)\
**Post date:** [November 27, 2013, 5:29am UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/32 "2013-11-27T05:29:25Z")

</div>

> [@49071:@Norman Palardy](#):
>
> WM\_REDRAW you mean ?

I mean ANY anti-flicker supported by windows apis.  
I use windows many times more for development than mac, for that i have seen alot of flicker.

I just feel like it should never have been possible to even create flicker. But it happens, then i see this and think why doesn’t the framework has such build in (so you never notice flicker) or have a AutoBlockFlicker flag on some controls for example.

---

<div class="post-metadata">

**Author:** ![jim\_mckay](https://forum.xojo.com/user_avatar/forum.xojo.com/jim_mckay/32/905_2.png) [@jim\_mckay](https://forum.xojo.com/u/jim_mckay)\
**Post date:** [November 27, 2013, 5:33pm UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/33 "2013-11-27T17:33:49Z")

</div>

Have you tried using drawinto in the paint event of the window or container? I’ve seen some great results with pushbuttons and progressbars. This is one approach I use in the ActivityViewer project to help reduce flicker on Win32.

Sub Paint(g As Graphics, areas() As REALbasic.Rect)  
PushButton1.DrawInto g,PushButton1.Left,PushButton1.top  
End Sub

Seems to help a lot if live resizing the window causes flicker. Doesn’t work well for listboxes though if I recall…

---

<div class="post-metadata">

**Author:** ![Richard\_Duke](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_duke/32/246_2.png) [@Richard\_Duke](https://forum.xojo.com/u/Richard_Duke)\
**Post date:** [January 26, 2014, 10:26pm UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/34 "2014-01-26T22:26:02Z")

</div>

[quote=47326:@Russ Lunn]I’ve just found that when i call these functions the part of the container control that overlaps the locked window (or allow redraw)  
doesn’t work correctly, it is not receiving mouse events as far as i can tell.

this is really annoying because i need to be able to see which row in my listbox is clicked![/quote]

i encounter problem with these code took… i have this code on the resized and resizing on my main form and i open a container control that have some code on the on open to read a table and show the record but instead of doing that, it went into a endless loop on the Open Event for the container control. Removing the code solved the problem.

---

<div class="post-metadata">

**Author:** ![changwon\_lee](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@changwon\_lee](https://forum.xojo.com/u/changwon_lee)\
**Post date:** [April 28, 2017, 1:19pm UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/35 "2017-04-28T13:19:14Z")

</div>

Trying to remove flickering of Listbox by referring the code Russ Lunn suggested initially.

```auto
Sub LockWindow(hw as integer)
  #if TargetWin32 Then
    Declare Sub LockWindowUpdate Lib "user32" (ByVal hWnd As Integer)
    LockWindowUpdate hw
  #endif
End Sub
```

In my case, one Listbox in a ContainerControl under a MainWindow and flickering issue doesn’t look good, so I tried the code as following.

```auto
    LockWindow MainWindow.MainContainerScreen.JOBMonitorList.Handle
    PopulateListBoxJOBMonitor(MainWindow.MainContainerScreen.JOBMonitorList,rs)
    LockWindow 0
```

PopulateListBoxJOBMonitor method just gives values to Listbox.  
However, I don’t see any difference with or without the code.

For a ContainerControl, should I use a different number when I call LockWindow?  
Anyone can help me out?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [April 28, 2017, 1:25pm UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/36 "2017-04-28T13:25:34Z")

</div>

LockWindowUpdate is unlikely to be the right call

Aarons WFS has this comment regarding this  
// This is incorrect and should only be used for drag and drop operations

you probably want the [WFS code](https://github.com/arbp/WFS) which sends a WM\_SETREDRAW message in the method named FreezeUpdate

---

<div class="post-metadata">

**Author:** ![changwon\_lee](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@changwon\_lee](https://forum.xojo.com/u/changwon_lee)\
**Post date:** [April 28, 2017, 1:57pm UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/37 "2017-04-28T13:57:09Z")

</div>

Cool. I would like to check it first.  
Thanks a lot for the information.

---

<div class="post-metadata">

**Author:** ![changwon\_lee](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@changwon\_lee](https://forum.xojo.com/u/changwon_lee)\
**Post date:** [April 28, 2017, 2:57pm UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/38 "2017-04-28T14:57:55Z")

</div>

Tried WFS code and used SendMessage method as following, but when I run below code, I can’t see any data on Listbox and in case I click the Listbox, I just can see the updated data on the Listbox.

It seems that I am doing wrong thing. Can you advise me?

```auto
 Const WM_SETREDRAW = &hB
 call SendMessage( MainWindow.MainContainerScreen.JOBMonitorList.Handle, WM_SETREDRAW, 0, 0 )

// Data loading into Listbox
While Not rs.EOF
    dataList.AddRow("")
    For i As Integer = 1 To dataList.ColumnCount - 1

.......

Wend
 
  call SendMessage( MainWindow.MainContainerScreen.JOBMonitorList.Handle, WM_SETREDRAW, 1, 0 )

```

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [April 28, 2017, 3:23pm UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/39 "2017-04-28T15:23:01Z")

</div>

I have no idea about this API on Windows  
I just recalled seeing this comment from Aaron in the re and that WM\_SETREDRAW is the right thing to use

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [April 28, 2017, 3:35pm UTC](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256/40 "2017-04-28T15:35:42Z")

</div>

My experience with all these magic pills is that none of those I tried really worked.

[Previous page](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256.md?page=1)

[Next page](https://forum.xojo.com/t/tip-removing-flicker-on-windows/12256.md?page=3)
