Author Topic: STATUSBAR - FLICKER FREE?  (Read 7537 times)

0 Members and 1 Guest are viewing this topic.

Aurel

  • Guest
STATUSBAR - FLICKER FREE?
« on: October 18, 2015, 11:18:05 AM »
HI
MIke maybe...probably  :D
Is there a way to have statusbar control flicker-free when we resizing
main window?

Mike Lobanovsky

  • Guest
Re: STATUSBAR - FLICKER FREE?
« Reply #1 on: October 18, 2015, 12:03:50 PM »
Hi Aurel,

There's a universal rule for flicker-free drawing: "Do not allow anything to redraw itself twice".

The best approach will be to create your (main) window without the CS_HREDRAW+CS_VREDRAW class styles. Many common controls redraw themselves regardless of whether their parent window redraws itself on window resize.

For example, all statusbar control windows have a CS_VREDRAW style of their own, and they are also forced to repaint themselves when they are autoresized horizontally. So, if their parent windows have those extra CS_HREDRAW+CS_VREDRAW class styles, then the statusbars are always repainted twice, first, due to their own CS_VREDRAW style and horizontal autosizing, and second, due to their parent's CS_HREDRAW+CS_VREDRAW class styles, which inevitably causes flicker.

FBSL's main window ME and additional forms created with a call to FbslForm() have only one class style defined, CS_DBLCLKS, that allows the main message pipe to receive and process WM_L/R/MBUTTONDBLCLK messages.

Aurel

  • Guest
Re: STATUSBAR - FLICKER FREE?
« Reply #2 on: October 18, 2015, 02:33:57 PM »
Hi Mike

I already have just that :
Code: [Select]
wcx.style = CS_DBLCLKS '|CS_OWNDC so there is no CS_VREDRAW - CS_HREDRAW

another thing main window style is :

Code: [Select]
winstyle = WS_MINMAXSIZE or WS_CLIPCHILDREN
but still STATUSBAR flickering when is under resizing
...well i blame  function

Code: [Select]
MoveWindow ( status,0,(h-32),w,h,1)which is under message WM_SIZE
last parameter is 1 wich mean
ByVal bRepaint As Long - inside include file

And also one thing ...maybe ...just maybe is problem because i use
old :
Code: [Select]
Type WNDCLASS
 'cbSize        as long
 Style         as long
 lpfnwndproc   as long
 cbClsextra    as long
 cbWndExtra    as long
 hInstance     as long
 hIcon         as long
' hIconSm       AS long
 hCursor       as long
 hbrBackground as long
 lpszMenuName  as long
 lpszClassName as long
End Type

..and not this one:

Code: [Select]
Type WNDCLASSEX
 cbSize        as int
 Style         as int
 lpfnwndproc   as sys
 cbClsextra    as int
 cbWndExtra    as int
 hInstance     as sys
 hIcon         as sys
 hCursor       as sys
 hbrBackground as sys
 lpszMenuName  as sys
 lpszClassName as sys
 hIconSm       AS sys
End Type

what you mean about that ?
by the way statusbar created in EBasic or Cretive have non-flicker statusbar
probably beacause are created with MFC addition ..i am not sure

Aurel

  • Guest
Re: STATUSBAR - FLICKER FREE?
« Reply #3 on: October 18, 2015, 02:57:00 PM »
well i found something here :
http://winapi.foosyerdoos.org.uk/code/commoncntrls/htm/createstatusbar.php

and remove api func MoveWindow from WM_SIZE
and add this:

Code: [Select]
SendMessage status,WM_SIZE ,0,0like is in that example (in C).
and seems that statusbar not flickering  ;)

by the way this statusbar is part of my AScio2 editor written in Oxygen.
Next thing is flickering of Listbox...
i will look more into this problem...  ::)

Mike Lobanovsky

  • Guest
Re: STATUSBAR - FLICKER FREE?
« Reply #4 on: October 18, 2015, 03:27:34 PM »
1. WNDCLASS requires RegisterClass(), WNDCLASSEX requires RegisterClassEx(). Don't be lazy bones while typing your code; prefer to use WNDCLASSEX/RegisterClassEx/CreateWindowEx. WNDCLASSEX should be defined as shown above; do not change anything to long -- OxygenBasic is sensitive to proper use of sys in certain places.

2. MoveWindow() is not a proper way to handle statusbar resizing. This function generates a cascade of events that make the statusbar repaint itself several times causing flicker.

The statusbar is a self-resizing control. Just send it a WM_SIZE message with zero parameters and it will do everything itself: it will move itself to the bottom of its parent and it will automatically adjust its own height and width to fit.

Consider the following short FBSL script. It will provide you with a flicker-free statusbar. Note that MSCtls_StatusBar32 is a predefined class and you don't need to register it. Just use CreateWindowEx() to respawn it with zero X and Y, zero width and height, and zero window style and extended style. FbslControl() is intrinsically mapped to CreateWindowEx() as commented in the script.

The statusbar will appropriately resize and reposition itself automatically whenever it receives WM_SIZE from its parent. No exessive repainting will occur and flicker will go away.

Code: OxygenBasic
  1. ' CTLID=control ID, X=x pos; Y=y pos; W=width; H=height; S=window styles; XS=extended window styles as per CreateWindowEx()
  2. '                              CLASS NAME     PARENT CAPTION    CTLID X  Y  W  H  S  XS
  3. Dim hStatus = FbslControl("MSCtls_StatusBar32", ME, "Ready...", 1000, 0, 0, 0, 0, 0, 0)
  4. Center(ME): Show(ME)
  5.  
  6. Begin Events
  7.   Select Case CBMSG
  8.     Case &H5 ' WM_SIZE
  9.      SendMessage(hStatus, &H5, 0, 0)
  10.   End Select
  11. End Events


[EDIT] You were a tad faster than me to post. :)
« Last Edit: October 18, 2015, 03:41:25 PM by Mike Lobanovsky »

Aurel

  • Guest
Re: STATUSBAR - FLICKER FREE?
« Reply #5 on: October 18, 2015, 09:19:09 PM »
Hi Mike
Thank you of course  :)

Do you can show example with LISTBOX without flickering?
In FBSL ...if is not problem?

Mike Lobanovsky

  • Guest
Re: STATUSBAR - FLICKER FREE?
« Reply #6 on: October 19, 2015, 06:46:24 AM »
Hi Aurel,

The following FBSL script (and of course its equivalent in OxygenBasic if its main window doesn't have CS_HREDRAW/CS_VREDRAW and has WS_CLIPCHILDREN) will provide you with a GUI that's perfectly flicker-free under XP Classic and in absolutely all modes under Vista and subsequent Windows operating systems' DWM. The only slight problem it may have is the listbox' currently highlited line under any XP theme. Unlike Vista+ DWM, the XP theme manager draws highlighted backgrounds directly on screen rather than in the backbuffer, so some faint flicker is unavoidable.

Code: OxygenBasic
  1. #Include <Include\Windows.inc>
  2.  
  3. #Define LST_STYLE WS_CHILD BOr WS_VISIBLE BOr WS_TABSTOP BOr LBS_NOINTEGRALHEIGHT
  4. #Define LST_EXTSTYLE WS_EX_CLIENTEDGE
  5.  
  6. Macro ListAddString(s) = SendMessage(hList, LB_ADDSTRING, 0, s)
  7. Macro ResizeStatusBar() = SendMessage(hStatus, WM_SIZE, 0, 0)
  8. Macro ResizeListBox() = MoveWindow(hList, 40, 40, LoWord(CBLPARAM) - 80, HiWord(CBLPARAM) - 100, TRUE)
  9.  
  10. Type RECT: Left As Long, Top As Long, Right As Long, Bottom As Long: End Type
  11.  
  12. Dim hList, hStatus, rc As RECT
  13.  
  14. Resize(ME, 0, 0, 500, 300) ' FBSL resizes based on non-client, rather than client, area dimensions, so ...
  15. GetClientRect(ME, @rc) ' ... get whatever client area the main window actually has into rc.Right/rc.Bottom
  16.  
  17. hList = FbslControl("ListBox", ME, "", 1000, 40, 40, rc.Right - 80, rc.Bottom - 100, LST_STYLE, LST_EXTSTYLE)
  18. hStatus = FbslControl("MSCtls_StatusBar32", ME, "Ready...", 1001, 0, 0, 0, 0, 0, 0)
  19.  
  20. ListAddString("Some")("listbox")("strings")("added")("for")("your")("enjoyment")
  21.  
  22. Center(ME): Show(ME)
  23.  
  24. Begin Events
  25.   Select Case CBMSG
  26.     Case WM_SIZE
  27.       ' NB: the order in which controls are
  28.      ' resized and/or moved by MoveWindow()
  29.      ' or SetWindowPos() may matter much!
  30.      ResizeListBox()
  31.       ResizeStatusBar()
  32.   End Select
  33. End Events

The general rule here is to first, resize/reposition all manually resizable controls, and then, allow auto-resizable controls such as statusbars, toolbars and/or rebars to do their job automatically.

It should however be noted that separate calls to MoveWindow() and/or SetWindowPos() for each manually resizable control isn't the best solution. It will not be noticeable with just a couple of controls on the form, but if the number of controls is a dozen or more, you will clearly see each control crawling to its new place like a cockroach one at a time, and especially on a slow PC.

MS Windows offers a method to eliminate that unwanted behavior and resize/reposition some or all of the manually resizable controls instantaneously in one single repaint of the main window. There are three matching Win32 APIs used for that purpose: BeginDeferWindowPos(), DeferWindowPos(), and EndDeferWindowPos().

-- BeginDeferWindowPos() accepts the number of child control windows you wish to resize/reposition instantaneously, and returns a sys hDwp handle that should be used in subsequent calls to the other APIs. Note that all child controls must belong to a common immediate parent. If at least one has some other parent, e.g. if it is located on another form, the entire method will silently fail and all the controls will remain in their original places.

-- DeferWindowPos() accepts the hDwp handle from a previous call to BeginDeferWindowPos() or DeferWindowPos() and has the other parameters exactly like those of SetWindowPos() function. DeferWindowPos() again returns a new hDwp handle that must be used in the next function call.

-- EndDeferWindowPos() accepts the last hDwp handle returned from the last DeferWindowPos() call and actually repositions instantaneously all the controls that have just been supplied with a corresponding DeferWindowPos() call.

Pseudocode might look as follows:

Code: OxygenBasic
  1. ' ........
  2. Case WM_SIZE
  3.   Dim hDwp = BeginDeferWindowPos(3) ' plan to resize/move 3 child controls
  4.  hDwp = DeferWindowPos(hDwp, hCtrl1, ...) ' prepare resize/move of control #1; other params as per SetWindowPos
  5.  hDwp = DeferWindowPos(hDwp, hCtrl2, ...) ' prepare resize/move of control #2
  6.  hDwp = DeferWindowPos(hDwp, hCtrl3, ...) ' prepare resize/move of control #3
  7.  EndDeferWindowPos(hDwp) ' actually move all 3 controls instantaneously
  8.  SendMessage(hStatus, WM_SIZE, 0, 0) ' let auto-resizable controls do their job
  9. ' ........
  10.  


Hope this helps. :)
« Last Edit: October 19, 2015, 07:30:11 AM by Mike Lobanovsky »

