Page 3 of 4

..

Posted: Tue Jun 29, 2004 12:59 am
by NoahPhense
I have the solution. It just need to be converted from another language.

- np

Posted: Tue Jun 29, 2004 1:32 am
by PB
> I just tried the exact same code again, and now I get the same nasty
> flickering like my home PC.

Confirmed: Your original post is now flickering for me too! 8O
It's probably related to how intensive the CPU is working, because
I haven't done anything different to before, yet before it didn't
flicker for me either. Weird. To me, the "flickering" looks a bit
like "mouse pointer trails", if you've ever seen those, but done
to the window instead of the mouse. I haven't changed my screen
resolution, refresh rate, or any other display settings. Strange!

Posted: Tue Jun 29, 2004 2:03 am
by Sparkie
@PB - Thanks for the confirmation. The odds that my age is affecting my mind/eyes/sanity has just dropped a few percentage points. :D

Posted: Tue Jun 29, 2004 2:06 am
by PolyVector
I was tinkering with my 'solution' trying to get it to work for my SkinBuilder app I'm designing... this thing is far more complicated (and flickers far more) than the example apps here...

Best solution to date (for me):
When processing the #PB_Event_SizeWindow event, resize all your gadgets as you normally would.
Then, insert this line at the very end of your size routine:

Code: Select all

