Page 1 of 1

Fading Child Window on Parent

Posted: Sun Dec 12, 2010 4:57 am
by electrochrisso
Copy the code and run it, there are plenty of possibilities, have fun. :)

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

Re: Fading Child Window on Parent

Posted: Sun Dec 12, 2010 6:23 am
by netmaestro
Good try, but it isn't a child window. If it were it would have the WS_CHILD style bit set, you wouldn't need to manage the WM_MOVE event as it would be automatic and when you clicked back and forth between the two windows, the first window wouldn't show its focused state changing. You can't layer a child window, the OS doesn't allow it.

Btw, put a sizegadget on the first window and see the result.

Re: Fading Child Window on Parent

Posted: Sun Dec 12, 2010 7:21 am
by PureLust
netmaestro wrote:Good try, but it isn't a child window.
I think, it's a common mistake to call these kind of windows "child windows" and outcomes from the fact, that the last Parameter in "OpenWindow()" is called "ParentWindowID".
This naming implied, that the new window will be a "child" of the "ParentWindow", even if it's not a "Child-Window" in the API-Sense. .

Re: Fading Child Window on Parent

Posted: Mon Dec 13, 2010 2:37 am
by electrochrisso
Netmaestro you are correct, as PureLust pointed out I called it a child window because I set the parent window flag on the first window. I have made this example simple but will work on another to take care of the sizing issue.
Netmaestro, when you say "You can't layer a child window, the OS doesn't allow it", that the way I have done it so far is at least pointing in the right direction and I just tidy up sizing issues etc. or is it dangerous to layer windows altogether. :?:

Anyway thanks for the feedback. :)

Re: Fading Child Window on Parent

Posted: Mon Dec 13, 2010 9:16 pm
by yrreti
Just playing around, I took your code and modified it so that the resize works like it normally does.
Try it and see. The Fade image stays within the main window when moving and keeps it's window
position when resizing.
EDIT: Actually it still needs a little tweaking. Because if you resize over the image side and bottom
at the same time, it messes up a little, but out of time to do more right now, so see what you can do.

Code: Select all

Enumeration
  #Window_Main
  #Window_Child
  #Button_1
  #Button_2
  #Button_3
  #ImageGadget
  #ImageImage
EndEnumeration

Global hWin,Opacity,xc,yc,wc,hc,xcd,ycd,nw,nh
nw=320
nh=240

