Sign in to follow this  
Followers 0
dickep

Make a transparent window with "buttons" showing

10 posts in this topic

I have looked here and cannot seem to find what can help me.

What I want is a window that is completely transparent with some circles in it. The circles (colored) should be the ONLY thing showing. Later, the circle color will change per some calculations in the app.

I just need to figure out how to make the main window "invisible" with only the colored circles showing.

I have put in some code I have been trying. Maybe this could be a start point - or not.

Thanks

E

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global $ctrlGraphic = 0, $iColor = 0xFFFFFF, $oColor = 0x00ff66, $mColor = 0x00ff00
Global $count = 1

Global $hGUI = GUICreate("Draw Test", 300, 300)
GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
GUISetState()
WinSetTrans($hGUI,"",100)

_Redraw()
HotKeySet("g", "_Redraw") ; Hit 'g' to redraw graphic

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _Redraw()
    consolewrite($ctrlGraphic)
    If $ctrlGraphic Then
        GUICtrlDelete($ctrlGraphic)
        $iColor -= 0x404040
        If $iColor < 0 Then $iColor = 0xFFFFFF
    EndIf
    $ctrlGraphic = GUICtrlCreateGraphic(10, 10, 280, 280)
    WinSetTrans($ctrlGraphic,"",100)
    ConsoleWrite("Debug: $ctrlGraphic = " & $ctrlGraphic & "; $iColor = 0x" & Hex($iColor) & @LF)
    ;GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetColor(-1, 0)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, $iColor)
    GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 10,10,20,20)
    if mod($count,2) = 0 Then
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, $iColor)
    ElseIf mod($count,3) = 0 Then
        GUICtrlSetGraphic(-1,$GUI_GR_COLOR, 0 , $oColor)
    Else
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, $mColor)
    EndIf
    GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 10,50, 20,20)
    if mod($count,2) = 0 Then
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, $oColor)
    ElseIf mod($count,3) = 0 Then
        GUICtrlSetGraphic(-1,$GUI_GR_COLOR, 0 , $mColor)
    Else
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, $iColor)
    EndIf
    GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 10,90,20,20)
    if mod($count,2) = 0 Then
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, $mColor)
    ElseIf mod($count,3) = 0 Then
        GUICtrlSetGraphic(-1,$GUI_GR_COLOR, 0 , $iColor)
    Else
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, $oColor)
    EndIf
    GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 10,130,20,20)
    GUICtrlSetGraphic(-1, $GUI_GR_REFRESH)
EndFunc   ;==>ReDraw

Share this post


Link to post
Share on other sites



dickep,

Here is a simple example of a transparent GUI with "buttons" which you can change as the script runs. Just click on the red one!

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WINAPI.au3>

$hGUI = GUICreate("Test", 500, 500, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
GUISetBkColor(0xABCDEF)

$hPic_1 = GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\Advanced\Images\Red.bmp", 10, 10, 15, 15)
$hPic_2 = GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\Advanced\Images\Green.bmp", 100, 10, 15, 15)
$hPic_3 = GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\Advanced\Images\Blue.bmp", 200, 10, 15, 15)

_WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF, 250)

GUISetState()

$fState = True

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hPic_1
            $fState = Not $fState
            If $fState = True Then
                GUICtrlSetImage($hPic_2, "C:\Program Files\AutoIt3\Examples\GUI\Advanced\Images\Green.bmp")
                GUICtrlSetImage($hPic_3, "C:\Program Files\AutoIt3\Examples\GUI\Advanced\Images\Blue.bmp")
            Else
                GUICtrlSetImage($hPic_2, "C:\Program Files\AutoIt3\Examples\GUI\Advanced\Images\Blue.bmp")
                GUICtrlSetImage($hPic_3, "C:\Program Files\AutoIt3\Examples\GUI\Advanced\Images\Green.bmp")
            EndIf
    EndSwitch

WEnd

I used the AutoIt bmps to guarantee you would have them - to get round buttons, you would need to create/download some suitable .gifs with transparent backgrounds.

I hope this helps. :mellow:

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!!! This is almost what I wanted, but a GREAT improvement over mine. I am still looking over the code trying to figure out what/how you did it.

However - I downloaded a couple of GIF's with transparent backgrounds and, well, they have a black area making them square with a button in the middle. Not sure why.

Also, I can't relocate the "window". Need that and resizing, but will wait for other stuff first.

I have attached the GIF's I used to see if you get the same results.

