Thanks to all of your responses, now we have three working alternatives to choose from:
Code: Select all
; Define
Enumeration
#BarDefaultStatusbar
#BarChiStatusbar
#BarBirdGadget
EndEnumeration
#BarMode=#BarDefaultStatusbar
;#BarMode=#BarChiStatusbar
;#BarMode=#BarBirdGadget
#PB_DpiBits= 16
#PB_DpiScale= 1<<#PB_DpiBits
Global DpiScale=GetDeviceCaps_(GetDC_(0),#LOGPIXELSX)<<#PB_DpiBits/96; 12 Bit (statt Fließkommaberechnung)
#SB_SETBKCOLOR= $2001
#PBM_SETBARCOLOR= 1033
#PBM_SETBKCOLOR= 8193
Macro ScaleUp(value)
(((value)*DpiScale)/#PB_DpiScale)
EndMacro
Macro ScaleDown(value)
(((value)<<#PB_DpiBits)/DpiScale)
EndMacro
; EndDefine
Procedure StatusBarFieldWidth(StatusBar,Field.i,Width.l)
If IsStatusBar(StatusBar)
Protected StatusBarID=StatusBarID(StatusBar)
Protected nParts,lResult
Protected lLeftField.l
Protected *dwFields
nParts=SendMessage_(StatusBarID,#SB_GETPARTS,0,0)
*dwFields=AllocateMemory(nParts*4)
If *dwFields
SendMessage_(StatusBarID,#SB_GETPARTS,nParts,*dwFields)
If Field>0
lLeftField=PeekL(*dwFields+(Field-1)*4)
EndIf
PokeL(*dwFields+Field*4,lLeftField+ScaleUp(Width))
lResult=SendMessage_(StatusBarID,#SB_SETPARTS,nParts,*dwFields)
; Resize progress bar (by Chi)
If #BarMode=#BarChiStatusbar And Field<2
Protected ProgressId=GetWindow_(StatusBarID,#GW_CHILD)
Protected Rect.Rect
Protected PosLeft,PosRight
PosLeft=PeekL(*dwFields)
PosRight=PeekL(*dwFields+4)
GetClientRect_(ProgressId,@Rect)
SetWindowPos_(ProgressId,#HWND_TOP,PosLeft+5,5,PosRight-PosLeft-11,Rect\bottom,#SWP_NOZORDER|#SWP_NOACTIVATE)
EndIf
FreeMemory(*dwFields)
ProcedureReturn lResult
EndIf
ProcedureReturn #False
EndIf
EndProcedure
Procedure Main()
LoadFont(0,"Segoe UI",14,#PB_Font_Bold)
OpenWindow(0,0,0,600,400,"Progress Bar", #PB_Window_SystemMenu|#PB_Window_TitleBar|#PB_Window_ScreenCentered)
CreateStatusBar(0, WindowID(0))
AddStatusBarField(ScaleUp(20))
AddStatusBarField(ScaleUp(200))
AddStatusBarField(#PB_Ignore)
StatusBarText(0,0,"> > > > > > > >",#PB_StatusBar_BorderLess)
StatusBarText(0,1,"|---MOVE---|",#PB_StatusBar_BorderLess)
StatusBarText(0,2,"< < < < < < < <",#PB_StatusBar_BorderLess)
TextGadget(99,50,30,500,30,StringField("Default Purebasic StatusbarProgress.Statusbar Progress fix by Chi.Progress Gadget Workaround",#BarMode+1,"."),#PB_Text_Center)
TextGadget(88,50,70,500,30,StringField("Resizing of the progressbar is forced by swapping between text and bar.Resizing is done by SetWindowPos in the StatusBarFieldWidth procedure.The progressbar gadget linked to the statusbar needs gets resized",#BarMode+1,"."),#PB_Text_Center)
TextGadget(77,50,300,500,50,"The progressbar handling can be changed by setting the #BarMode constant in the program.",#PB_Text_Center)
SetGadgetColor(77,#PB_Gadget_FrontColor,#Gray)
ButtonGadget(1,200,140,200,50,"Toggle Field Width")
ButtonGadget(2,200,200,200,50,"Toggle Text/Progress Bar")
SetGadgetFont(99,FontID(0))
If #BarMode=#BarBirdGadget
ProgressBarGadget(0,ScaleUp(20)+5,4,ScaleUp(200)-11,ScaleUp(16),0,100)
HideGadget(0,1)
SetGadgetState(0,50)
SetParent_(GadgetID(0),StatusBarID(0))
SetWindowTheme_(GadgetID(0),#Null,"")
SendMessage_(GadgetID(0),#PBM_SETBARCOLOR,0,$0A0AAA)
SendMessage_(GadgetID(0),#PBM_SETBKCOLOR,0,$F8E7DC)
SetWindowTheme_(StatusBarID(0),#Null,"")
SendMessage_(StatusBarID(0),#SB_SETBKCOLOR,0,$EFD0BB)
SetWindowLongPtr_(GadgetID(0),#GWL_EXSTYLE,GetWindowLongPtr_(GadgetID(0),#GWL_EXSTYLE)&~#WS_EX_STATICEDGE)
EndIf
w=20
p=0
Repeat
lEvent = WaitWindowEvent()
Select lEvent
Case #PB_Event_Gadget
Select EventGadget()
Case 1
SetGadgetText(1,"Field is "+StringField("wide.short",Bool(w=20)+1,"."))
w=120-w
StatusBarFieldWidth(0,0,w)
StatusBarFieldWidth(0,1,220-w)
Select #BarMode
Case #BarDefaultStatusbar
If p
StatusBarText(0,1,"Brute force fix")
StatusBarProgress(0,1,50)
EndIf
Case #BarBirdGadget
ResizeGadget(0,ScaleUp(w)+5,#PB_Ignore,ScaleUp(220-w)-11,#PB_Ignore)
EndSelect
Case 2
p!1
SetGadgetText(2,"Field type is "+StringField("text.progress",p+1,"."))
If #BarMode=#BarBirdGadget
HideGadget(0,p!1)
StatusBarText(0,1,StringField(".|---MOVE---|",2-p,"."),#PB_StatusBar_BorderLess)
Else
If p
StatusBarProgress(0,1,50,#PB_StatusBar_BorderLess)
Else
StatusBarText(0,1,"|---MOVE---|",#PB_StatusBar_BorderLess)
EndIf
EndIf
EndSelect
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
EndProcedure
Main()