
Code: Select all
;
; Fading Child Window on Parent, by Electrochrisso
;
Enumeration
#Window_Main
#Window_Child
#Button_1
#Button_2
#Button_3
#ImageGadget
#ImageImage
EndEnumeration
Global hWin,Opacity
Procedure CallBack(hWnd,Msg,wParam,lParam)
Result=#PB_ProcessPureBasicEvents
Select Msg
Case #WM_MOVE
GetWindowRect_(WindowID(#Window_Main),win.RECT)
x=win\left:y=win\top
SetWindowPos_(WindowID(#Window_Child),0,x+323,y+GetSystemMetrics_(#SM_CYCAPTION )+3,0,0,#SWP_NOSIZE|#SWP_NOACTIVATE)
EndSelect
ProcedureReturn Result
EndProcedure
Procedure SetWinOpacity(hWin.l,Opacity.l)
SetWindowLong_(hWin,#GWL_EXSTYLE,#WS_EX_LAYERED);#WS_EX_LAYERED=$00080000
SetLayeredWindowAttributes_(hWin,0,Opacity,2)
EndProcedure
Procedure FadeWindow(FadeDuration,FadeStartOpacity,FadeEndOpacity)
FadeStartTime=ElapsedMilliseconds()
While ElapsedMilliseconds()<FadeStartTime+FadeDuration
ActOpacity=Abs(FadeStartOpacity-(FadeStartOpacity-FadeEndOpacity)/FadeDuration*(ElapsedMilliseconds()-FadeStartTime))
While WindowEvent():Wend
SetWinOpacity(hWin,ActOpacity)
Delay(20)
Wend
EndProcedure
If CreateImage(#ImageImage,320,240)
MyFont=LoadFont(0,"Tahoma",24)
StartDrawing(ImageOutput(#ImageImage))
Box(0,0,320,240,$FFFFFF)
DrawingFont(MyFont)
DrawText(15,10,"This Example Shows",$999999,$FFFFFF)
DrawText(15,50,"how I use Window",$999999,$FFFFFF)
DrawText(15,90,"Fading...",$999999,$FFFFFF)
DrawText(15,150,"Click on 2",$FF0000,$FFFFFF)
StopDrawing()
EndIf
If OpenWindow(#Window_Main,0,0,640,480,"Fading Child Window on Parent",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
ButtonGadget(#Button_1,5,5,20,20,"1")
ButtonGadget(#Button_2,5,25,20,20,"2")
ButtonGadget(#Button_3,5,45,20,20,"3")
hWin=OpenWindow(#Window_Child,WindowX(#Window_Main)+323,WindowY(#Window_Main)+GetSystemMetrics_(#SM_CYCAPTION )+3,320,240,"",#PB_Window_BorderLess|#PB_Window_Invisible,WindowID(#Window_Main))
ImageGadget(#ImageGadget,0,0,320,240,ImageID(#ImageImage))
SetWinOpacity(hWin,255):a=1
SetWindowCallback(@CallBack())
HideWindow(#Window_Child,0):DisableGadget(#ImageGadget,1)
Repeat
Event=WaitWindowEvent()
If Event=#PB_Event_Gadget
Button=EventGadget()
If Button=#Button_1 And a<>1
a=1
FadeWindow(500,255,0)
StartDrawing(ImageOutput(#ImageImage))
Box(0,0,320,240,$FFFFFF)
DrawingFont(MyFont)
DrawText(15,10,"This Example Shows",$999999,$FFFFFF)
DrawText(15,50,"how I use Window",$999999,$FFFFFF)
DrawText(15,90,"Fading...",$999999,$FFFFFF)
DrawText(15,150,"Click on 2",$FF0000,$FFFFFF)
StopDrawing()
SetGadgetState(#ImageGadget,ImageID(#ImageImage))
FadeWindow(500,0,255)
EndIf
If Button=#Button_2 And a<>2
a=2
FadeWindow(500,255,0)
StartDrawing(ImageOutput(#ImageImage))
Box(0,0,320,240,$FFFF00)
DrawingFont(MyFont)
DrawText(15,10,"By placing a Child",$999999,$FFFF00)
DrawText(15,50,"Window on a Parent",$999999,$FFFF00)
DrawText(15,90,"Window...",$999999,$FFFF00)
DrawText(15,150,"Click on 3",$0000FF,$FFFF00)
StopDrawing()
SetGadgetState(#ImageGadget,ImageID(#ImageImage))
FadeWindow(500,0,255)
EndIf
If Button=#Button_3 And a<>3
a=3
FadeWindow(500,255,0)
StartDrawing(ImageOutput(#ImageImage))
Box(0,0,320,240,$00FFFF)
DrawingFont(MyFont)
DrawText(15,10,"Thanks to PureLust",$999999,$00FFFF)
DrawText(15,50,"for help with a bit",$999999,$00FFFF)
DrawText(15,90,"of the fading code.",$999999,$00FFFF)
DrawText(15,150,"Click on 1",$00BB00,$00FFFF)
StopDrawing()
SetGadgetState(#ImageGadget,ImageID(#ImageImage))
FadeWindow(500,0,255)
EndIf
EndIf
If Event=#PB_Event_CloseWindow
Quit=1
EndIf
Until Quit=1
EndIf
End