Jump to content

Child Window of Desktop ( transparent )


Bluesmaster
 Share

Recommended Posts

Hello Community,

I want to create some boxes on my desktop. The boxes have to recognize mouse clicks so I use labels to represent the boxes border.

The problem:

If I make the window transparent it will no longer accept mouse clicks. This behavior only appears when I make the window a child of the desktop.

; GUI
$WS_POPUP          = 0x80000000
$WS_EX_LAYERED     = 0x00080000
$GUI_desktop_Child = GUICreate( "" , 500 , 200 , 500 , 500 , $WS_POPUP ,  $WS_EX_LAYERED  )
GUISetBkColor( 0x00FF00 )
GUISetState()

    ; BOX
    GUICtrlCreateLabel( "" ,  5 , 5 , 300 , 5   )
    GUICtrlSetBkColor( -1 , 0xEA0000   )
    GUICtrlCreateLabel( "" ,  5 , 100 , 300 , 5   )
    GUICtrlSetBkColor( -1 , 0xEA0000   )
    GUICtrlCreateLabel( "" ,  5 , 5 , 5 , 100   )
    GUICtrlSetBkColor( -1 , 0xEA0000   )
    GUICtrlCreateLabel( "" ,  300 , 5 , 5 , 100   )
    GUICtrlSetBkColor( -1 , 0xEA0000   )


; MAKE CHILD OF DESKTOP & ALPHA MASK
$hDeskWin=_WinGetDesktopHandle()
DllCall("user32.dll", "int", "SetParent", "hwnd", $GUI_desktop_Child , "hwnd", $hDeskWin )
DllCall( "user32.dll" , "bool", "SetLayeredWindowAttributes", "hwnd", $GUI_desktop_Child, "dword",   0x00FF00 , "byte", 250, "dword",  0x03 ) ; ( has to be executed AFTER! making it childwindow )



HotKeySet( "{ESC}" , "_exit" )
Func _exit()
    Exit
EndFunc


While 1
    Sleep(50)
WEnd



Func _WinGetDesktopHandle()

    Local $i,$hDeskWin,$hSHELLDLL_DefView,$hListView
    ; The traditional Windows Classname for the Desktop, not always so on newer O/S's
    $hDeskWin=WinGetHandle("[CLASS:Progman]")
    ; Parent->Child relationship: Desktop->SHELLDLL_DefView
    $hSHELLDLL_DefView=ControlGetHandle($hDeskWin,'','[CLASS:SHELLDLL_DefView; INSTANCE:1]')
    ; No luck with finding the Desktop and/or child?
    If $hDeskWin='' Or $hSHELLDLL_DefView='' Then
    ; Look through a list of WorkerW windows - one will be the Desktop on Windows 7+ O/S's
    $aWinList=WinList("[CLASS:WorkerW]")
    For $i=1 To $aWinList[0][0]
    $hSHELLDLL_DefView=ControlGetHandle($aWinList[$i][1],'','[CLASS:SHELLDLL_DefView; INSTANCE:1]')
    If $hSHELLDLL_DefView<>'' Then
    $hDeskWin=$aWinList[$i][1]
    ExitLoop
    EndIf
    Next
    EndIf
    ; Parent->Child relationship: Desktop->SHELDLL_DefView->SysListView32
    $hListView=ControlGetHandle($hSHELLDLL_DefView,'','[CLASS:SysListView32; INSTANCE:1]')
    If $hListView='' Then Return SetError(-1,0,'')
    Return SetExtended($hListView,$hDeskWin)

EndFunc

BoxOnDesktop.au3

( note, this will only work on windows 8 as there child windows accept the $WS_EX_LAYERED property )

How can I make the gui accept mouse clicks?

 

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Link to comment
Share on other sites

Hi,
Here you go :

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
 
$hGUI = GUICreate("MyGUI", 50, 50, 50, 50, BitOR($WS_POPUP, $WS_CHILD), $WS_EX_TRANSPARENT, _WinAPI_GetDesktopWindow())
GUISetBkColor(0xFF0000)
GUISetState(@SW_SHOW, $hGUI)
 
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $GUI_EVENT_PRIMARYDOWN
            ConsoleWrite("primary down" & @CrLf)
    EndSwitch
WEnd
 
GUIDelete($hGUI)

Edit: If you want to make it layered, then use the WinAPI function for it ;) (_WinAPI_SetLayeredWindowAttributes)

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

Hi Firefox,

Thanks for your suggestion. Unfortunately your solution has some drawbacks.

1. its not really a child window of the desktop I meant ( the explorer window with the icons  ) but a child of the "desktop" as root of the window tree

