Jump to content
Sign in to follow this  
JohnOne

Transparent GUI with solid label controls

Recommended Posts

JohnOne

Never done much with GUI's and after a quick search cannot find anything.

Is it possible?

Say I have a transparent gui with one black square label, all you would see is the black square and not the static background, would not be worried about title bar or border.

Any suggestions, links, snidey comments welcome.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
funkey

Maybe example of _WinAPI_CreateRectRgn() gives you an idea.

  • Like 1

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites
Melba23

JohnOne,

This is how I have done it in the past: :)

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("", 400, 400, Default, Default, $WS_POPUP, BitOr($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))

$cExit = GUICtrlCreateButton(" Exit ", 10, 10, 80, 30)

; Must be within GUI window
$cLabel = GUICtrlCreateLabel("", 100, 100, 200, 200)
GUICtrlSetBkColor($cLabel, 0)

GUISetControlsVisible($hGUI)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $cExit
            Exit
    EndSwitch
WEnd

Func GUISetControlsVisible($hWnd)
    Local $aM_Mask, $aCtrlPos, $aMask

    $aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 0, "long", 0)
    $aLastID = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", GUICtrlGetHandle(-1))

    For $i = 3 To $aLastID[0]
        $aCtrlPos = ControlGetPos($hWnd, '', $i)
        If Not IsArray($aCtrlPos) Then ContinueLoop

        $aMask = DllCall("gdi32.dll", "long", "CreateRectRgn", _
            "long", $aCtrlPos[0], _
            "long", $aCtrlPos[1], _
            "long", $aCtrlPos[0] + $aCtrlPos[2], _
            "long", $aCtrlPos[1] + $aCtrlPos[3])
        DllCall("gdi32.dll", "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
    Next
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $hWnd, "long", $aM_Mask[0], "int", 1)
EndFunc
No doubt you can now replace the DllCalls with new WinAPI* functions. ;)

M23

  • Like 2

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
taietel

This is another approach:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
$hGUI = GUICreate("", 100, 100, -1,-1, $WS_POPUP, $WS_EX_LAYERED+$WS_EX_TOOLWINDOW)
GUISetBkColor(0xabcdef)
GUICtrlCreateLabel("Label1", 5, 5, 50, 50, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetBkColor(-1, 0xFF0000)
_WinAPI_SetLayeredWindowAttributes($hGUI,0xabcdef)
GUISetState(@SW_SHOW)

While 1
    Sleep(10)
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
  • Like 1

Share this post


Link to post
Share on other sites
mesale0077

#include <Constants.au3>
    #include <GUIConstantsEx.au3>
    #include <Misc.au3>
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>
     
    Global Const $SC_DRAGMOVE = 0xF012
     
    HotKeySet('{ESC}', '_Exit')
     
    Example()
     
    Func Example()
    Local $hGUI = GUICreate('', 100, 100, Default, Default, $WS_POPUP)
    _WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF)
     
    Local $iButton = GUICtrlCreateButton('Drag me', 0, 0, 100, 100)
    GUISetState(@SW_SHOW, $hGUI)
     
    Local $aCtrlCursor = 0, $aMousePos = 0, _
    $fMove = False, _
    $iBefore = 0
    While 1
    Switch GUIGetMsg()
    Case $iButton
    MsgBox($MB_SYSTEMMODAL, '', 'Button click')
    ; ExitLoop
     
    Case $GUI_EVENT_PRIMARYDOWN
    $aCtrlCursor = GUIGetCursorInfo($hGUI)
    $aMousePos = MouseGetPos()
    $fMove = False
    $iBefore = $aMousePos[0] + $aCtrlCursor[0] + $aMousePos[1] + $aCtrlCursor[1] ; Detect the co-ordinates before.
     
    While _IsPressed(01)
    WinMove($hGUI, '', $aMousePos[0] - $aCtrlCursor[0], $aMousePos[1] - $aCtrlCursor[1])
    ; _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, False)
    ; If the co-ordinates are different then it moved.
    $fMove = Not ($aMousePos[0] + $aCtrlCursor[0] + $aMousePos[1] + $aCtrlCursor[1] = $iBefore)
    $aMousePos = MouseGetPos()
    If @error Then ExitLoop
    WEnd
     
    ; If it moved clear the button message.
    If $fMove Then
    Do ; Clear the button message.
    Until GUIGetMsg() = 0
    EndIf
     
    EndSwitch
    WEnd
     
    GUIDelete($hGUI)
    EndFunc ;==>Example
     
    Func _Exit()
    Exit
    EndFunc ;==>_Exit

