Code: Alles auswählen
;
; simple Windows Pen Animation
;
; by Danilo, 01.05.2005 - german forum
;
Global CurrentPenIndex
Global AnimRect.RECT
#timer_speed = 250 ; in milliseconds
#color1 = $FFFFFF
#color2 = $000000
#pen_pattern = 0 ; style, can be 0 or 1
Dim Pens.l(4)
Procedure CreateGeometricPen_Horz(color1,color2)
If CreateImage(#PB_Any,8,1)
If StartDrawing(ImageOutput())
CompilerIf #pen_pattern = 0
LineXY(0,0,4,0,color1)
LineXY(4,0,8,0,color2)
CompilerElse
LineXY(0,0,1,0,color1)
LineXY(2,0,3,0,color2)
LineXY(4,0,5,0,color1)
LineXY(6,0,7,0,color2)
CompilerEndIf
StopDrawing()
lb.LOGBRUSH
lb\lbStyle = #BS_PATTERN
lb\lbHatch = ImageID()
pen = ExtCreatePen_(#PS_GEOMETRIC,1,@lb,0,0)
EndIf
EndIf
ProcedureReturn pen
EndProcedure
Procedure CreateGeometricPen_Vert(color1,color2)
If CreateImage(#PB_Any,1,8)
If StartDrawing(ImageOutput())
CompilerIf #pen_pattern = 0
LineXY(0,0,0,4,color1)
LineXY(0,4,0,8,color2)
CompilerElse
LineXY(0,0,0,1,color1)
LineXY(0,2,0,3,color2)
LineXY(0,4,0,5,color1)
LineXY(0,6,0,7,color2)
CompilerEndIf
StopDrawing()
lb.LOGBRUSH
lb\lbStyle = #BS_PATTERN
lb\lbHatch = ImageID()
pen = ExtCreatePen_(#PS_GEOMETRIC,1,@lb,0,0)
EndIf
EndIf
ProcedureReturn pen
EndProcedure
Procedure SetRect(x,y,w,h)
AnimRect\left = x
AnimRect\top = y
AnimRect\right = x+w
AnimRect\bottom = y+h
EndProcedure
Procedure WndProc(hWnd,Msg,wParam,lParam)
If hWnd = WindowID(0)
Select Msg
Case #WM_PAINT
hDC = BeginPaint_(hWnd,ps.PAINTSTRUCT)
If hDC
oldPen = SelectObject_(hDC,Pens(CurrentPenIndex))
MoveToEx_(hDC,AnimRect\left ,AnimRect\top,@saved.POINT)
LineTo_ (hDC,AnimRect\right ,AnimRect\top)
MoveToEx_(hDC,AnimRect\left ,AnimRect\bottom,@p.POINT)
LineTo_ (hDC,AnimRect\right ,AnimRect\bottom)
SelectObject_(hDC,Pens(CurrentPenIndex+1))
MoveToEx_(hDC,AnimRect\left ,AnimRect\top,@p.POINT)
LineTo_ (hDC,AnimRect\left ,AnimRect\bottom)
MoveToEx_(hDC,AnimRect\right ,AnimRect\top,@p.POINT)
LineTo_ (hDC,AnimRect\right ,AnimRect\bottom)
SelectObject_(hDC,oldPen)
MoveToEx_(hDC,saved\x,saved\y,@p.POINT)
EndIf
EndPaint_(hWnd,@ps)
ProcedureReturn 0
Case #WM_TIMER
If CurrentPenIndex = 0
CurrentPenIndex = 2
Else
CurrentPenIndex = 0
EndIf
InvalidateRect_(hWnd,0,1)
UpdateWindow_(hWnd)
EndSelect
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
; create 4 pens for animation
Pens(0) = CreateGeometricPen_Horz(#color1,#color2)
Pens(1) = CreateGeometricPen_Vert(#color1,#color2)
Pens(2) = CreateGeometricPen_Horz(#color2,#color1)
Pens(3) = CreateGeometricPen_Vert(#color2,#color1)
; set the AnimRect co-ordinates
SetRect(10,10,300,200)
; go!
OpenWindow(0,0,0,400,400,#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible,"Windows PenAnim")
SetWindowCallback(@WndProc())
SetTimer_(WindowID(),1,#timer_speed,0) ; start timer
HideWindow(0,0)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
; free the 4 pens
For i = 0 To 3
DeleteObject_(Pens(i))
Next i
Styles kannst Du mit den 4 Konstanten am Anfang einstellen.
gewechselt.