Sign in to follow this  
Followers 0
Randoii

Invisible GUI help

4 posts in this topic

Hello all,

I've been trying to modify a little script someone made.

He/She made a GUI with a polygon.

now i tried to make it transparent but it wont work, cant seem to figure out how to fix this.

Original:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $hGUI, $hGraphic, $aPoints[4][2]

    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)
    GUISetState()

    ; Draw a polygon
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)

    $aPoints[0][0] = 3
    $aPoints[1][0] = 150
    $aPoints[1][1] = 150
    $aPoints[2][0] = 200
    $aPoints[2][1] = 100
    $aPoints[3][0] = 250
    $aPoints[3][1] = 150

    MsgBox(4096, "Information", "Fill Polygon")

    _GDIPlus_GraphicsFillPolygon($hGraphic, $aPoints)

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Clean up resources
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()

EndFunc   ;==>_Main

Modified by me:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $hGUI, $hGraphic, $aPoints[4][2]
    Dim $DS_SETFOREGROUND, $WS_EX_TOPMOST, $WS_EX_TRANSPARENT

    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300, $DS_SETFOREGROUND, $WS_EX_TOPMOST + $WS_EX_TRANSPARENT)
    GUISetState()

    ; Draw a polygon
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)

    $aPoints[0][0] = 3
    $aPoints[1][0] = 150
    $aPoints[1][1] = 150
    $aPoints[2][0] = 200
    $aPoints[2][1] = 100
    $aPoints[3][0] = 250
    $aPoints[3][1] = 150

    MsgBox(4096, "Information", "Fill Polygon")

    _GDIPlus_GraphicsFillPolygon($hGraphic, $aPoints)

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Clean up resources
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()

EndFunc   ;==>_Main

Share this post


Link to post
Share on other sites



Part of your problem is probably here:

Dim $DS_SETFOREGROUND, $WS_EX_TOPMOST, $WS_EX_TRANSPARENT

You declared the variables, but didn't give them a value so they effectively do nothing. Get rid of that line, and add #include <WindowsConstants.au3> at the top of your script to make sure those variables contain the correct information.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thank you,

I now got rid of the error, but still the gui is not transparent yet.

Ill check the help file if i can find anything more on this.

Share this post


Link to post
Share on other sites

Thanks for your help, but i searched a little better on the forum here and found what i was looking for

And thanks UEZ for this one:

;coded by UEZ 2011
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

Global $hGUI, $hImage, $hGraphic, $hImage
Global Const $SC_DRAGMOVE = 0xF012
_GDIPlus_Startup()
; Load PNG image
$hImage = _GDIPlus_ImageLoadFromFile("Audiograbber_512x512_transparent.png")
$iWidth = _GDIPlus_ImageGetWidth($hImage)
$iHeight = _GDIPlus_ImageGetHeight($hImage)

; Create GUI
$hGUI = GUICreate("Show PNG", $iWidth, $iHeight, -1, -1, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST)
$hGUI_child = GUICreate("", $iWidth, $iHeight, 0, 0, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST + $WS_EX_MDICHILD, $hGUI)
$hButton = GUICtrlCreateButton("Exit", $iWidth * 2 / 3, $iHeight * 2 / 3, 40, 40)
GUISetBkColor(0xFFFFFF, $hGUI_child)
GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hGUI_child)
SetTransparentBitmap($hGUI, $hImage)
_WinAPI_SetLayeredWindowAttributes($hGUI_child, 0xFFFFFF, 0xff)

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI_child)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
DllCall($ghGDIPDll, "uint", "GdipSetTextRenderingHint", "handle", $hGraphic, "int", 4)
_GDIPlus_GraphicsDrawString($hGraphic, "GDI+ Full Transparency", 0, $iHeight / 2 - 20, "Arial", 24)

GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $hButton
            GUIRegisterMsg($WM_LBUTTONDOWN, "")
            _GDIPlus_ImageDispose($hImage)
            _GDIPlus_GraphicsDispose($hGraphic)
            _GDIPlus_Shutdown()
            GUIDelete($hGUI)
            ExitLoop
    EndSwitch
WEnd

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndFunc   ;==>_WM_LBUTTONDOWN

Func SetTransparentBitmap($hGUI, $hImage, $iOpacity = 0xFF)
    Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
    $hScrDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
    DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow($hGUI,  $hMemDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
EndFunc   ;==>SetTransparentBitmap

Problem solved

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  
Followers 0