or

#include <Constants.au3>
    #include <GUIConstantsEx.au3>
    #include <Misc.au3>
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>
     
    Global Const $SC_DRAGMOVE = 0xF012
     
    HotKeySet('{ESC}', '_Exit')
     
    Example()
     
    Func Example()
    Local $hGUI = GUICreate('', 400, 400,  -1,-1, $WS_POPUP, $WS_EX_LAYERED+$WS_EX_TOOLWINDOW)
    GUISetBkColor(0xabcdef)
   
     
; Must be within GUI window
Local $cLabel = GUICtrlCreateLabel("", 100, 100, 200, 200)
GUICtrlSetBkColor($cLabel, 0)
    Local $iButton = GUICtrlCreateButton(" Exit ", 10, 10, 80, 30)
 _WinAPI_SetLayeredWindowAttributes($hGUI, 0xABCDEF)
    GUISetState(@SW_SHOW, $hGUI)
     
    Local $aCtrlCursor = 0, $aMousePos = 0, _
    $fMove = False, _
    $iBefore = 0
    While 1
    Switch GUIGetMsg()
    Case $iButton
    MsgBox($MB_SYSTEMMODAL, '', 'Button click')
    exit
    ; ExitLoop
     
    Case $GUI_EVENT_PRIMARYDOWN
    $aCtrlCursor = GUIGetCursorInfo($hGUI)
    $aMousePos = MouseGetPos()
    $fMove = False
    $iBefore = $aMousePos[0] + $aCtrlCursor[0] + $aMousePos[1] + $aCtrlCursor[1] ; Detect the co-ordinates before.
     
    While _IsPressed(01)
    WinMove($hGUI, '', $aMousePos[0] - $aCtrlCursor[0], $aMousePos[1] - $aCtrlCursor[1])
    ; _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, False)
    ; If the co-ordinates are different then it moved.
    $fMove = Not ($aMousePos[0] + $aCtrlCursor[0] + $aMousePos[1] + $aCtrlCursor[1] = $iBefore)
    $aMousePos = MouseGetPos()
    If @error Then ExitLoop
    WEnd
     
    ; If it moved clear the button message.
    If $fMove Then
    Do ; Clear the button message.
    Until GUIGetMsg() = 0
    EndIf
     
    EndSwitch
    WEnd
     
    GUIDelete($hGUI)
    EndFunc ;==>Example
     
    Func _Exit()
    Exit
    EndFunc ;==>_Exit
Edited by mesale0077
  • Like 1

Share this post


Link to post
Share on other sites
mLipok

JohnOne,

This is how I have done it in the past: :)

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("", 400, 400, Default, Default, $WS_POPUP, BitOr($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))

$cExit = GUICtrlCreateButton(" Exit ", 10, 10, 80, 30)

; Must be within GUI window
$cLabel = GUICtrlCreateLabel("", 100, 100, 200, 200)
GUICtrlSetBkColor($cLabel, 0)

GUISetControlsVisible($hGUI)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $cExit
            Exit
    EndSwitch
WEnd

Func GUISetControlsVisible($hWnd)
    Local $aM_Mask, $aCtrlPos, $aMask

    $aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 0, "long", 0)
    $aLastID = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", GUICtrlGetHandle(-1))

    For $i = 3 To $aLastID[0]
        $aCtrlPos = ControlGetPos($hWnd, '', $i)
        If Not IsArray($aCtrlPos) Then ContinueLoop

        $aMask = DllCall("gdi32.dll", "long", "CreateRectRgn", _
            "long", $aCtrlPos[0], _
            "long", $aCtrlPos[1], _
            "long", $aCtrlPos[0] + $aCtrlPos[2], _
            "long", $aCtrlPos[1] + $aCtrlPos[3])
        DllCall("gdi32.dll", "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
    Next
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $hWnd, "long", $aM_Mask[0], "int", 1)
EndFunc
No doubt you can now replace the DllCalls with new WinAPI* functions. ;)

M23

 

 

Very nice script.

mLipok


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-03-17

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  

×