Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
#Include "commctrl.inc"
%ID_Timer = 600
%IDC_StatusBar = 601
%IDC_Button = 602
Global hDlg,hBar As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Statusbar Test",300,300,350,100, %WS_OverlappedWindow, 0 To hDlg
Control Add Button, hDlg, %IDC_Button, "Start",10,10,100,20
Control Add Statusbar, hDlg, %IDC_StatusBar, "",0,0,0,0
Statusbar Set Parts hDlg, %IDC_StatusBar, 75,75,99999
Statusbar Set Text hDlg, %IDC_StatusBar, 1, 0, "one"
Statusbar Set Text hDlg, %IDC_StatusBar, 2, 0, "two"
Statusbar Set Text hDlg, %IDC_StatusBar, 3, 0, "three"
Control Set Color hDlg, %IDC_StatusBar, %Red, %Yellow
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local hDC As Dword
Static PerCent As Single
Select Case Cb.Msg
Case %WM_Command
If Cb.Ctl = %IDC_Button Then SetTimer(Cb.Hndl, %ID_Timer, 1000, ByVal %NULL)
Case %WM_Timer
PerCent = PerCent + 10
DrawBar PerCent
hDC = GetDC(hBar)
If PerCent > 100 Then
Percent = 0 : KillTimer Cb.Hndl, %ID_Timer
Control ReDraw hDlg, %IDC_StatusBar
End If
End Select
End Function
Sub DrawBar(PerCent As Single)
Local hBar, hDC As Dword, r As Rect, origPen, origBrush As Dword
' Control ReDraw hDlg, %IDC_StatusBar
Control Handle hDlg, %IDC_StatusBar To hBar
Control Send hDlg, %IDC_StatusBar, %SB_GetRect, 2, VarPtr(r)
Dialog Set Text hDlg, Str$(r.nLeft) + Str$(r.nTop) + Str$(r.nRight) + Str$(r.nBottom)
origPen = SelectObject(hdc,GetStockObject(%DC_Pen))
origBrush = SelectObject(hdc,GetStockObject(%DC_Brush))
' Rectangle hDC, r.nLeft,r.nTop,r.nRight,r.nBottom
SelectObject(hDC, GetStockObject(%DC_Brush))
SelectObject(hDC, GetStockObject(%DC_Pen))
SetDCPenColor(hDC, %Red)
SetDCBrushColor(hDC, %Blue)
' Rectangle hDC, r.nLeft,r.nTop,(r.nRight*PerCent)/100, r.nBottom
Rectangle hDC, r.nLeft,r.nTop,PerCent*r.nRight/100, r.nBottom
SelectObject(hDC,origPen)
SelectObject(hDC,origBrush)
ReleaseDC(hBar,hDC)
End Sub
'gbs_00801
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm