Here is the latest code which reduce the flicker and thanks to you Justin, no more flicker to the controls inside the PanelGadget. But, one last thing, The Tab doesn't flick when the tab was changed (The control is). But when resized, the tab is flicking again. Any way to prevent it?
Code: Select all
Enumeration
#Str1
#Str2
#Panel1
#Str3
#Str4
#Str5
#Str6
EndEnumeration
Global Panel1OldProcedure = #Null
Procedure PanelMainCallBack(hWnd, uMsg, wparam, lparam)
Protected ps.PAINTSTRUCT
Select uMsg
Case #WM_ERASEBKGND
ProcedureReturn 1
Case #WM_PAINT
If wparam
ProcedureReturn CallWindowProc_(PanelMainOldProcedure, hWnd, uMsg, wparam, lparam)
EndIf
hdc = BeginPaint_(hWnd, ps)
memDC = CreateCompatibleDC_(hdc)
hBMP = CreateCompatibleBitmap_(hdc, ps\rcPaint\right, ps\rcPaint\bottom)
hOldBMP = SelectObject_(memDC, hBMP)
CallWindowProc_(Panel1OldProcedure, hWnd, #WM_ERASEBKGND, memDC, 0)
CallWindowProc_(Panel1OldProcedure, hWnd, #WM_PRINT, memDC, #PRF_CLIENT)
BitBlt_(hdc, ps\rcPaint\left, ps\rcPaint\top, ps\rcPaint\right, ps\rcPaint\bottom, memDC, ps\rcPaint\left, ps\rcPaint\top, #SRCCOPY)
;Cleanup
SelectObject_(memDC, hOldBMP)
DeleteObject_(hBMP)
DeleteDC_(memDC)
EndPaint_(hwin, ps)
ProcedureReturn 0
Default
ProcedureReturn CallWindowProc_(Panel1OldProcedure, hWnd, uMsg, wparam, lparam)
EndSelect
EndProcedure
Procedure EnumChilds(hwnd.i, param.i)
SetWindowLongPtr_(hwnd, #GWL_STYLE, GetWindowLongPtr_(hwnd, #GWL_STYLE) | #WS_CLIPCHILDREN)
ProcedureReturn #True
EndProcedure
If OpenWindow(0, 0, 0, 200, 200, "Flicker Free Test", #PB_Window_SizeGadget | #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #WS_CLIPCHILDREN)
;Making huge flicker to the PanelGadget
;SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, GetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE) | #WS_EX_COMPOSITED)
StringGadget(#Str1, 5, 5, 190, 20, "", #WS_CLIPSIBLINGS)
StringGadget(#Str2, 5, 30, 190, 20, "", #WS_CLIPSIBLINGS)
PanelGadget(#Panel1, 5, 55, 192, 140)
AddGadgetItem(#Panel1, -1, "Tab 01")
StringGadget(#Str3, 5, 5, 172, 20, "", #WS_CLIPSIBLINGS)
StringGadget(#Str4, 5, 30, 172, 20, "", #WS_CLIPSIBLINGS)
AddGadgetItem(#Panel1, -1, "Tab 02")
StringGadget(#Str5, 5, 5, 172, 20, "", #WS_CLIPSIBLINGS)
StringGadget(#Str6, 5, 30, 172, 20, "", #WS_CLIPSIBLINGS)
CloseGadgetList()
;Set #WS_CLIPCHILDREN to the panel and its childrens, only the statics are necessary i guess
SetWindowLongPtr_(GadgetID(#Panel1), #GWL_STYLE, GetWindowLongPtr_(GadgetID(#Panel1), #GWL_STYLE) | #WS_CLIPCHILDREN)
EnumChildWindows_(GadgetID(#Panel1), @EnumChilds(), 0)
Panel1OldProcedure = SetWindowLongPtr_(GadgetID(#Panel1), #GWLP_WNDPROC, @PanelMainCallBack())
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
EventGadget = EventGadget()
EventType = EventType()
Case #PB_Event_SizeWindow
ResizeGadget(#Str1, #PB_Ignore, #PB_Ignore, WindowWidth(0) - 10, #PB_Ignore)
ResizeGadget(#Str2, #PB_Ignore, #PB_Ignore, GadgetWidth(#Str1), #PB_Ignore)
ResizeGadget(#Panel1, #PB_Ignore, #PB_Ignore, WindowWidth(0) - 8, WindowHeight(0) - GadgetY(#Panel1) - 5)
ResizeGadget(#Str3, #PB_Ignore, #PB_Ignore, GadgetWidth(#Panel1) - 18, #PB_Ignore)
ResizeGadget(#Str4, #PB_Ignore, #PB_Ignore, GadgetWidth(#Str3), #PB_Ignore)
ResizeGadget(#Str5, #PB_Ignore, #PB_Ignore, GadgetWidth(#Panel1) - 18, #PB_Ignore)
ResizeGadget(#Str6, #PB_Ignore, #PB_Ignore, GadgetWidth(#Str5), #PB_Ignore)
Case #PB_Event_CloseWindow
EventWindow = EventWindow()
If EventWindow = 0
CloseWindow(0)
Break
EndIf
EndSelect
ForEver
EndIf