MDI Child Window Flicker in PB 5.11

Windows specific forum
CalamityJames
User
User
Posts: 78
Joined: Sat Mar 13, 2010 4:50 pm

MDI Child Window Flicker in PB 5.11

Post by CalamityJames »

In the program below, if you change the size of the child window using either the right or bottom edge there is great deal of flickering on my Windows XP system with PB 5.11 (but not 5.10).

Code: Select all

#Main = 0
  #MDIChild = 1
  If OpenWindow(#Main, 0, 0, 400, 300, "MDIGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget)
    If CreateMenu(#Main, WindowID(#Main))
      MenuTitle("Menu index 0")
      MenuTitle("MDI windows menu")
        MenuItem(0, "self created item")
        MenuItem(1, "self created item")

      MDIGadget(0, 0, 0, 0, 0, 1, 2, #PB_MDI_AutoSize)
        AddGadgetItem(0, #MDIChild, "child window")
          ; add gadgets here...
      UseGadgetList(WindowID(#Main)) ; go back to the main window gadgetlist
    EndIf
    Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
  EndIf
In a rather more sophisticated program where I intercept the WM_Paint and WM_Erasebackground messages I now find that the window does not draw itself properly and even disappears unexpectedly in 5.11. This program worked perfectly in 5.10. I assume these two issues are connected. Even in the simple program I think the flckering is unacceptable.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: MDI Child Window Flicker in PB 5.11

Post by IdeasVacuum »

Confirmed.

Just tested the above code with PB5.10 and then PB5.11(Final Release) on WinXP SP3.

Stark difference between the two, a lot of flicker in PB5.11 :shock:
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: MDI Child Window Flicker in PB 5.11

Post by Thunder93 »

Same results here too.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: MDI Child Window Flicker in PB 5.11

Post by Shield »

I also get flickers on Windows 7 and 8. SmartWindowRefresh doesn't help at all.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: MDI Child Window Flicker in PB 5.11

Post by Thunder93 »

That is what I tried too.
Shield wrote:I also get flickers on Windows 7 and 8. SmartWindowRefresh doesn't help at all.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Fred
Administrator
Administrator
Posts: 16686
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: MDI Child Window Flicker in PB 5.11

Post by Fred »

It's because of this fix: http://www.purebasic.fr/english/viewtop ... =4&t=53898 . We used WS_CLIPCHILDREN on subwindow creation, but it could lead to artifact so it has been removed, hence the flickering (which is a shame on Windows anyway, if you don't use a third party doublebuffer GUI toolkit). You can still try to re-enable it for your MDI window with SetWindowLong_() if you want.
codeprof
User
User
Posts: 65
Joined: Sun Sep 16, 2012 12:13 pm

Re: MDI Child Window Flicker in PB 5.11

Post by codeprof »

this has no flickering, but redraw bugs at the border if you move the inner window. :(

Code: Select all

#Main = 0
  #MDIChild = 1
  If OpenWindow(#Main, 0, 0, 400, 300, "MDIGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget)
    
    

    If CreateMenu(#Main, WindowID(#Main))
      MenuTitle("Menu index 0")
      MenuTitle("MDI windows menu")
        MenuItem(0, "self created item")
        MenuItem(1, "self created item")

        MDIGadget(0, 0, 0, 0, 0, 1, 2, #PB_MDI_AutoSize)
        
        SetWindowLong_(GadgetID(0), #GWL_EXSTYLE, #WS_EX_COMPOSITED)
        
        
        AddGadgetItem(0, #MDIChild, "child window")
          ; add gadgets here...
      UseGadgetList(WindowID(#Main)) ; go back to the main window gadgetlist
    EndIf
    Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
  EndIf
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: MDI Child Window Flicker in PB 5.11

Post by ts-soft »

Code: Select all

Procedure SetClip(hWnd, state = #False)
  Protected Style = GetWindowLongPtr_(hWnd, #GWL_STYLE)
  SetWindowLongPtr_(hWnd,#GWL_STYLE, style | #WS_CLIPCHILDREN )
  SetWindowPos_(hWnd, 0, 0, 0, 0, 0, #SWP_NOMOVE | #SWP_NOSIZE | #SWP_NOZORDER | #SWP_FRAMECHANGED)
  
  If state 
    Style = GetWindowLongPtr_(hWnd,#GWL_EXSTYLE)
    SetWindowLongPtr_(hWnd, #GWL_EXSTYLE, style | #WS_EX_COMPOSITED)
    SetWindowPos_(hWnd, 0, 0, 0, 0, 0, #SWP_NOMOVE | #SWP_NOSIZE | #SWP_NOZORDER | #SWP_FRAMECHANGED)     
  EndIf 
EndProcedure


#Main = 0
#MDIChild = 1
If OpenWindow(#Main, 0, 0, 400, 300, "MDIGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget)
  
  
  
  If CreateMenu(#Main, WindowID(#Main))
    MenuTitle("Menu index 0")
    MenuTitle("MDI windows menu")
    MenuItem(0, "self created item")
    MenuItem(1, "self created item")
    
    MDIGadget(0, 0, 0, 0, 0, 1, 2, #PB_MDI_AutoSize)
    
    SetClip(GadgetID(0))
    
    
    AddGadgetItem(0, #MDIChild, "child window")
    ; add gadgets here...
    UseGadgetList(WindowID(#Main)) ; go back to the main window gadgetlist
  EndIf
  Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf 
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: MDI Child Window Flicker in PB 5.11

Post by Thunder93 »

Any reason why someone shouldn't do it like I have it? Besides the scenario Fred said?

Code: Select all

#Main = 0
  #MDIChild = 1
  If OpenWindow(#Main, 0, 0, 400, 300, "MDIGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget)
    
    If CreateMenu(#Main, WindowID(#Main))
      MenuTitle("Menu index 0")
      MenuTitle("MDI windows menu")
        MenuItem(0, "self created item")
        MenuItem(1, "self created item")

        MDIGadget(0, 0, 0, 0, 0, 1, 2, #PB_MDI_AutoSize)        
        
        AddGadgetItem(0, #MDIChild, "child window")
        SetWindowLong_(GadgetID(0), #GWL_STYLE, GetWindowLong_(GadgetID(0), #GWL_STYLE)|#WS_CLIPCHILDREN)  ; <---- Added
          ; add gadgets here...
      UseGadgetList(WindowID(#Main)) ; go back to the main window gadgetlist
    EndIf
    Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
  EndIf
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
codeprof
User
User
Posts: 65
Joined: Sun Sep 16, 2012 12:13 pm

Re: MDI Child Window Flicker in PB 5.11

Post by codeprof »

A soultion for the problem with the Tooltip could be to modify the Callback funtion of the StringGadget if it is inside a Mdi-Window (As the problem seems to be the Tooltip and not the Mdi-Window itself).
The window could be forced to be redrawn if a Tooltip windows was closed...

Code: Select all

Global oldCB

Procedure WinCallback(hWnd, uMsg, WParam, *LParam.NMHDR) 
  If uMsg = #WM_NOTIFY
    If *lParam\code = #TTN_POP ; A Popup window was closed
      If GetProp_(hWnd, "MDIWINDOW") <> 0 ; If StringGadget is in a MDI-Window...
        RedrawWindow_(GetProp_(hWnd, "MDIWINDOW"), #Null, #Null, #RDW_INVALIDATE | #RDW_ERASE | #RDW_FRAME)
      EndIf  
    EndIf    
  EndIf  
  ProcedureReturn CallFunctionFast(oldCB, hWnd,uMsg, WParam, *lParam)
EndProcedure 





Define.i Wd, Sw, Md, Ev, Fi
Wd = OpenWindow(#PB_Any, 0, 0, 600, 400, "Test", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
If Not Wd = 0
  SetWindowColor(Wd, RGB(255, 255, 255))
  If CreateMenu(#PB_Any, WindowID(Wd))
    OpenSubMenu("Window")
    Md = MDIGadget(#PB_Any, 0, 0, 400, 300, 0, 0, #PB_MDI_AutoSize)
    
    
    
    SetWindowLong_(GadgetID(Md), #GWL_STYLE, GetWindowLong_(GadgetID(md), #GWL_STYLE)|#WS_CLIPCHILDREN)  ; <---- Added
    
    
    
    If Not Md = 0
      Sw = AddGadgetItem(Md, #PB_Any, "MDI-Test")
      
      
      ;Avoid Flickering inside the window
      SetWindowLong_(WindowID(Sw), #GWL_STYLE, GetWindowLong_(WindowID(Sw), #GWL_STYLE)|#WS_CLIPCHILDREN)  ; <---- Added
      
      
      If Not Sw = 0
        ResizeWindow(Sw, #PB_Ignore, #PB_Ignore, 400, 300)
        SetWindowColor(Sw, RGB(255, 100, 100))
        sg = StringGadget(#PB_Any, 20, 20, 100, 25, "", #PB_String_Numeric)
        
        
        
        
        oldCB = SetWindowLong_(GadgetID(sg), #GWL_WNDPROC, @WinCallback())                                ; <---- Added
        SetProp_(GadgetID(sg), "MDIWINDOW", WindowID(Sw))                                                 ; <---- Added
        
        
     
        
        TextGadget(#PB_Any, 20, 45, 300, 25, "Please enter non-numeric values above!")
        Repeat
          Test = WaitWindowEvent(5000)
          Select Test
            Case #PB_Event_CloseWindow: Fi = 1
          EndSelect
        Until Fi = 1
      EndIf
    EndIf
  EndIf
EndIf
End
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: MDI Child Window Flicker in PB 5.11

Post by Thunder93 »

Good solution codeprof! :D
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Post Reply