Windows transparency from pixmap

BlitzMax Forums/MaxGUI Module/Windows transparency from pixmap

JoshK(Posted 2009) [#1]
I found some dead links and non-working code, but nothing to do this. I have an alpha-blended splash screen that fades out, and it would be cool if I could multiply the window transparency by the pixmap transparency per pixel, so the image background doesn't affect the underlying window:



klepto2(Posted 2009) [#2]
SuperStrict

Import maxgui.drivers

Extern "win32"
   Function SetWindowLongA(hWnd:Int, nIndex:Int, dwNewLong:Int)
   Function SetLayeredWindowAttributes(hwnd:Int, crKey:Int, bAlpha:Int, dwFlags:Int)	
EndExtern

Const GWL_STYLE:Int = -16
Const GWL_EXSTYLE:Int = $FFFFFFEC
Const WS_EX_LAYERED:Int = $80000
Const LWA_ALPHA:Int = 2
Const LWA_COLORKEY:Int = 1

Local window:TGadget = CreateWindow("Test",200,200,237,237,,WINDOW_CENTER)
Local panel:TGadget = CreatePanel(0,0,ClientWidth(window),ClientHeight(window),window)
SetGadgetPixmap(panel,LoadPixmap("lua_splash.png"),PANELPIXMAP_STRETCH)

Local win:Int=QueryGadget(window,QUERY_HWND)
Local old:Int=GetWindowLongA(win,GWL_STYLE)
Local newstyle:Int = old & WS_EX_LAYERED
Local style:Int=SetWindowLongA(win,GWL_EXSTYLE,newstyle)


SetWindowLongA(win, -20,  WS_EX_LAYERED)
SetLayeredWindowAttributes(win, RGB(255,255,255),128,LWA_COLORKEY|LWA_ALPHA)


While WaitEvent()

Wend

End

Function RGB:Int(R:Int,G:Int,B:Int,A:Int=0)
     Return A Shl 24 | R Shl 16 | G Shl 8 | B Shl 0
End Function



xlsior(Posted 2009) [#3]
Klepto2: That still looks the same to me -- the transparent part of the image still draws a faint box around the image, just like in Leadwerk's screenshot.


jsp(Posted 2009) [#4]
I suspect that you fiter on a color which is not the background then.
When using a white rectangle with a black circle on top as mask, it looks absolutely sharp. White used as filter.
And I can see the faint box (depending on the alpha of course), when filtering on the black.
Or do you mean something different? How does your image look like?


klepto2(Posted 2009) [#5]
sry, was in a hurry previously, here is a small explanation:

SetLayeredWindowAttributes(win, RGB(255,255,255),128,LWA_COLORKEY|LWA_ALPHA)

win = handle to the gadget (should be clear)
1st parameter = the MaskColor which will make the image transparent.
2nd parameter = the overall opacity (alpha value) in a range 0..255
3rd parameter = LWA_COLORKEY and/ or LWA_ALPHA

In my sample the mask color of the image is white RGB(255,255,255) because i used this image:



In most cases you will use a color which is less used like RGB(255,0,255).

I hope this helps.


JoshK(Posted 2009) [#6]
Cool, this makes a nice little touch!


xlsior(Posted 2009) [#7]
sry, was in a hurry previously, here is a small explanation:


Ah, I see -- works ok now, sorry about that.

Very, very nice!

Just out of curiosity: Are there any system requirements for this to function, or should it work on all PC's?

(e.g. only Vista /windows 7 with aero, or also on a plain vanilla Windows XP machine?)


klepto2(Posted 2009) [#8]
The transperancy key was introduced in Windows2000 as far as I remember. After a small research: this feature is available since Windows Me and 2000.


Arowx(Posted 2010) [#9]
Can you use something like this to make nice transparent graphical buttons?