Re: borderless image on the desktop

new topic     » goto parent     » topic index » view thread      » older message » newer message
sergelli said...

The bitmap plotted onto the window shows the selected color with transparency, perfectly.

I used the same background color for the bitmap and for the window {0,0,255}

But the back color of window, is not transparent.

How do I make a transparent window?

Doing some more testing, it looks like you need a few more functions to get this working correctly. What you need to do is create a "layered" window and then tell Windows what color to make transparent. This method will work on all versions of Windows since 2000.

Save this as layered.ew and include it into your program.

include Win32Lib.ew 
 
public constant 
	xSetLayeredWindowAttributes = registerw32Function( user32, "SetLayeredWindowAttributes", {C_LONG,C_LONG,C_LONG,C_LONG}, C_UINT ) 
 
public constant 
	LWA_COLORKEY	= #0001, 
	LWA_ALPHA		= #0002 
 
public procedure setLayeredWindow( integer id, integer layered = w32True ) 
 
	integer has = controlStyle( id, WS_EX_LAYERED, w32True, STYLE_HAS ) 
	if layered and not has then 
		controlStyle( id, WS_EX_LAYERED, w32True, STYLE_ADD ) 
	elsif has and not layered then 
		controlStyle( id, WS_EX_LAYERED, w32True, STYLE_REMOVE ) 
	end if 
 
end procedure 
 
public procedure setWindowColorKey( integer id, object colorKey ) 
 
	atom hWnd = getHandle( id ) 
	if sequence( colorKey ) then colorKey = colorValue( colorKey ) end if 
	w32Func( xSetLayeredWindowAttributes, {hWnd,colorKey,NULL,LWA_COLORKEY} ) 
	 
end procedure 
 
public procedure setWindowAlpha( integer id, integer alpha ) 
 
	atom hWnd = getHandle( id ) 
	alpha = and_bits( alpha, #FF ) 
	w32Func( xSetLayeredWindowAttributes, {hWnd,NULL,alpha,LWA_ALPHA} ) 
	 
end procedure 

Then between your create() statements and your WinMain() call, set these options:

-- make this a layered window, (you could also 
-- use createEx() with the WS_EX_LAYERED flag) 
setLayeredWindow( Main, w32True ) 
 
-- the window alpha defaults to zero, which makes it 
-- invisible, so set it back to 255 (100%) instead 
setWindowAlpha( Main, 255 ) 
 
-- set the 'transparent' color key (use your color here) 
setWindowColorKey( Main, #FF00FF ) 

-Greg

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu