Jump to content
Sign in to follow this  
JRowe

Transparency issue, UpdateLayeredWindow

Recommended Posts

JRowe

So, I'm trying to set the transparency of a window I'm rendering to using Au3Irrlicht.

What I'd like to do is simply have a particular color rendered as transparent. I've tried everything I can find on the forums, and thus far nothing has worked (in particular, SetLayeredWindowAttributes for transparency.)

Does anyone know how to easily set a keycolor for a transparent gui?

I want to have all pixels of the color 255, 0, 255 be transparent, and everything else rendered normally.

Thanks!

//////////

Update:

Ok, so I've poked around with the UpdateLayeredWindow function, which seems to be what I need.

The only questions I'm having are as follows:

$hWnd = $gui
$hDCDest = _WinAPI_GetDC($hWnd)
$pPTDest = 0
$pSize = 0
$hDCSrce = _WinAPI_CreateCompatibleDC(0)
$pPTSrce = $tagPOINT;;;;;;;;;;;;?????
$iRGB = 0xFF00FF
$pBlend = $tagBLENDFUNCTION 
$iFlags = $ULW_COLORKEY

_WinAPI_UpdateLayeredWindow($hWnd, $hDCDest, $pPTDest, $pSize, $hDCSrce, $pPTSrce, $iRGB, $pBlend, $iFlags)

How do I set $pPTSrce?

What is $pBlend?

I believe that after I answer those questions, this should work.Thanks!

Edited by jrowe

Share this post


Link to post
Share on other sites
JRowe

Ok, so msdn has informed me that I should set everything to 0 except hWnd, crKey, and pblend. hWnd and crKey are easy... just the handle and the RGB colorkey.

What the heck is pblend? lol. I'm trying to find other references, but so far it's been fruitless. Thanks again.

Share this post


Link to post
Share on other sites
JRowe

CODE

#include <GUIConstants.au3>

#include <Constants.au3>

#include <WindowsConstants.au3>

#include <WINAPI.au3>

#include "IrrlichtPluginUtils.au3"

;############# Constants ##########

Global Const $LWA_ALPHA = 0x2

Global Const $LWA_COLORKEY = 0x1

;############# Example ############

#Region - GUI Create

$gui = GUICreate("trans", 300, 400, -1, -1, -1, $WS_EX_LAYERED)

GUICtrlCreateLabel("This is text on a transparent Layered GUI", 10, 10, 200, 20, -1, $GUI_WS_EX_PARENTDRAG)

GUICtrlSetTip(-1, "Click label to drag layered window")

$layButt = GUICtrlCreateButton("Button", 10, 40, 40)

GUISetBkColor(0xABCDEF)

_WinAPI_SetLayeredWindowAttributes($gui, 0x010101)

CreateDeviceOnWindow( $gui, $EDT_OPENGL, 10, 10, 320, 240, 32, 0, 0 )

GUISetState()

$guicontrol = GUICreate("ControlGUI", 300, 400, 100, 100)

$checkTrans = GUICtrlCreateCheckbox("Transparent color 0xABCDEF (Checked) Or 0x010101", 10, 10)

$checkBorder = GUICtrlCreateCheckbox("POPUP-Style", 10, 30)

GUICtrlCreateLabel("Transparency for Layered GUI", 10, 50)

$slidTrans = GUICtrlCreateSlider(10, 70, 200, 30)

GUICtrlSetLimit($slidTrans, 255, 0)

GUICtrlSetData(-1, 255)

GUISetState()

#EndRegion - GUI Create

$Camera = AddCameraSceneNode( 0, 0, 25, -40, 0, 0, 0 )

$Node = AddCubeSceneNode( 20 )

$Au3Texture = GetTexture( "data\au3.bmp" )

SetMaterialTexture( $Node, 0, $Au3Texture )

SetMaterialFlag( $Node, $EMF_LIGHTING, 0 )

$Y = 0

$Direction = 2

#Region - GUI SelectLoop

While IrrRun( )

SetRotation( $Node, 0, $Y, 0 )

BeginScene( true, true, 0, 171, 205, 239 )

SceneDraw( )

GuiDraw( )

EndScene( )

sleep( 20 )

$Y += $Direction

If $Y > 360 Then $Y -= 360

If $Y < 0 Then $Y += 360

$extMsg = GUIGetMsg(1)

$msg = $extMsg[0]

Switch $extMsg[1]

Case $guicontrol

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

Case $msg = $checkTrans Or $msg = $slidTrans

; Change Attributes of Trans-Color and Window Transparency

If BitAND(GUICtrlRead($checkTrans), $GUI_CHECKED) = $GUI_CHECKED Then

_WinAPI_SetLayeredWindowAttributes($gui, 0xABCDEF, GUICtrlRead($slidTrans))

Else

_WinAPI_SetLayeredWindowAttributes($gui, 0x010101, GUICtrlRead($slidTrans))

EndIf

Case $msg = $checkBorder

If BitAND(GUICtrlRead($checkBorder), $GUI_CHECKED) = $GUI_CHECKED Then

GUISetStyle($WS_POPUP, -1, $gui)

Else

GUISetStyle($GUI_SS_DEFAULT_GUI, -1, $gui)

EndIf

EndSelect

Case $gui

Select

Case $msg = $layButt

Dim $transcolor, $alpha

$info = _WinAPI_GetLayeredWindowAttributes($gui,$transcolor, $alpha)

MsgBox(0, 'Layered GUI', "Button on layered Window Clicked" & @CRLF & "Information about this window: " & @CRLF & _

"Transparent Color: " & $transcolor & @CRLF & _

"Alpha Value: " & $alpha & @CRLF & _

"LWA_COLORKEY: " & (BitAND($info,$LWA_COLORKEY)=$LWA_COLORKEY) & @CRLF & _

"LWA_ALPHA: " & (BitAND($info,$LWA_ALPHA)=$LWA_ALPHA) )

Case $msg = $GUI_EVENT_CLOSE

Exit MsgBox(0, '', "Close from Layered GUI")

EndSelect

EndSwitch

WEnd

#EndRegion - GUI SelectLoop

;############# EndExample #########

;===============================================================================

;

; Function Name: _WinAPI_SetLayeredWindowAttributes

; Description:: Sets Layered Window Attributes:) See MSDN for more informaion

; Parameter(s):

; $hwnd - Handle of GUI to work on

; $i_transcolor - Transparent color

; $Transparency - Set Transparancy of GUI

; $isColorRef - If True, $i_transcolor is a COLORREF( 0x00bbggrr ), else an RGB-Color

; Requirement(s): Layered Windows

; Return Value(s): Success: 1

; Error: 0

; @error: 1 to 3 - Error from DllCall

; @error: 4 - Function did not succeed - use

; _WinAPI_GetLastErrorMessage or _WinAPI_GetLastError to get more information

; Author(s): Prog@ndy

;

; Link : @@MsdnLink@@ SetLayeredWindowAttributes

; Example : Yes

;===============================================================================

;

Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False)

If $dwFlages = Default Or $dwFlages = "" Or $dwFlages < 0 Then $dwFlages = 0x03

If Not $isColorRef Then

$i_transcolor = Hex(String($i_transcolor), 6)

$i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))

EndIf

Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $dwFlages)

Select

Case @error

Return SetError(@error, 0, 0)

Case $Ret[0] = 0

Return SetError(4, _WinAPI_GetLastError(), 0)

Case Else

Return 1

EndSelect

EndFunc ;==>_WinAPI_SetLayeredWindowAttributes

;===============================================================================

;

; Function Name: _WinAPI_GetLayeredWindowAttributes

; Description:: Gets Layered Window Attributes:) See MSDN for more informaion

; Parameter(s):

; $hwnd - Handle of GUI to work on

; $i_transcolor - Returns Transparent color ( dword as 0x00bbggrr or string "0xRRGGBB")

; $Transparency - Returns Transparancy of GUI

; $isColorRef - If True, $i_transcolor will be a COLORREF( 0x00bbggrr ), else an RGB-Color

; Requirement(s): Layered Windows

; Return Value(s): Success: Usage of LWA_ALPHA and LWA_COLORKEY (use BitAnd)

; Error: 0

; @error: 1 to 3 - Error from DllCall

; @error: 4 - Function did not succeed

; - use _WinAPI_GetLastErrorMessage or _WinAPI_GetLastError to get more information

; - @extended contains _WinAPI_GetLastError

; Author(s): Prog@ndy

;

; Link : @@MsdnLink@@ GetLayeredWindowAttributes

; Example : Yes

;===============================================================================

;

Func _WinAPI_GetLayeredWindowAttributes($hwnd, ByRef $i_transcolor, ByRef $Transparency,$asColorRef = False)

$i_transcolor = -1

$Transparency = -1

Local $Ret = DllCall("user32.dll", "int", "GetLayeredWindowAttributes", "hwnd", $hwnd, "long*", $i_transcolor, "byte*", $Transparency, "long*", 0)

Select

Case @error

Return SetError(@error, 0, 0)

Case $Ret[0] = 0

Return SetError(4, _WinAPI_GetLastError(), 0)

Case Else

If Not $asColorRef Then

$Ret[2] = Hex(String($Ret[2]), 6)

$Ret[2] = '0x' & StringMid($Ret[2], 5, 2) & StringMid($Ret[2], 3, 2) & StringMid($Ret[2], 1, 2)

EndIf

$i_transcolor = $Ret[2]

$Transparency = $Ret[3]

Return $Ret[4]

EndSelect

EndFunc ;==>_WinAPI_GetLayeredWindowAttributes

So, this works, but there is no color or texture to the rendered 3D object. It appears as a white 'shadow' of the 3D object (in this case, it's a cube.)

Any help would be greatly appreciated. :mellow:

Share this post


Link to post
Share on other sites
JRowe

And strangely, it works when I use the newest software renderer. I can now render 3D objects to the screen, sans windows, etc. woot :mellow:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.