Il s'agit d'une barre de progression avec indication du pourcentage textuel. je crois que c'est Gnozal qui avait initié ce code.
Le plantage se fait sur GrabImage() qui échoue et plante donc le DrawImage() qui suit.
J'ai indiqué l'endroit avec des commentaires dans la première procédure.
Si vous avez une idée pour parer à ça et continuer d'utiliser ce gadget, ça m'aiderait bien, merci.
Code : Tout sélectionner
Enumeration
#Container
#progbar
EndEnumeration
Procedure ProcTextProgressBarGadget(hwnd, msg, wParam, lParam)
Protected OldProc.l, ImgID.l, ImgID2.l, hdcOut.l, hdcIn.l, ps.PAINTSTRUCT, GadgetNumber.l
Protected Text.s, BarColor.l, Progression.d, BackColor.l, ProgWidth.d, TextColor2.l
OldProc = GetProp_(hwnd, "OldProc")
TextColor = GetProp_(hwnd, "TextColor")
TextColor2 = GetProp_(hwnd, "TextColor2")
BackColor = GetProp_(hwnd, "BackColor")
BarColor = GetProp_(hwnd, "BarColor")
Select msg
Case #WM_PAINT
GadgetNumber = GetDlgCtrlID_(hwnd)
Progression = (GetGadgetState(GadgetNumber) - GetGadgetAttribute(GadgetNumber, #PB_ProgressBar_Minimum)) / (GetGadgetAttribute(GadgetNumber, #PB_ProgressBar_Maximum) - GetGadgetAttribute(GadgetNumber, #PB_ProgressBar_Minimum))
ProgWidth = GadgetWidth(GadgetNumber)* Progression
Text = StrD(Progression * 100, 0) + "%"
BeginPaint_(hwnd, @ps) ;>
hdcOut = ps\hdc
ImgID2 = CreateImage(#PB_Any, GadgetWidth(GadgetNumber), GadgetHeight(GadgetNumber), 24)
StartDrawing(ImageOutput(ImgID2))
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(GetStockObject_(#DEFAULT_GUI_FONT))
Box(0, 0, GadgetWidth(GadgetNumber), GadgetHeight(GadgetNumber), BarColor)
FrontColor(TextColor)
DrawText(GadgetWidth(GadgetNumber) / 2 - 0.5 * TextWidth(Text), GadgetHeight(GadgetNumber) / 2 - 0.5 * TextHeight(Text), Text)
StopDrawing()
ImgID = CreateImage(#PB_Any, GadgetWidth(GadgetNumber), GadgetHeight(GadgetNumber), 24)
Debug Str(ImgID)
hdcIn = StartDrawing(ImageOutput(ImgID))
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(GetStockObject_(#DEFAULT_GUI_FONT))
Box(0, 0, GadgetWidth(GadgetNumber), GadgetHeight(GadgetNumber), BackColor)
FrontColor(TextColor2)
DrawText(GadgetWidth(GadgetNumber) / 2 - 0.5 * TextWidth(Text), GadgetHeight(GadgetNumber) / 2 - 0.5 * TextHeight(Text), Text)
Debug Str(ImgID2)
ImgTmpID = GrabImage(ImgID2 , #PB_Any, 0, 0, ProgWidth, GadgetHeight(GadgetNumber)) ; ECHOUE !!
Debug Str(ImgTmpID) ; = 0 ??
DrawImage(ImageID(ImgTmpID), 0, 0); = Plantage !! ( image non initialisée.)
BitBlt_(hdcOut, 0, 0, GadgetWidth(GadgetNumber), GadgetHeight(GadgetNumber), hdcIn, 0, 0, #SRCCOPY)
StopDrawing()
EndPaint_(hwnd, ps) ;<
FreeImage(ImgID)
FreeImage(ImgID2)
FreeImage(ImgTmpID)
ProcedureReturn #Null
Case #WM_NCDESTROY
RemoveProp_(hwnd, "OldProc")
RemoveProp_(hwnd, "TextColor")
RemoveProp_(hwnd, "TextColor2")
RemoveProp_(hwnd, "BackColor")
RemoveProp_(hwnd, "BarColor")
EndSelect
ProcedureReturn CallWindowProc_(OldProc, hwnd, msg, wParam, lParam)
EndProcedure
Procedure CreateTextProgressBarGadget(GadgetNumber.l, X.l, Y.l, width.l, Height.l, Minimum.l, Maximum.l, FirstTextColor.l = #PB_Ignore, SecondTextColor.l = #PB_Ignore, BarColor.l = #PB_Ignore, BackColor.l = #PB_Ignore)
Protected ImgID.l, ImgID2.l
If FirstTextColor = #PB_Ignore
FirstTextColor = GetSysColor_(#COLOR_WINDOWTEXT)
EndIf
If SecondTextColor = #PB_Ignore
SecondTextColor = GetSysColor_(#COLOR_HIGHLIGHTTEXT)
EndIf
If BackColor = #PB_Ignore
BackColor = GetSysColor_(#COLOR_BTNFACE)
EndIf
If BarColor = #PB_Ignore
BarColor = GetSysColor_(#COLOR_HIGHLIGHT)
EndIf
ProgressBarGadget(GadgetNumber, X, Y, width, Height, Minimum, Maximum)
SetProp_(GadgetID(GadgetNumber), "BackColor", BackColor)
SetProp_(GadgetID(GadgetNumber), "BarColor", BarColor)
SetProp_(GadgetID(GadgetNumber), "TextColor", SecondTextColor)
SetProp_(GadgetID(GadgetNumber), "TextColor2", FirstTextColor)
SetProp_(GadgetID(GadgetNumber), "OldProc", SetWindowLong_(GadgetID(GadgetNumber), #GWL_WNDPROC, @ProcTextProgressBarGadget()))
EndProcedure
OpenWindow(0,0,0,600,300,"ProgressBarText",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ContainerGadget(#Container, 10,100,580,20,#PB_Container_Single)
CreateTextProgressBarGadget(#progbar, 0,0,580,20,0,100,#Black, #White, RGB(157, 196, 224), RGB(184, 184, 173))
CloseGadgetList()
SetGadgetState(#progbar,62)
Repeat
ev = WaitWindowEvent()
Select ev
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
Until ev=#PB_Event_CloseWindow