J'ai épluché les 3000 threads des forums PB et autre pour comprendre que je ne suis pas le 1er à pleurer devant une IHM qui clignote sous Windows
aprés pas mal de test, il semble que le redraw d'un canvasGadget en lieu et place d'un scrollAreaGadget ne provoque aucun clignotement, même sans aucune bidouille d'appel de SendMessage_() ou autre...
Il ne me reste plus qu'à gérer l'apparition des ascenseurs pour faire une custom scrollarea à base de canvas, et ça devrait le faire.
Code : Tout sélectionner
;XIncludeFile "Modul_DeFlicker.pbi"
Macro DisableRedraw(hWnd)
; http://msdn.microsoft.com/en-US/library/dd145219(v=vs.85).aspx
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
SendMessage_(hWnd,#WM_SETREDRAW,0,0)
CompilerEndIf
EndMacro
Macro EnableRedraw(hWnd)
; http://msdn.microsoft.com/en-US/library/dd145219(v=vs.85).aspx
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
SendMessage_(hWnd,#WM_SETREDRAW,1,0)
RedrawWindow_(hWnd, 0, 0, #RDW_ERASE | #RDW_FRAME | #RDW_INVALIDATE | #RDW_ALLCHILDREN)
CompilerEndIf
EndMacro
Macro StopWindowUpdate(_winID_)
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
SendMessage_(_winID_,#WM_SETREDRAW,0,0)
CompilerEndIf
EndMacro
Macro ContinueWindowUpdate(_winID_, _redrawBackground_ = 0)
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
SendMessage_(_winID_,#WM_SETREDRAW,1,0)
InvalidateRect_(_winID_,0,_redrawBackground_)
UpdateWindow_(_winID_)
CompilerEndIf
EndMacro
;###############################################################################################################################
;- ------Variables
;###############################################################################################################################
Structure Thumb
x.i
y.i
gadget_id.i
EndStructure
; --- les gadgets
Global MainWindow
Global container
; --- dimension de la fenetre
Global Wind_w = 800
Global Wind_h = 600
; --- dimensions des vignettes
Global thumbSize = 40
Global thumbSep=5
Global nbThumb = 150
Global nbThumbByLine
; liste des vignettes
Global NewList list_thumbs.Thumb()
Global useScrollArea.b = #False
;###############################################################################################################################
;- ------Procedures
;###############################################################################################################################
Declare Window_Resize()
Declare calcThumbPositions()
Declare createGalleryGadgets()
;###############################################################################################################################
;+++++++++++++++++++++++++++++++++++++
; Gestion de l'evenement resizewindow
;+++++++++++++++++++++++++++++++++++++
Procedure Window_Resize()
;SendMessage_(WindowID(MainWindow),#WM_SETREDRAW,#False,0) ; <======================
; aucun effet
;winID = WindowID(MainWindow)
;StopWindowUpdate(winID)
; aucun effet
;DeFlicker_StartResize(MainWindow)
;HideGadget(container,#True)
Protected size_window_w = WindowWidth(MainWindow)
Protected size_window_h = WindowHeight(MainWindow)
; aucun effet?
;LockWindowUpdate_(WindowID(MainWindow))
; On ajuste la container a la taille de la fenetre
;SendMessage_(GadgetID(container),#WM_SETREDRAW,#False,0)
ResizeGadget(container ,#PB_Ignore, #PB_Ignore, size_window_w-15, size_window_h-15)
;SetGadgetAttribute(container,#PB_ScrollArea_InnerWidth,size_window_w-15)
;SetGadgetAttribute(container,#PB_ScrollArea_InnerHeight,size_window_h-15)
; si le nombre de vignettes par ligne change, on met a jour les positions
Protected new_nbThumbByLine = (GadgetWidth(container)-15) /(thumbSize+thumbSep)
If new_nbThumbByLine<>nbThumbByLine
calcThumbPositions()
ForEach list_thumbs()
;SendMessage_(list_thumbs()\gadget_id,#WM_SETREDRAW,#False,0)
ResizeGadget(list_thumbs()\gadget_id,list_thumbs()\x,list_thumbs()\y,#PB_Ignore, #PB_Ignore)
Next
nbThumbByLine = new_nbThumbByLine
EndIf
;LockWindowUpdate_(0)
;UpdateWindow_(WindowID(MainWindow))
; aucun effet
;DeFlicker_EndResize()
;DeFlicker_RefreshWindow(MainWindow)
;HideGadget(container,#False)
;ContinueWindowUpdate(winID)
;ForEach list_thumbs()
; SendMessage_(list_thumbs()\gadget_id,#WM_SETREDRAW,#True,0) ; <##########################
;Next
;SendMessage_(GadgetID(container),#WM_SETREDRAW,#True,0) ; <##########################
;SendMessage_(WindowID(MainWindow),#WM_SETREDRAW,#True,0) ; <======================
;RedrawWindow_(WindowID(MainWindow),#Null,#Null,#RDW_INVALIDATE) ; <======================
EndProcedure
;+++++++++++++++++++++++++++++++++++++
; Calcul de la position de chaque canvasgadgets
;+++++++++++++++++++++++++++++++++++++
Procedure calcThumbPositions()
nbThumbByLine = (GadgetWidth(container)-15) /(thumbSize+thumbSep);(largeur ascenceur vertical=15?)
thumb_num.i = 0
ForEach list_thumbs()
list_thumbs()\x=thumbSep+(thumb_num % nbThumbByLine)*(thumbSize+thumbSep)
list_thumbs()\y=thumbSep+(thumb_num/nbThumbByLine)*(thumbSize+thumbSep)
thumb_num+1
Next
EndProcedure
;+++++++++++++++++++++++++++++++++++++
; Construction de la liste de canvasgadgets
; dans le container
;+++++++++++++++++++++++++++++++++++++
Procedure createGalleryGadgets()
nb_thumb.i = ListSize(list_thumbs())
; On va ajouter tous les canvasGadget dans le container
OpenGadgetList(container)
ForEach list_thumbs()
; On ajoute la vignette dans le container
; on memorise le numero du gadget dans la liste
list_thumbs()\gadget_id=CanvasGadget(#PB_Any, list_thumbs()\x,list_thumbs()\y,thumbSize,thumbSize)
StartDrawing(CanvasOutput(list_thumbs()\gadget_id))
; couleur ou image
Box(0,0,thumbSize-1,thumbSize-1,RGB(Random(255,0),Random(255,0),Random(255,0)))
DrawText(20,20,Str(thumb_num),RGB(255,255,255))
StopDrawing()
thumb_num+1
Next
CloseGadgetList()
EndProcedure
;###############################################################################################################################
;- ------Initialisation
;###############################################################################################################################
MainWindow = OpenWindow(#PB_Any,0,0,Wind_w,600,"test resize",#PB_Window_SystemMenu | #PB_Window_SizeGadget)
If useScrollArea
container = ScrollAreaGadget(#PB_Any, 0, 0, Wind_w-15, Wind_h-15, Wind_w-30, Wind_h-30, #PB_ScrollArea_Raised)
Else
container = CanvasGadget(#PB_Any,0,0, Wind_w-15, Wind_h-15,#PB_Canvas_Border|#PB_Canvas_Container)
EndIf
SetGadgetColor(container,#PB_Gadget_BackColor ,RGB(50,50,50))
; aucun effet
;SmartWindowRefresh bascially create a clip region out of all sibling control, and apply it to the WM_ERASEBACKGROUND message, so the erase doesn't overwrite the controls with a solid color. So the more control you have in your root window, the worste it will perfom.
;SmartWindowRefresh(MainWindow, #True)
; aucun effet
;#WS_EX_COMPOSITED = $2000000
;SetWindowLong_(MainWindow, #GWL_EXSTYLE, GetWindowLong_(MainWindow, #GWL_EXSTYLE) | #WS_EX_COMPOSITED)
; Gestion du redimensionnement de la fenetre en temps reel
BindEvent(#PB_Event_SizeWindow,@Window_Resize(),MainWindow)
; on cree une liste de canvasGadgets
For i=0 To nbThumb -1
AddElement(list_thumbs())
Next
nbThumbByLine = (GadgetWidth(container)-15) /(thumbSize+thumbSep);(largeur ascenceur vertical=15?)
calcThumbPositions()
createGalleryGadgets()
;###############################################################################################################################
;- ------Boucle principale
;###############################################################################################################################
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Si ça fonctionne, je nettoie le code et je poste le résultat.