WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Boxes Examples from Users

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Transparent Splash Example

 Keywords: Transparent Splash Popup Graphic Picture Captionless Borderless Irregular Border Box SetLayeredWindowAttributes GetWindowLongA SetWindowLongA

;==================================
;SplashWindow UDF   ....IFICantBYTE
;hWindow       = handle to the window we want to make transparent, captionless and borderless (Popup style)
;AlphaBlend    = a value from 0 to 255 to control the amount any visible part of the window will be blended with the windows beneath it
;TransColorRGB = a pipe delimited string of decimal "RED|GREEN|BLUE" values for the color we want to make our transparent one
;
;Returns the previous window style values in a TAB delimited string
;-----------------------
#DefineFunction SplashWindow(hWindow,AlphaBlend,TransColorRGB)
Terminate("2-5-0" > WinVersion(5),"Error","Need Windows 2000 or above for this to work")
WS_EX_LAYERED = 524288
WS_CAPTION = 12582912
WS_POPUP = 2147483648
GWL_STYLE = -16
GWL_EXSTYLE = -20
LWA_ALPHA = 2
LWA_COLORKEY = 1

r = ItemExtract(1,TransColorRGB,"|")
g = ItemExtract(2,TransColorRGB,"|")
b = ItemExtract(3,TransColorRGB,"|")
TransColor = b*256*256 + g*256 + r
USER32 = DirWindows(1):"USER32.DLL"

OldStyle = DllCall(USER32, long:"GetWindowLongA", long:hWindow, long:GWL_STYLE)
;NewStyle = OldStyle ^ WS_CAPTION
NewStyle = WS_POPUP
DllCall(USER32, long:"SetWindowLongA", long:hWindow, long:GWL_STYLE, long:NewStyle)

OldExStyle = DllCall(USER32,long:"GetWindowLongA",long:hWindow,long:GWL_EXSTYLE)
NewExStyle = OldExStyle ^ WS_EX_LAYERED

DllCall(USER32,long:"SetWindowLongA",long:hWindow,long:GWL_EXSTYLE,long:NewExStyle)

DllCall(USER32,long:"SetLayeredWindowAttributes",long:hwindow,long:TransColor,long:AlphaBlend,long:LWA_ALPHA|LWA_COLORKEY)

Return(OldStyle:@TAB:OldExStyle);return previous styles

#EndFunction
;=================================



;!!!!!!!!!!!
;In this example we will use a simple WinBatch box as our transparent splash screen - you could fairly easily use a Dialog box or any other window.
;This will only work on Windows 2000 or newer
;!!!!!!!!!!!

BMP = "C:\Program Files\WinBatch\System\wbowl.bmp" ;change it to whatever works for you - this BMP has a black background, so I chose black as the transparent color.

BoxColor(1,"0,0,0",0) ;sets the background color - in this example we are using BLACK as the color to become transparent - you can change it to anything you like.
BoxDrawRect(1,"0,0,1000,1000",2) ;object which will use the color - a black box filling the window
BoxTextColor(1,"255,0,0")
BoxTextFont(1, "", 70, 0, 0)
BoxDrawText(1, "0,30,950,150", "Transparent Splash Example by ....IFICantBYTE", @TRUE,1)
BoxBitMap(1, "300,160,700,900" , BMP, 3) ;Draw our BMP picture on the window


AlphaBlend = 200 ; 0 to 255 where 0 is invisible and 255 is fully solid
TransparentColor = "0|0|0" ; Black is our chosen transparent color in this example - you can change it to anything you like
WindowHandle = DllHwnd("") ; A handle to the window we want to make transparent and Popup style (ie. no Caption or borders) - in this example we use this WB window itself


PreviousStyles = SplashWindow(WindowHandle,AlphaBlend,TransparentColor);Do it! and return previous window styles so we can set them back later if we like

BoxesUp("200,200,800,800", @NORMAL);Show it!

TimeDelay(5)
;If you wanted to keep the Window open and put it back to normal, then uncomment the following lines which should reset the styles
;DllCall(DirWindows(1):"USER32.DLL",long:"SetWindowLongA",long:WindowHandle,long:-20,long:ItemExtract(2,PreviousStyles,@TAB))
;DllCall(DirWindows(1):"USER32.DLL", long:"SetWindowLongA", long:WindowHandle, long:-16, long:ItemExtract(1,PreviousStyles,@TAB))
;BoxesUp("200,200,800,800", @NORMAL);Back to normal
;TimeDelay(5)

Exit

Article ID:   W17687
Filename:   Transparent Splash Example.txt
File Created: 2011:11:08:09:05:56
Last Updated: 2011:11:08:09:05:56