Page 1 of 1

Alpha Blending in XP

Posted: Sun Aug 28, 2005 5:47 pm
by ricardo
Code updated for 5.20+

Maybe most of you already know how to do it, i put it here in case someones don't.

I think only works in XP (however i dont think anyone continue using w1895 :twisted: )

Code: Select all

;AlphaBlending test in XP by Ricardo (sunday morning, was bored)

#WS_EX_LAYERED = $80000
#LWA_ALPHA = $2

Procedure AlphaBlendIt()
  Alpha.b = GetGadgetState(1)
  SetWindowLong_(WindowID(0), #GWL_EXSTYLE, #WS_EX_LAYERED)
  SetLayeredWindowAttributes_(WindowID(0), 0, Alpha, #LWA_ALPHA)
EndProcedure

If OpenWindow(0,100,150,450,200,"Alpha Blending",#PB_Window_SystemMenu)
  TrackBarGadget(1,10,10,250,20,0,255,#PB_TrackBar_Ticks )
  SetGadgetState(1,200)
  ButtonGadget(2,200,70,150,25,"AlphaBlendIt")
  ButtonGadget(3,200,120,150,25,"Play a little")
  Repeat
    EventID=WaitWindowEvent()
    
    Select EventID
        
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 2
            AlphaBlendIt()
          Case 3
            For i = 0 To 250
              Delay(20)
              WindowEvent()
              Alpha.b = 250-i
              SetWindowLong_(WindowID(0), #GWL_EXSTYLE, #WS_EX_LAYERED)
              SetLayeredWindowAttributes_(WindowID(0), 0, Alpha, #LWA_ALPHA)
            Next
            SetWindowLong_(WindowID(0), #GWL_EXSTYLE, #WS_EX_LAYERED)
            SetLayeredWindowAttributes_(WindowID(0), 0, 250, #LWA_ALPHA)
        EndSelect
        
    EndSelect
    
  Until EventID=#PB_Event_CloseWindow
EndIf
*Lets try to do this to a menu

Posted: Sun Aug 28, 2005 6:07 pm
by ricardo
More fun:

Code: Select all

;AlphaBlending test in XP by Ricardo (sunday morning, was bored)

#WS_EX_LAYERED = $80000
#LWA_ALPHA = $2

Procedure AlphaBlendIt()
    Alpha.b = GetGadgetState(1)
    SetLayeredWindowAttributes_(WindowID(), 0, Alpha, #LWA_ALPHA)
EndProcedure

If OpenWindow(0,100,150,450,200,#PB_Window_SystemMenu,"Alpha Blending")
    CreateGadgetList(WindowID())
    TrackBarGadget(1,10,10,250,20,0,255,#PB_TrackBar_Ticks )
    SetGadgetState(1,200)
    ButtonGadget(2,200,70,150,25,"AlphaBlendIt")
    ButtonGadget(3,200,120,150,25,"Play a little")
    SetWindowLong_(WindowID(), #GWL_EXSTYLE, #WS_EX_LAYERED)
    SetLayeredWindowAttributes_(WindowID(), 0, 180, #LWA_ALPHA)
    Repeat
        EventID=WaitWindowEvent()
        Select EventID
            
            Case #PB_EventGadget
                Select EventGadgetID()
                    Case 2
                        AlphaBlendIt()
                    Case 3
                        For i = 0 To 250
                            Delay(5)
                            WindowEvent()
                            Alpha.b = 250-i
                            SetLayeredWindowAttributes_(WindowID(), 0, Alpha, #LWA_ALPHA)
                        Next
                        SetLayeredWindowAttributes_(WindowID(), 0, 250, #LWA_ALPHA)
                EndSelect
            Case #PB_EventCloseWindow
                For i = 0 To 250
                    WindowEvent()
                    Alpha.b = 250-i
                    SetLayeredWindowAttributes_(WindowID(), 0, Alpha, #LWA_ALPHA)
                Next
                Quit = 1
        EndSelect 
    Until Quit = 1
EndIf

Posted: Sun Aug 28, 2005 8:27 pm
by Fou-Lu
It doesn't work here with windows "1898SE" :? .
There are still many people using win9x out there, though. Besides that, a good program has to be compatible with other OS's... :wink:
Hopefully, Linux will conquer the world, and Windows will be banned from earth! Mwa-ha-ha-ha!!! :lol:

Posted: Sun Aug 28, 2005 8:50 pm
by rsts
But for those of us with XP - it's a neat effect.

Thanks for sharing

Posted: Sun Aug 28, 2005 9:14 pm
by ricardo
Fou-Lu wrote:It doesn't work here with windows "1898SE" :? .
Well, for the museum-windows versions :twisted: i think you can copy the image that is in the back of the window (i see some snippet there to do it) and colorize a little (to give the appareance of the Alpha Blending), im sure it will look the same.

Changing the value of the colorized you can give the feeling of making more or less Alpha Blending. I hope someone can help us with this trick.

*The joke about museum_windows version is juts that, a joke :D

Posted: Sun Aug 28, 2005 9:29 pm
by Num3
ricardo wrote:*The joke about museum_windows version is juts that, a joke :D
Smells like a flame war comming ... :twisted:

Posted: Mon Aug 29, 2005 12:27 am
by Fou-Lu
ricardo wrote:*The joke about museum_windows version is juts that, a joke :D
Don't worry, I'm aware 98 is museum-like. :wink: But you can stay with your XP-super-cool-Alphablending stuff! :? I preffer my nice blue screens! :lol:

Posted: Mon Aug 29, 2005 12:44 am
by Dare2
:D

Posted: Mon Aug 29, 2005 8:20 am
by dige
But be careful! If you simple use SetLayeredWindowAttributes_(), your
programm will completely not run on every WinNT or Win9x machine.
It is better to check if the function existis in the User32.dll and should called then with CallFunction...

Posted: Sat Sep 03, 2005 2:33 am
by lexvictory
according to ms docs this works in win 2000