Jump to content

[SOLVED - WORKAROUND]Setting transparency of a single gui pic element to 60% or so


tip
 Share

Recommended Posts

Hi to all,

I'm trying to set transparency of a gui ctrl created with guictrlcreatepic(). It is not a background image and I don't want to make my gui transparent. I just want to set transparency of a single element to 60%. Just like the white box in following jpg:

P.S.: It is not my gui. I just made it in Gimp to explain what I have in mind :x...

I've read more than several topics in the forum but all of them was about creating a transparent gui and transparent png background image.

Thanks everybody in advance.

Regards

Tip

Edited by tip

[center]MsgBox_Tipped: Eye candy msgboxes/inputboxes/loginboxes. | CreateBlankBox: Semi-transparent layers with borders and rounded corners.[/center]

Link to comment
Share on other sites

Not perfect, but a child gui works.

#include <WindowsConstants.au3>

$hGUI = GUICreate(@ScriptName, 320, 240)
GUISetState()

$hChild = GUICreate(@ScriptName, 75, 25, 10, 10, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetState()

$cIdButton = GUICtrlCreateButton("Press me!", 0, 0, 75, 25)
WinSetTrans($hChild, "", 128)

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $cIdButton
            MsgBox(0, "I'm a title", "You pressed the button!!")
    EndSwitch
WEnd
Link to comment
Share on other sites

Thanks for the reply. I have thought of it too but I prefer not to use a child gui because on top of that transparent bar I'd like to put some labels.

If I put the labels on the parent gui and then use a semi-transprent child gui, child gui(transparent bar) overlaps them. If I create a semi-transparent gui and put the labels on them, the labels look hazy :P. So, if possible, I perefer to set guictrlcreatepic's transparency :x...

Thanks again.

Regards

Tip

Edited by tip

[center]MsgBox_Tipped: Eye candy msgboxes/inputboxes/loginboxes. | CreateBlankBox: Semi-transparent layers with borders and rounded corners.[/center]

Link to comment
Share on other sites

  • 2 weeks later...

Hi to all again,

With help from trancexx I've found a way to create a semi-transparent box over background pic and under the other ctrls.

It is not perfect but it does the job.

I've created a semi-transparent white box png with Gimp. Then I load it using trancexx GifAnimation UDF. The only catch is to set iARGB to 0xFFFFFF. I think that constant is responsible of the background color of semi-transparent elements. If I set to 0 or leave as default -I think it was 0xFF000000- it creates a greyish semi-transparent box.

Regards

Tip

[center]MsgBox_Tipped: Eye candy msgboxes/inputboxes/loginboxes. | CreateBlankBox: Semi-transparent layers with borders and rounded corners.[/center]

Link to comment
Share on other sites

Link to comment
Share on other sites

Link to comment
Share on other sites

Why? Why not! It is an alternative and not a must do stuff! And GDI+ isn't so complicated as it seems to be.

It is a matter of taste...

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

It is a matter of taste...

This matter of profitability and size of code. If there is a dialog "About" then what is the point to create the image programmatically when can we all do in one line by using the native AutoIt function GUICtrl... Edited by Yashied
Link to comment
Share on other sites

Here one possible and very simple GDI+ code:

#include <GDIPlus.au3>
#include <WindowsConstants.au3>

_GDIPlus_Startup()
$hBitmap = _GDIPlus_BitmapCreateFromFile("Ex.jpg")
$iW =  _GDIPlus_ImageGetWidth($hBitmap)
$iH =  _GDIPlus_ImageGetHeight($hBitmap)
$hGUI = GUICreate("GDI+ Test", $iW, $iH)
GUISetState()

$hBrush = _GDIPlus_BrushCreateSolid(0x99E0E0F0)
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iW, $iH)
_GDIPlus_GraphicsFillRect ($hGraphic, 25, 225, 550, 160, $hBrush)

GUIRegisterMsg($WM_PAINT, "WM_PAINT")

While GUIGetMsg() <> -3
WEnd

_GDIPlus_BrushDispose($hBrush)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
GUIDelete($hGUI)
Exit

Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam, $lParam
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW + $RDW_INVALIDATE)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iW, $iH)
    _GDIPlus_GraphicsFillRect ($hGraphic, 25, 225, 550, 160, $hBrush)
    Return  "GUI_RUNDEFMSG"
EndFunc

It is larger than the "native" AutoIt function but much flexible in creating "effects"! If you just want to load an image and display it then use the native functions.

You need the raw Ex.jpg without the polygon to see it properly.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Hi,

I found GDI+ func are not very good with semi-transparent images. I will try to explain the problem but it is a bit complicated, so bare with me.

I maybe wrong here but, if I use GDI funcs to draw an image I need to register a "DrawAll" (WM_PAINT I think) func too, right? That DrawAll func redraws the image if a part/all of it goes of the screen etc. If I use GDI funcs to draw it and register a DrawAll func to keep it alive, when a part of it goes of the screen DrawAll func redraws it. So far so good. But it draws another image on top of the first image without removing the first one. This gives you 2 semi-transparent images on top of each other making a nearly non-transparent layer. It doesn't happen if all of the image goes of the screen, it happens only if a part of the image is off screen and you can see the rest. :x).

That's why I didn't use GDI+ func and prefered trancexx UDF.

Edited by tip

[center]MsgBox_Tipped: Eye candy msgboxes/inputboxes/loginboxes. | CreateBlankBox: Semi-transparent layers with borders and rounded corners.[/center]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...