TIP: removing flicker on windows

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!

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!

[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 :wink:

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

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.

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

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.

Why isn’t this in the framework?

Lol… Just, lol.

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.

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

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.

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…

[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.

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

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.

    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.

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 which sends a WM_SETREDRAW message in the method named FreezeUpdate

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

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?

 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 )

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

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