Sign in to follow this  
Followers 0
ZetupEXE

Transparent GUI and Picture

11 posts in this topic

Hi there,

well thanks a lot to this Forum i've got several good ideas and hints for solving problems with autoIT. The Forum helps me a lot like for doin this:

http://www.911cd.net/forums//index.php?showtopic=22523

but now i've got a problem, that's going to make me crazy. hope you guys can help me out.

i like to have a transparent gui, and within this gui, i like to have a picture with transparent background. the picture have a drop shadow, is an png file with alpha channel and should be placed within the gui. my aim is to get the transparent gui with the picture inside to look smooth. well, my english isn't as good as it should be, so please take the example script and get an idea of what my problem is. the edge of the picture is crispy.

if someone knew how to get the picture looking smooth with or without gui, my thanks is yours.

cu

Zetup-exe

test.zip

Share this post


Link to post
Share on other sites



ZetupEXE,

It looks as if some of the pixels on the edge of the shadow have the same value as the background, which gives you the ragged/"crispy" look when they too become transparent. If you were to replace the background with another colour value you might be able to get a smoother look - all will depend on your skill in choosing the correct pixels on the shadow edge to change/leave alone.

I hope you had nothing planned over Xmas, because it might well take some time......... ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

@Melba23: Thanks for you advice. I tried a lot of colors (mabe thousands ;) ) but it doesnt work. the crispy look is where the smooth black drop shadow goes! so i think it's rather, that the color which should be transparent isn't exactly the "transparentcolor" anymore.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

@Melba23: Thanks for you advice. I tried a lot of colors (mabe thousands ;) ) but it doesnt work. the crispy look is where the smooth black drop shadow goes! so i think it's rather, that the color which should be transparent isn't exactly the "transparentcolor" anymore.

I am no expert on transparency but I think you are almost doomed to fail. To make the effect you want the window and button have to be redrawn every time the background changes. If the background stays the same then there is an easy way to do waht you want.

If you run the script using your mouse then you have 2 seconds to place the mouse cursor where you want the button to appear.

; *** Start added by AutoIt3Wrapper ***
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <screencapture.au3>
; *** End added by AutoIt3Wrapper ***
#AutoIt3Wrapper_Add_Constants=n
;Global Const $GUI_DISABLE = 128
#include "G:\icons\Icons.au3"

Sleep(2000)

ButtonGui()


; ButtonGui (Gui welche beim Drücken des mittleren Mausbuttons aufgerufen wird)
Func ButtonGui()
    Local $mousepos = MouseGetPos()
    MouseMove($mousepos[0] - 50, $mousepos[1], 0)
    _ScreenCapture_Capture("fake.jpg", $mousepos[0] - 24, $mousepos[1] - 24, $mousepos[0] + 104, $mousepos[1] + 104)
    MouseMove($mousepos[0], $mousepos[1], 0)
    $bc = PixelGetColor($mousepos[0], $mousepos[1])

    $buttonGUI = GUICreate("ButtonGUI", 65, 60, $mousepos[0] - 24, $mousepos[1] - 24, $WS_POPUP + $WS_VISIBLE + $DS_SETFOREGROUND, BitOR(0x2000000, $WS_EX_TOOLWINDOW));, $WS_EX_LAYERED))
    $buttonPic = GUICtrlCreatePic("", 1, 1, 64, 64)
    _SetImage($buttonPic, "startButton.png")
    $bg = GUICtrlCreatePic("fake.jpg", 0, 0, 128, 128)
    GUICtrlSetState(-1, $GUI_DISABLE)

    GUICtrlSetState($buttonPic, $GUI_DISABLE)
    Sleep(9000)
    Exit

    GUISetState(@SW_SHOW)
    While 1
    Sleep(100)
    WEnd
EndFunc ;==>ButtonGui

EDIT:Added mouse moves so cursor was not included in screen capture.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Sometimes changing the transparent colour gives a different effect. I've had the same issue using an extracted icon and found darker colours work better.

GUISetBkColor(0x000000)
_API_SetLayeredWindowAttributes($buttonGUI,0x000000,255);set special colour fully transparent
Edited by picea892

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

#Include <GUIConstantsEx.au3>
#Include <Icons.au3>
#Include <WinAPIEx.au3>

$hForm = GUICreate('', 64, 64, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
$hBitmap = _Icons_Bitmap_Load(@ScriptDir & '\startButton.png')
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUISetState()

_SetBitmap($hForm, $hBitmap, 255)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _SetBitmap($hWnd, $hBitmap, $iOpacity)

    Local $hDC, $hMemDC, $tBlend, $tSize, $tSource

    $hDC = _WinAPI_GetDC($hWnd)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = _WinAPI_GetBitmapDimension($hBitmap)
    $tSource = DllStructCreate($tagPOINT)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    DllStructSetData($tBlend, 'Alpha', $iOpacity)
    DllStructSetData($tBlend, 'Format', 1)
    _WinAPI_UpdateLayeredWindow($hWnd, $hDC, 0, DllStructGetPtr($tSize), $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_DeleteDC($hMemDC)
EndFunc   ;==>_SetBitmap

Func WM_NCHITTEST($hWnd, $iMsg, $wParam, $lParam)
    Switch $hWnd
        Case $hForm
            Return $HTCAPTION
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NCHITTEST

Icons.au3

WinAPIEx.au3

Edited by Yashied

Share this post


Link to post
Share on other sites

That's nice Yashied!

Shame on me, I'd forgotten about your icons.au3.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
;) Very good Yashied, thanks.

Share this post


Link to post
Share on other sites

Yashied,

браво!

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

YES! that's it! thanks a lot

Share this post


Link to post
Share on other sites

#Include <GUIConstantsEx.au3>
#Include <Icons.au3>
#Include <WinAPIEx.au3>

$hForm = GUICreate('', 64, 64, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
$hBitmap = _Icons_Bitmap_Load(@ScriptDir & '\startButton.png')
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUISetState()

_SetBitmap($hForm, $hBitmap, 255)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _SetBitmap($hWnd, $hBitmap, $iOpacity)

    Local $hDC, $hMemDC, $tBlend, $tSize, $tSource

    $hDC = _WinAPI_GetDC($hWnd)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = _WinAPI_GetBitmapDimension($hBitmap)
    $tSource = DllStructCreate($tagPOINT)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    DllStructSetData($tBlend, 'Alpha', $iOpacity)
    DllStructSetData($tBlend, 'Format', 1)
    _WinAPI_UpdateLayeredWindow($hWnd, $hDC, 0, DllStructGetPtr($tSize), $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_DeleteDC($hMemDC)
EndFunc   ;==>_SetBitmap

Func WM_NCHITTEST($hWnd, $iMsg, $wParam, $lParam)
    Switch $hWnd
        Case $hForm
            Return $HTCAPTION
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NCHITTEST

Icons.au3

WinAPIEx.au3

This code is perfect for a splashscreen.

But how do I get it work with some more transparent PNGs on the gui?

At the moment the form is resized to the bitmap-size.

1) But what if I want to have more than one bitmap?

2) Also I tried

WinAPI_UpdateLayeredWindow($hWnd, $hDC, 0, 0, $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA)

like it is mentioned in the helpfile but that doesn't work.

2a) How can i prevent the form to resize itself to the bitmap-size without loosing transparency?

2b) Or how is it possible to resize it to a fixed (bigger) size than the bitmap without loosing transparency?

UTA

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