Jump to content

Transparent GUI with solid label controls


Go to solution Solved by Melba23,

Recommended Posts

Posted

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.

Posted

Maybe example of _WinAPI_CreateRectRgn() gives you an idea.

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.

  • Moderators
  • Solution
Posted

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

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

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

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

Things you should know first...In the beginning there was only ONE! And zero...

Progs:

  Reveal hidden contents
Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text
Posted (edited)

#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
Posted

  On 3/25/2014 at 12:43 PM, Melba23 said:

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:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
  • Recently Browsing   0 members

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