Aurel

  • Guest
Re: STATUSBAR - FLICKER FREE?
« Reply #7 on: October 19, 2015, 12:33:55 PM »
Hi Mike
and thank you very much on reply  ;)
well i have some problems to find my version of FBSL editor written in Oxygen
but i quickly modify one for FB and work without trouble then i finally compile
your FBSL example .
..well status bar work fine ..i mean with almost no-flickering but lisbox flicker
same as mine 
i still dont try way with few api which you recommend me
but i will .

In attachment is source code of editor and listbox example
(hehe ..i even modify toolbar bitmaps..)

[attachment deleted by admin]
« Last Edit: October 19, 2015, 12:41:25 PM by Aurel »

Mike Lobanovsky

  • Guest
Re: STATUSBAR - FLICKER FREE?
« Reply #8 on: October 19, 2015, 04:53:02 PM »
Thanks for the zip, Aurel!

I can't compile FBSL scripts with your editor (you can't compile them from the command line or shell; you must use the FBSL2EXE.fbs compiler script from the FBSL v3.5 RC2 distro properly installed on your PC) but I can load an FBSL script into it and I can also run its manually precompiled executable from the same directory where the script is.

Below is the zip with two videos of running Listbox.exe under XP Sp3 Classic and XP Sp3 Luna-themed. None of them show any signs of flicker except for very faint shimmering of the themed listbox' white "Some" (line 0 -- that's the default selection when the app starts) and then blue "strings" (line 2 selected with the mouse). The statusbar shows absolutely no flicker in either video. And I repeat, under Vista, 7, 8, 8.1 and 10 there will be no flicker at all in the unthemed Classic, or opaquely themed Basic, or semi-transparent Aeroglass modes of DWM operation.

You are probably still under your legacy XP Sp2. That's very bad and I told you about that more than once in the past. We do not know how bad your video drivers are and what broken spam you could have additionally installed over those years. Sp1 and Sp2 were very buggy, and Sp3 also enjoyed hundreds of updates and fixes during the years it was supported by MS. So what I (and everyone else except you) may be seeing on our XP screens may not be available to you by definition no matter how hard we try.