2. Due to this it as toplevel-window appears above other windows on creation and disappears on "toogleDesktop"

I found a  solution that was very complicated to figure out ( took me  2 days ). I will post it later.

 

regards

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Link to comment
Share on other sites

2. Due to this it as toplevel-window appears above other windows on creation

_WinAPI_SetWindowPos($hGUI, $HWND_BOTTOM, 0, 0, 0, 0, BitOR($SWP_NOACTIVATE, $SWP_NOMOVE, $SWP_NOSIZE))

GUISetState(@SW_SHOWNOACTIVATE, $hGUI)

and disappears on "toogleDesktop"

This can not be overrided, but I would like to see your code anyway :)

Br, FireFox.

Link to comment
Share on other sites

Well a snippet says more than a thousand words. Gui 1-3 demostrate some problems I had. Gui 4 fits my needs where magic effect of "winmove" is remarkable.

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


; GUI 1 - DISAPPEARS - ...on toogle Desktop
$hGUI = GUICreate("MyGUI", 50, 50, 50, 50, BitOR( $WS_POPUP, $WS_CHILD ), $WS_EX_TRANSPARENT , _WinAPI_GetDesktopWindow() )
GUISetBkColor(0xFF0000)
GUISetState(@SW_SHOW, $hGUI)



; GUI 2 - CLICKTROUGH - Cannot receive mouse clicks
;~ $WS_POPUP         = 0x80000000
$hGUI2 = GUICreate( "" ,  200 , 100 ,  200 , 200 , $WS_POPUP ,  0x00080000  ) ; $WS_EX_LAYERED = 0x00080000
GUISetBkColor( 0xff0000 )
DllCall("user32.dll", "int", "SetParent", "hwnd", $hGUI2 , "hwnd", _WinGetDesktopHandle() )
DllCall( "user32.dll" , "bool", "SetLayeredWindowAttributes", "hwnd", $hGUI2 , "dword",   0x00FF00 , "byte", 250, "dword",  0x03 ) ; ( has to be executed AFTER! making it childwindow )
GUISetState()



; GUI 2 - BLUR - Can receive mouse clicks but appears blur on non black background
$hGUI3 = GUICreate( "" ,  100 , 200 ,  800 , 500 , $WS_POPUP   )
GUISetBkColor( 0xff0000 )
DllCall("user32.dll", "int", "SetParent", "hwnd", $hGUI3 , "hwnd", _WinGetDesktopHandle() )
GUISetState()



; GUI 3 - GOOD - is not blurred and can receive mouse clicks
$hGUI4 = GUICreate( "" ,  200 , 100 ,  200 , 200 , $WS_POPUP ,  0x00080000  ) ; $WS_EX_LAYERED = 0x00080000
GUISetBkColor( 0xff0000 )
DllCall("user32.dll", "int", "SetParent", "hwnd", $hGUI4 , "hwnd", _WinGetDesktopHandle() )
DllCall( "user32.dll" , "bool", "SetLayeredWindowAttributes", "hwnd", $hGUI4, "dword",   0x00FF00 , "byte", 250, "dword",  0x03 ) ; ( has to be executed AFTER! making it childwindow )
WinMove( $hGUI4 , "" , 500 ,  500 )
GUISetState()




HotKeySet("{ESC}", "_Exit")
Func _Exit()
    Exit
EndFunc


$i = 11
While 1

$i += 15
Sleep( 50 )
;~ WinMove( $hGUI1 , "" , $i ,  $i )

WEnd


Func _WinGetDesktopHandle()
    $aWinList=WinList("[CLASS:WorkerW]")
        For $i=1 To $aWinList[0][0]
            $hSHELLDLL_DefView=ControlGetHandle($aWinList[$i][1],'','[CLASS:SHELLDLL_DefView; INSTANCE:1]')
            If $hSHELLDLL_DefView<>'' Then
                $hDeskWin=$aWinList[$i][1]
                ExitLoop
            EndIf
        Next
    ; Parent->Child relationship: Desktop->SHELDLL_DefView->SysListView32
    $hListView=ControlGetHandle($hSHELLDLL_DefView,'','[CLASS:SysListView32; INSTANCE:1]')
    Return SetExtended($hListView,$hDeskWin)
EndFunc

regards

Bluesmaster

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Link to comment
Share on other sites

  • 9 years later...
  • Developers

What is wrong with your ability to read? When i request you to stop resurrecting old post I do mean you have to stop with that...

...and the next post resurrects again a 9 years old thread. 

You have now 2 options:

1. Confirm to me you understood and won't do this again.

2. You ignore my post and you will be banned.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...