Alpha Blending in XP

Share your advanced PureBasic knowledge/code with the community.
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Alpha Blending in XP

Post 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
ARGENTINA WORLD CHAMPION
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post 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
ARGENTINA WORLD CHAMPION
User avatar
Fou-Lu
Enthusiast
Enthusiast
Posts: 201
Joined: Tue Jul 12, 2005 8:30 am
Location: I'm pretty sure this is all a nightmare
Contact:

Post 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:

~Fou-Lu (aka Lørd Cinneris (actually Elias Sant'Ana))

Image Image
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

But for those of us with XP - it's a neat effect.

Thanks for sharing
ricardo
Addict
Addict
Posts: 2402
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post 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
ARGENTINA WORLD CHAMPION
Num3
PureBasic Expert
PureBasic Expert
Posts: 2810
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

ricardo wrote:*The joke about museum_windows version is juts that, a joke :D
Smells like a flame war comming ... :twisted:
User avatar
Fou-Lu
Enthusiast
Enthusiast
Posts: 201
Joined: Tue Jul 12, 2005 8:30 am
Location: I'm pretty sure this is all a nightmare
Contact:

Post 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:

~Fou-Lu (aka Lørd Cinneris (actually Elias Sant'Ana))

Image Image
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

:D
@}--`--,-- A rose by any other name ..
dige
Addict
Addict
Posts: 1247
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post 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...
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

according to ms docs this works in win 2000
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Post Reply