RedrawWindow_(WindowID(#Window_Main),0,0,#RDW_INTERNALPAINT|#RDW_UPDATENOW)
This is a bit inefficient since some of the window/gadgets have already been drawn, but maybe someone can optimize it?

Edit:
This works just as well (and it's easier on the keyboard) :

Code: Select all

UpdateWindow_(WindowID())

..

Posted: Tue Jun 29, 2004 3:03 am
by NoahPhense
Try this..

Code: Select all

SetWindowLong_(WindowID(#Window_0), #GWL_EXSTYLE, GetWindowLong_(WindowID(#Window_0), #GWL_EXSTYLE) | $02000000) ; #WS_EX_COMPOSITED)
...
full listing

Code: Select all

Declare Resize()

Enumeration
  #Window_0
EndEnumeration

Enumeration
  #Listview_0
  #String_0
  #Button_0
  #Text_0
EndEnumeration

; don't really need to be global.. 
Global cx.l, cy.l, wpi.l, f.l

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 311, 255, 596, 292,  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered , "blah..")
    ; **
    SetWindowLong_(WindowID(#Window_0), #GWL_EXSTYLE, GetWindowLong_(WindowID(#Window_0), #GWL_EXSTYLE) | $02000000) ; #WS_EX_COMPOSITED)

    If CreateGadgetList(WindowID())
      ListViewGadget(#Listview_0, 0, 5, 290, 175)
      StringGadget(#String_0, 300, 5, 295, 175, "")
      ButtonGadget(#Button_0, 5, 185, 285, 105, "")
      TextGadget(#Text_0, 325, 205, 155, 30, "This is a test...")
      ReSize()
    EndIf
  EndIf
EndProcedure

Open_Window_0()

Repeat
  
  Event = WaitWindowEvent()
  
  If Event = #PB_EventGadget
      ; Debug "WindowID: " + Str(EventWindowID())
    GadgetID = EventGadgetID()
    
    If GadgetID = #Listview_0
      ;
    ElseIf GadgetID = #String_0
      ;
    ElseIf GadgetID = #Button_0
      ;
    EndIf
  
  ElseIf Event = #PB_Event_SizeWindow 
    ReSize()  
  EndIf
  
Until Event = #PB_EventCloseWindow

End
;

Procedure ReSize() 

  f = #SWP_NOACTIVATE|#SWP_NOZORDER 
  cy = WindowHeight()
  cx = WindowWidth()
  hw = cx/2 
  hh = cy/2 

  wpi = BeginDeferWindowPos_(4) ; Pass the number of windows To be re-sized
;          Params For DeferWindowPos 
;          1) The value passed from BeginDeferWindowPos 
;          2) The Window handle (retrieved from GetDlgItem) 
;          3) A value specifing 'Z-order' (ignored here) 
;          4) x,y,w,h of window 
;          5) Flags (the values in 'f' seem To work best 
      DeferWindowPos_(wpi,GetDlgItem_(WindowID(#Window_0),0),0,0,0,hw,hh,f) 
      DeferWindowPos_(wpi,GetDlgItem_(WindowID(#Window_0),1),0,hw+1,0,(cx-(hw+1)),hh,f) 
      DeferWindowPos_(wpi,GetDlgItem_(WindowID(#Window_0),2),0,0,hh+1,hw,cy-(hh+1),f) 
      DeferWindowPos_(wpi,GetDlgItem_(WindowID(#Window_0),3),0,hw+1,hh+1,(cx-(hw+1)),cy-(hh+1),f) 
   EndDeferWindowPos_(wpi)
   wpi = 0 ; clearit
EndProcedure
Question, has anyone tried what Fred has suggested on page 1?

- np

Posted: Tue Jun 29, 2004 6:17 am
by PolyVector
@NoahPhense
Your code updates HORRIBLY slow when the window is large on my computer... If I take out this line, it solves the major slowdown, but flickering still occurs...

Code: Select all

SetWindowLong_(WindowID(#Window_0), #GWL_EXSTYLE, GetWindowLong_(WindowID(#Window_0), #GWL_EXSTYLE) | $02000000) ; #WS_EX_COMPOSITED)
I do, however, like the DeferWindowPos_() part... I'll be using it :)

I did try Fred's method when he posted it, but couldn't get it to work correctly...

Posted: Tue Jun 29, 2004 9:54 am
by DoubleDutch
I treid freds method on my ConsoleX library - it flickered on resize on my machine.

Code: Select all

If Message=#WM_ERASEBKGND
    Result=-1 ; or #NULL the result is the same...
EndIf
It stopped the flicker completely. This was a resizing window screen.

But if you try it with gadgets it seem to still flicker. :(

Posted: Tue Jun 29, 2004 10:48 am
by El_Choni
Has anybody tried adding #WS_CLIPCHILDREN to the window #GWL_STYLE, as I suggested? (I think OpenWindow should use it by default)
Excludes the area occupied by child windows [gadgets] when drawing occurs within the parent window. This style is used when creating the parent window.
Has always worked for me.

..

Posted: Tue Jun 29, 2004 2:49 pm
by NoahPhense
El_Choni wrote:Has anybody tried adding #WS_CLIPCHILDREN to the window #GWL_STYLE, as I suggested? (I think OpenWindow should use it by default)
Excludes the area occupied by child windows [gadgets] when drawing occurs within the parent window. This style is used when creating the parent window.
Has always worked for me.
I tried it. Can't say if it worked or not. Because I've yet to encounter
any flicker on any window, yet.. ;)

- np

Posted: Tue Jun 29, 2004 4:54 pm
by halo
There shouldn't be anything wrong with the code. I did not write this. I just copied it out of the "samples" directory because I knew it would flicker, just like every other PureBasic program I run.

..

Posted: Tue Jun 29, 2004 5:27 pm
by NoahPhense
halo wrote:There shouldn't be anything wrong with the code. I did not write this. I just copied it out of the "samples" directory because I knew it would flicker, just like every other PureBasic program I run.
No I just meant that I don't have flickering, so it's hard for me to code
for something I cannot see. But I'm still trying.. ;)

- np

Try this out.. lemme know what happens:

no_flicker.rar

Posted: Wed Jun 30, 2004 2:52 am
by PolyVector
Has anybody tried adding #WS_CLIPCHILDREN to the window #GWL_STYLE, as I suggested? (I think OpenWindow should use it by default)
I Know what the problem was with using WS_CLIPCHILDREN... you can't simply use it on the main window... you must use it on all gadgets that are parents of anything that gets resized... When you do this, there is absolutly no flickering! :)

Code: Select all

Procedure ReduceFlicker_Enum(handle.l,Param.l)
  SetWindowLong_(handle,#GWL_STYLE,GetWindowLong_(handle,#GWL_STYLE)|#WS_CLIPCHILDREN)
  ProcedureReturn #True
EndProcedure

Procedure ReduceFlicker(WindowNumber.l)
  ReduceFlicker_Enum(WindowID(WindowNumber),0)
  EnumChildWindows_(WindowID(WindowNumber),@ReduceFlicker_Enum(),0)
EndProcedure
All you have to do now is call ReduceFlicker(WindowNumber) after all gadgets are created...
Then call UpdateWindow_(WindowID(WindowNum)) after you resize all your gadgets on the #PB_Event_SizeWindow event...

It has near-perfect results for me... Although there is some garbling on some things...hrmmmmm

Posted: Wed Jun 30, 2004 8:54 am
by tinman
Putting

Code: Select all

LockWindowUpdate_(WindowID())
...
LockWindowUpdate_(0)
UpdateWindow_(WindowID())
around your resize code seems to help here although there is still some slight flickering on my system.

@PolyVector: are there any problems making all gadgets have the clipchildren style? Is it safe to use on gadgets which have no children?

Posted: Wed Jun 30, 2004 9:11 am
by DoubleDutch
This method works great... :)

UNLESS

your using "PanelGadget":(

With PanelGadget the backgound of the PanelGadget is not erased on resize when you use your modification.

Is panelgadget created by PureBasic or Windows itself?

If its by PureBasic, FRED can u look into this? FRED, if you want to see what I mean I can send you an exe.

-Anthony

Posted: Wed Jun 30, 2004 10:15 am
by DoubleDutch
if you create another gadget AFTER your "ReduceFlicker(window#)" code, what is the process of making this new gadget "flickerfree"?

Do I just call ReduceFlicker(Window#) again?