Thanks again

E

images.rar

Share this post


Link to post
Share on other sites

dickep,

Set the background colour of the GUI to 0x000000 and use the same colour in the WinAPI call - your gifs have a black background and need that colour made transparent in the GUI. Once I do that, I get round buttons with no problem.

Dragging the window is posing a problem. I know of 3 ways to move a $WS_POPUP GUI - and none of them work once you add the layered style. I will keep looking.

As for resize - I do not how you can do that at the moment, but again I will keep looking.

So, only 1 out 3 so far - I will try to do better! :mellow:

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,

No, 1 of 3 is GREAT!!! You really do know this - I wish I knew 10% of what you do.

And I really do appreciate your help and will look forward to seeing what I can do with this.

E

Share this post


Link to post
Share on other sites

dickep,

Got the dragging working. You will need something on the GUI to grab hold of - as you can see I am currently using a label with the $GUI_WS_EX_PARENTDRAG style. That was one of the ways I thought of at first, but I could not see the label when I created it. Stupid me - the default text colour is the same as the colour we have set as the transparent colour. Hardly surprising I could not see it! :mellow:

Anyway, I just set the Default GUI text colour to something other than pure black - it makes no difference to the label text appearance.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WINAPI.au3>

$hGUI = GUICreate("Test", 500, 500, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
GUISetBkColor(0x000000)
GUICtrlSetDefColor(0x010101, $hGUI)

$hPic_1 = GUICtrlCreatePic("M:\Program\Au3 Scripts\0005a.gif", 10, 10, 30, 30)
$hPic_2 = GUICtrlCreatePic("M:\Program\Au3 Scripts\0035a.gif", 100, 10, 30, 30)
$hPic_3 = GUICtrlCreatePic("M:\Program\Au3 Scripts\0036a.gif", 200, 10, 30, 30)

GUICtrlCreateLabel("Click on the text to drag this transparent GUI" & @CRLF & "Press ESC to exit", 10, 50, 480, 50, -1, $GUI_WS_EX_PARENTDRAG)

_WinAPI_SetLayeredWindowAttributes($hGUI, 0x000000, 250)

GUISetState()

$fState = True

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hPic_1
            $fState = Not $fState
            If $fState = True Then
                GUICtrlSetImage($hPic_2, "M:\Program\Au3 Scripts\0035a.gif")
                GUICtrlSetImage($hPic_3, "M:\Program\Au3 Scripts\0036a.gif")
            Else
                GUICtrlSetImage($hPic_2, "M:\Program\Au3 Scripts\0036a.gif")
                GUICtrlSetImage($hPic_3, "M:\Program\Au3 Scripts\0035a.gif")
            EndIf
    EndSwitch

WEnd

Resizing remains difficult. One problem is that the GUI has no edges to grab hold of - it is essentially "not there" as far as Windows is concerned. A question - why do you want to resize it anyway? As the GUI does not really exist, why not make it as big as you need to begin with and then show/hide the additional controls as required?

2 out of 3! We are getting there! :(

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,

You are AWESOME!!! 2 of 3 is enough for me - unless you want to investigate more for "personal challenge".

I wanted to resize since the object I am building could go full screen down to about 100x100 size.

I have another problem, but am trying to work that out myself. Not related to this, general programming problem - sometimes can't see forest for the grass (or is that trees - oh, well).

Again, you ROCK sir!!!

E

Share this post


Link to post
Share on other sites

dickep,

Nothing to stop you using WinMove if you know the size you want. But as I said, the GUI essentially "does not exist" - so I can see little point in resizing it any smaller than the largest size you could want.

Shall I keep a look out for a post in the General Help forum? :mellow:

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

I will try the WinMove but not sure how to implement it because (1) I am not that familiar with AutoIt and (2) you stated very well that the window really "does not exist" so not sure how/what to grab to resize.

No, I figured out what I needed. Just played enough that I got something working.

Now, if you want to critique my code, I can post it and let you have at it.

Thanks again for your diligence and excellent help.

You are the AutoIt man!

E

Share this post


Link to post
Share on other sites

One more thing - just an FYI.

I was playing around with the GUICtrlCreatePic item(s) and put in the ,-1,$GUI_WS_EX_PARENTDRAG at the end of each line.

Now I can pick any button and drag the window where I want it. Melba23 inspired me and the help files, well, really do HELP.

Now to just get it working again - seems I got it out of sync and is not transparent anymore.

Thanks Melba23.

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