As the last resort, try to rewrite this Listbox.fbs script in OxygenBasic (this isn't too difficult), compile it, and if you still see it flicker, then send the exe to me to check it on my PC. If I see no flicker while you see one, then there will be no other cure to this problem than throw your PC away in the trash bin. :)

[attachment deleted by admin]

JRS

  • Guest
Re: STATUSBAR - FLICKER FREE?
« Reply #9 on: October 19, 2015, 05:05:46 PM »
Quote
If I see no flicker while you see one, then there will be no other cure to this problem than throw your PC away in the trash bin.

That may have crossed the line with Aurel and you will join the rest of us being drug addicts hooked on a magical pipe Aurel keeps referring to.

Aurel

  • Guest
Re: STATUSBAR - FLICKER FREE?
« Reply #10 on: October 21, 2015, 08:24:56 AM »
Hi Mike
and tanks for video ..
something it is not normal...and please stop with stupid observations
that XP-SP2 is bad and that your XP-SP3 is fine ...this simply is not true.
Also i use this older PC for programming and other programs i use for many
daily things...and all those things work perfactly fine.
Sooo i try same program on my kid win7 computer which is 3 year old
and same stupid listbox flickering is present.
so i again compile similar program in EBasic (on old PC)and there is no any kind of flickering.
And yes i will do that again in Oxygen Basic using this time WINDOWCLASSEX...

PS...i don't want bothering you ...so forget
i will find solution   :)

JRS

  • Guest
Re: STATUSBAR - FLICKER FREE?
« Reply #11 on: October 21, 2015, 09:14:56 AM »
Quote from: Aurel
something it is not normal...and please stop with stupid observations.



Mike Lobanovsky

  • Guest
Re: STATUSBAR - FLICKER FREE?
« Reply #12 on: October 21, 2015, 09:10:31 PM »
Hmmm Aurel,

Nobody, but nobody has ever called me "stupid". "Wild faker" yes, quite recently, "stupid" no, never, even my wives. :)

XP Sp3 isn't mine, it's every-bloody-body's standard out there while XP Sp2 is exclusively yours among all the BASIC'ers known to me on all currently existing BASIC sites. Have you seen my videos? Yes. Isn't that proof enough? No? Do you want me to re-write the code in OxygenBasic for you and compile it and film it on all of my four (!) PCs again and then send it to you for rejection? I could have but why should I?

Why should I jump out of my pants for the sake of a person who says "yes, your statusbar code doesn't flicker" and still sends me in the same message his editor script which keeps on using buggy MoveWindow() to reposition its own statusbar that's flickering like hell (read spitting) right in my face? Have you been able to compile my FBSL code, Aurel? Your editor can't compile it, so how did you manage to even check out my suggestions before criticizing them? Whom have I been telling all these things to, and what for?! Don't I have other things on my hands other than wasting my time giving pieces of advice and writing code and compiling demos and filming videos for a man that's deaf to my reasoning and blind to my demos and films?

After all, those problems are all yours, not mine.

My listbox and stausbar script you criticize is precompiled and attached in the zip below. The executable isn't password protected or exe-packed. You can decompile it freely to see if I'm cheating you regarding its code identity. Let's see if anybody at all in the whole world confirms your words that it flickers, and not mine that it doesn't, any more than was shown in my videos and commented on verbally in my messages.

After that you may go look for a solution youself. But it seems almost certain now that the best solution has already been suggested, whether you like it or not, by me in my previous post. :)

[attachment deleted by admin]

Aurel

  • Guest
Re: STATUSBAR - FLICKER FREE?
« Reply #13 on: October 22, 2015, 04:38:42 AM »
hmmm Mike
first of all ....i dont say that you are stupid... than that point that sp3 is better
and what a heck sp2 -or  sp3 have with flickering...NOTHING.
OK  :)
but who care...

Mike Lobanovsky

  • Guest
Re: STATUSBAR - FLICKER FREE?
« Reply #14 on: October 22, 2015, 06:35:43 AM »
Aurel,

If Sp3 doesn't flicker while Sp2 does, there's a bug in Sp2, not in the code we're running. If Sp2 has a bug while Sp3 hasn't, it means Sp2 is buggy and bad, and Sp3 is bugless and good. People usually throw out bad things and keep good things. That's my point expressed in very simple terms and basic English.

If you want to be a Sith and see things that aren't there, stick with Sp2. I prefer to stay a Dagobahn and stick with Sp3. Sorry but that makes our further communication in the field of control flicker totally pointless.  ::)