Procedure SetWinOpacity(hWin.l,Opacity.l)
  SetWindowLong_(hWin,#GWL_EXSTYLE,#WS_EX_LAYERED);#WS_EX_LAYERED=$00080000
  SetLayeredWindowAttributes_(hWin,0,Opacity,2)
EndProcedure

Procedure CallBack(hWnd,Msg,wParam,lParam)
  Result=#PB_ProcessPureBasicEvents
  Select Msg
  Case #WM_MOVE
    xm = WindowX(#Window_Main)
    ym = WindowY(#Window_Main)
    xp=xm+xcd
    yp=ym+ycd
    ResizeWindow(#Window_Child, xp, yp, nw, nh);320, 240)
  EndSelect
  ProcedureReturn Result
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_SizeGadget|#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))
  xm = WindowX(#Window_Main)
  ym = WindowY(#Window_Main)
  wm = WindowWidth(#Window_Main)
  hm = WindowHeight(#Window_Main)
  xc = WindowX(#Window_Child)
  yc = WindowY(#Window_Child)
  wc = WindowWidth(#Window_Child)
  hc = WindowHeight(#Window_Child)
  xcd=xc-xm;distance position from left side
  ycd=yc-ym;distance position from top side
  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_SizeWindow
      xm = WindowX(#Window_Main)
      ym = WindowY(#Window_Main)
      wm = WindowWidth(#Window_Main)
      hm = WindowHeight(#Window_Main)
      xc = WindowX(#Window_Child)
      yc = WindowY(#Window_Child)
      wc = WindowWidth(#Window_Child)
      hc = WindowHeight(#Window_Child)
      xcd=xc-xm;distance position from left side
      ycd=yc-ym;distance position from top side
      
      xp=xm+xcd
      yp=ym+ycd
      
      ;right side position
      rmp=xm+wm
      rcp=xc+wc
      If rmp<rcp-2;-2 for border
        nw=wc-(rcp-rmp)
        If nw<1
          nw=1
        EndIf
      Else
        nw= 320
      EndIf
      
      ;bottom position
      bmp=ym+hm
      bcp=yc+hc
      If bmp<bcp-2
        nh=hc-(bcp-bmp)
        If nh<1
          nh=1
        EndIf
      Else
        nh= 240
      EndIf
      
      ResizeWindow(#Window_Child, xp, yp, nw, nh)
      While WindowEvent()
      Wend   ;redraw window
      
    EndIf
    
    If Event=#PB_Event_CloseWindow
      Quit=1
    EndIf    
    
  Until Quit=1
EndIf

End

Fading Window on Parent ID

Posted: Tue Dec 14, 2010 12:29 am
by electrochrisso
I have changed the naming of the Child Window to Fading Window to try for a more correct description.
I have also made modifications for window resizing as well as included a couple of tips from PureLust.
yrreti thanks for your input and I will check through your code, but on first look it does not seem to work on the system I am using now, XP Home SP3 on old laptop, can you check my latest version and see if it works on yours.

Code: Select all

;
; Fading Window on Parent ID, by Electrochrisso
;

Enumeration
  #Window_Main
  #Window_Fade
  #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,#WM_SIZE
      GetWindowRect_(WindowID(#Window_Main),win.RECT)
      x=win\left:y=win\top
      SetWindowPos_(WindowID(#Window_Fade),0,x+WindowWidth(#Window_Main)-316,y+GetSystemMetrics_(#SM_CYCAPTION	)+4,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
  SetWinOpacity(hWin, FadeEndOpacity)
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 Window on Parent ID",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered)
  WindowBounds(#Window_Main,400,300,#PB_Ignore,#PB_Ignore)
  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_Fade,WindowX(#Window_Main)+323,WindowY(#Window_Main)+GetSystemMetrics_(#SM_CYCAPTION	)+4,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_Fade,0):DisableGadget(#ImageGadget,1):SetActiveWindow(#Window_Main);DisableWindow(#Window_Fade,1)
  
  Repeat
    Event=WaitWindowEvent()
    If EventWindow()=#Window_Fade And EventType()=#PB_EventType_LeftClick
      SetActiveWindow(#Window_Main)
    EndIf
    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 Fade",$999999,$FFFF00)
          DrawText(15,50,"Window onto Parent",$999999,$FFFF00)
          DrawText(15,90,"ID 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
	SetLayeredWindowAttributes_(hWin,#Null,#Null,#LWA_ALPHA)
	SetWindowLong_(hWin,#GWL_EXSTYLE,GetWindowLong_(hWin,#GWL_EXSTYLE) & ~#WS_EX_LAYERED  & ~#WS_EX_TRANSPARENT)
EndIf

End

Re: Fading Child Window on Parent

Posted: Tue Dec 14, 2010 5:18 am
by PureLust
I'm not sure, if it was your target to place the fading-window at the top right position inside the main-window.
If so, you should use "GetSystemMetric_()" with #SM_CXSIZEFRAME, #SM_CYSIZEFRAME and #SM_CYCAPTION to calculate the right position.
(You will find further informations about the available SystemMetric-Settings in the MSDN.)

Just try the following example, if you were looking for a top right positioning:

Code: Select all

;
; Fading Window on Parent ID, by Electrochrisso
;

Enumeration
  #Window_Main
  #Window_Fade
  #Button_1
  #Button_2
  #Button_3
  #ImageGadget
  #ImageImage
EndEnumeration

Global hWin,Opacity

Procedure CallBack(hWnd,Msg,wParam,lParam)
	Result=#PB_ProcessPureBasicEvents
	Protected BorderWidth    = GetSystemMetrics_(#SM_CXSIZEFRAME)		; Width  of the Windowborder on a resizeable Window
	Protected BorderHeight   = GetSystemMetrics_(#SM_CYSIZEFRAME)		; Height of the Windowborder on a resizeable Window
	Protected TitleBarHeight = GetSystemMetrics_(#SM_CYCAPTION)		; Height of the caption (titlebar)
	Select Msg
		Case #WM_MOVE,#WM_SIZE
			GetWindowRect_(WindowID(#Window_Main),win.RECT)
			innerleft    = win\left  + BorderWidth
			innertop     = win\top   + BorderHeight + TitleBarHeight
			innerright   = innerleft + WindowWidth(#Window_Main)
			innerbottom  = innertop  + WindowHeight(#Window_Main)     
			SetWindowPos_(WindowID(#Window_Fade), 0, innerright - WindowWidth(#Window_Fade), innertop, 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
  SetWinOpacity(hWin, FadeEndOpacity)
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 Window on Parent ID",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered)
  WindowBounds(#Window_Main,400,300,#PB_Ignore,#PB_Ignore)
  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_Fade,WindowX(#Window_Main)+323,WindowY(#Window_Main)+GetSystemMetrics_(#SM_CYCAPTION   )+4,320,240,"",#PB_Window_BorderLess|#PB_Window_Invisible,WindowID(#Window_Main))
  ImageGadget(#ImageGadget,0,0,320,240,ImageID(#ImageImage))
  
  ; ---------------------------------------------------
  PostMessage_(WindowID(#Window_Main), #WM_SIZE,0,0)  ; <<< fire a #WM_SIZE to the Window, to force a repositioning of the Fade-Window via the callback
  ; ---------------------------------------------------
  
  SetWinOpacity(hWin,255):a=1
  SetWindowCallback(@CallBack())
  HideWindow(#Window_Fade,0):DisableGadget(#ImageGadget,1):SetActiveWindow(#Window_Main);DisableWindow(#Window_Fade,1)
  
  Repeat
    Event=WaitWindowEvent()
    If EventWindow()=#Window_Fade And EventType()=#PB_EventType_LeftClick
      SetActiveWindow(#Window_Main)
    EndIf
    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 Fade",$999999,$FFFF00)
          DrawText(15,50,"Window onto Parent",$999999,$FFFF00)
          DrawText(15,90,"ID 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
   SetLayeredWindowAttributes_(hWin,#Null,#Null,#LWA_ALPHA)
   SetWindowLong_(hWin,#GWL_EXSTYLE,GetWindowLong_(hWin,#GWL_EXSTYLE) & ~#WS_EX_LAYERED  & ~#WS_EX_TRANSPARENT)
EndIf

End
Cue: Try to use "EnableExplicit" all the time, to prevent malfunctions by typos.

Re: Fading Child Window on Parent

Posted: Thu Dec 16, 2010 12:52 am
by electrochrisso
Tanks PureLust I really appreciate your help and have decided to learn a bit more about the API and have started downloading some tutorials and references, let me know if you can refer me to any that may be more suitable to PB programming.

I realised that I would have to change the callback to what you have done after checking on Vista the original callback was lacking as the placement was a little out compared to XP and your callback alignes nicely on both, so I need to take more care and thought when writing API code as it can be quite complex to work with.

And I will also start to use EnableExplicit as you suggested too.