Jump to content

Child GUI inside hidden GUI not draggable


Leo1906
 Share

Recommended Posts

Hello there :)
I am trying to create a png GUI inside an invisible GUI. Why? Because I want to use invisible borders this would give me, so that you can only be able to drag the GUI within a given area and not outside. I want to achieve this because I don't want the GUI to get dragged on a second or third monitor on a multi-Dekstop system.

Creating a png GUI inside an normal GUI isn't that hard. I modified an example from  @UEZ to fit my needs:

#include <ButtonConstants.au3>
#include <MsgBoxConstants.au3>
#include <StructureConstants.au3>
#include <WinAPIConstants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


$hMain = GUICreate("Parent", 400, 400, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED,$WS_EX_TOOLWINDOW,$WS_EX_TOPMOST,$WS_EX_LAYERED))
_WinAPI_SetLayeredWindowAttributes($hMain, 0xABCDEF, 255)
GUISetBkColor(0xABCDEF)
GUISetState()

_GDIPlus_Startup()
Global Const $SC_DRAGMOVE = 0xF012
Global $iW, $iH, $hImage, $hBitmap, $hGUI
$hImage = _GDIPlus_BitmapCreateFromFile("C:\Program Files (x86)\AutoIt3\Examples\GUI\Torus.png")
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$iW = _GDIPlus_ImageGetWidth($hImage)
$iH = _GDIPlus_ImageGetHeight($hImage)
$hGUI = GUICreate("", $iW, $iH, 0, 0, $WS_POPUP, $WS_EX_LAYERED)
_WinAPI_SetParent($hGUI, $hMain)
GUISetState()
_WinAPI_BitmapDisplayTransparentInGUI($hBitmap, $hGUI)

;~ GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_WinAPI_DeleteObject($hBitmap)
_GDIPlus_BitmapDispose($hImage)
_GDIPlus_Shutdown()
GUIDelete()

Func _WinAPI_BitmapDisplayTransparentInGUI(ByRef $hHBitmap, ByRef $hGUI, $iOpacity = 0xFF, $bReleaseGDI = True)
    If Not BitAND(GUIGetStyle($hGUI)[1], $WS_EX_LAYERED) = $WS_EX_LAYERED Then Return SetError(1, 0, 0)
    Local $tDim = DllStructCreate($tagBITMAP)
    If Not _WinAPI_GetObject($hHBitmap, DllStructGetSize($tDim), DllStructGetPtr($tDim)) Then Return SetError(2, 0, 0)
    Local $tSize = DllStructCreate($tagSIZE), $tSource = DllStructCreate($tagPOINT), $tBlend = DllStructCreate($tagBLENDFUNCTION)
    Local Const $hScrDC = _WinAPI_GetDC(0), $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC), $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
    $tSize.X = $tDim.bmWidth
    $tSize.Y = $tDim.bmHeight
    $tBlend.Alpha = $iOpacity
    $tBlend.Format = 1
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, DllStructGetPtr($tSize), $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteDC($hMemDC)
    If $bReleaseGDI Then _WinAPI_DeleteObject($hHBitmap)
    Return True
EndFunc

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndFunc   ;==>_WM_LBUTTONDOWN

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc

This creates the invisible GUI and the png GUI inside. All works fine when the parent GUI is visible, you are able to drag the png GUI. But as soon as I make the parent GUI invisible, the child GUI can't be accessed. It is clearly visible, but you can't grab it. The mouse clicks just go through it.

The same applies if you try to create a normal GUI inside the parent GUI and set transparency to it. As soon as the transparency is set, the dragging seems to be disabled or you just can't activate or click it.
WinActivate the child GUI manually doesn't help, as well as getting the child GUIs handle from mouse position and reset it's transparency.
If you try to recieve the handle of the child GUI by the position of the mouse cursor you just get the handle of the GUI behind the child GUI. So you basically just see trough it ..

 

Is there any way to make the child GUI draggable?

Thanks in advance for your help :)

Link to comment
Share on other sites

Try this instead:

...
$hGUI = GUICreate("", $iW, $iH, -1, -1, $WS_POPUP, $WS_EX_LAYERED, $hMain)
;~ _WinAPI_SetParent($hGUI, $hMain)
GUISetState()
_WinAPI_BitmapDisplayTransparentInGUI($hBitmap, $hGUI)
...

 

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

44 minutes ago, UEZ said:

Try this instead:

...
$hGUI = GUICreate("", $iW, $iH, -1, -1, $WS_POPUP, $WS_EX_LAYERED, $hMain)
;~ _WinAPI_SetParent($hGUI, $hMain)
GUISetState()
_WinAPI_BitmapDisplayTransparentInGUI($hBitmap, $hGUI)
...

 

I tried this already .. Setting the parent like this doesn't seem to have the same effect like _WinAPI_SetParent
This unfortunately doesn't set the child GUI inside the parent GUI, so the invisible borders are gone .. the child GUI is draggable now, but with a setting like this I don't need to have it like child and parent ..

Link to comment
Share on other sites

2 hours ago, Leo1906 said:

Why? Because I want to use invisible borders this would give me, so that you can only be able to drag the GUI within a given area and not outside.

I still don't know / can't imagine why you are trying to display a PNG in a GUI within a GUI. How you are checking for the GUI position to stay in defined area?

 

Btw, is this working?

...
$hMain = GUICreate("Parent", 400, 400, -1, -1, $WS_POPUP, BitOR($WS_EX_MDICHILD,$WS_EX_LAYERED,$WS_EX_TOOLWINDOW,$WS_EX_TOPMOST))
...

 

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

1 hour ago, UEZ said:

I still don't know / can't imagine why you are trying to display a PNG in a GUI within a GUI. How you are checking for the GUI position to stay in defined area?

 

Btw, is this working?

...
$hMain = GUICreate("Parent", 400, 400, -1, -1, $WS_POPUP, BitOR($WS_EX_MDICHILD,$WS_EX_LAYERED,$WS_EX_TOOLWINDOW,$WS_EX_TOPMOST))
...

 

No it's not working ..

Ok, so let me explain a little ..
I have a GUI containing several child GUIs which each represent a task the programm is running. They can be deleted (and terminated) by dragging them out of the desktop. Whilest they are beeing dragged they change their transparency and at a certain point get deleted when you release them.
So far so good .. but on multi-monitor settings (like I am currentyl using) you can drag those GUIs out of the desktop and they get completly visible again which I don't want to happen. So I try to put them in an invisible area which they can't escape and which will be in one line with the @desktopwidth.
It's not about functionality, it's about appereance .. :D 

The second part is that I want to design my GUIs they way I want, not the way Windows says. I might be okay with transparent $WS_Popup GUIs, but setting transparency also don't let you move the GUIs.

Well .. it would be nice to get this to run, but I can't imagine any futher methods to achieve this .. It feels like I tried everything possible in pure Autoit. When it comes to DLLCalls and Build-In Windows functions I'm done with my skills .. :/ 

 

Edit: to let the GUIs stay in defined area I'm using this function here: 

And now I want the GUIs to stay inside the current dektop area ..

 

Edited by Leo1906
Link to comment
Share on other sites

What about this here?

#include <ButtonConstants.au3>
#include <MsgBoxConstants.au3>
#include <StructureConstants.au3>
#include <WinAPIConstants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


$hMain = GUICreate("Parent", 400, 400, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED,$WS_EX_TOPMOST))
;~ GUISetBkColor(0xABCDEF)
;~ _WinAPI_SetLayeredWindowAttributes($hMain, 0xABCDEF, 255)
GUISetState(@SW_SHOWNA, $hMain)

_GDIPlus_Startup()
Global Const $SC_DRAGMOVE = 0xF012
Global $iW, $iH, $hImage, $hBitmap, $hGUI
$hImage = _GDIPlus_BitmapCreateFromFile("C:\Program Files (x86)\AutoIt3\Examples\GUI\Torus.png")
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$iW = _GDIPlus_ImageGetWidth($hImage)
$iH = _GDIPlus_ImageGetHeight($hImage)
$hGUI = GUICreate("", $iW, $iH, 0, 0, BitOR(0,$WS_POPUP), $WS_EX_LAYERED)
_WinAPI_SetParent($hGUI, $hMain)

GUISetState(@SW_SHOW, $hGUI)

_WinAPI_BitmapDisplayTransparentInGUI($hBitmap, $hGUI)


;~ GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_WinAPI_DeleteObject($hBitmap)
_GDIPlus_BitmapDispose($hImage)
_GDIPlus_Shutdown()
GUIDelete()

Func _WinAPI_BitmapDisplayTransparentInGUI(ByRef $hHBitmap, ByRef $hGUI, $iOpacity = 0xFF, $bReleaseGDI = True)
    If Not BitAND(GUIGetStyle($hGUI)[1], $WS_EX_LAYERED) = $WS_EX_LAYERED Then Return SetError(1, 0, 0)
    Local $tDim = DllStructCreate($tagBITMAP)
    If Not _WinAPI_GetObject($hHBitmap, DllStructGetSize($tDim), DllStructGetPtr($tDim)) Then Return SetError(2, 0, 0)
    Local $tSize = DllStructCreate($tagSIZE), $tSource = DllStructCreate($tagPOINT), $tBlend = DllStructCreate($tagBLENDFUNCTION)
    Local Const $hScrDC = _WinAPI_GetDC(0), $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC), $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
    $tSize.X = $tDim.bmWidth
    $tSize.Y = $tDim.bmHeight
    $tBlend.Alpha = $iOpacity
    $tBlend.Format = 1
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, DllStructGetPtr($tSize), $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteDC($hMemDC)
    If $bReleaseGDI Then _WinAPI_DeleteObject($hHBitmap)
    Return True
EndFunc

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndFunc   ;==>_WM_LBUTTONDOWN

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc

 

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

Wow, this looks really good! :)
Haven't tried those State-Falgs for GUIs .. gread idea! :)

But there's still one thing .. When you add more than one child GUI it seems like you are only able to drag the first one created. I tried to set the Activation focus on the other one (the hotkey function) but you still can't drag the second one .. :/

 

#include <ButtonConstants.au3>
#include <MsgBoxConstants.au3>
#include <StructureConstants.au3>
#include <WinAPIConstants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
HotKeySet("^w", "_test") ; ctrl + w

$hMain = GUICreate("Parent", 400, 400, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED,$WS_EX_TOPMOST))
;~ GUISetBkColor(0xABCDEF)
;~ _WinAPI_SetLayeredWindowAttributes($hMain, 0xABCDEF, 255)
GUISetState(@SW_SHOWNA, $hMain)

_GDIPlus_Startup()
Global Const $SC_DRAGMOVE = 0xF012
Global $iW, $iH, $hImage, $hBitmap, $hGUI
$hImage = _GDIPlus_BitmapCreateFromFile("C:\Program Files (x86)\AutoIt3\Examples\GUI\Torus.png")
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$iW = _GDIPlus_ImageGetWidth($hImage)
$iH = _GDIPlus_ImageGetHeight($hImage)
$hGUI = GUICreate("", $iW, $iH, 0, 0, BitOR(0,$WS_POPUP), $WS_EX_LAYERED)
_WinAPI_SetParent($hGUI, $hMain)

GUISetState(@SW_SHOW, $hGUI)

$hImage2 = _GDIPlus_BitmapCreateFromFile("C:\Program Files (x86)\AutoIt3\Examples\GUI\Torus.png")
$hBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage2)
$iW = _GDIPlus_ImageGetWidth($hImage2)
$iH = _GDIPlus_ImageGetHeight($hImage2)
$hGUI2 = GUICreate("", $iW, $iH, 50, 50, BitOR(0,$WS_POPUP), $WS_EX_LAYERED)
_WinAPI_SetParent($hGUI2, $hMain)

GUISetState(@SW_SHOW, $hGUI2)

_WinAPI_BitmapDisplayTransparentInGUI($hBitmap, $hGUI)
_WinAPI_BitmapDisplayTransparentInGUI($hBitmap2, $hGUI2)

;~ GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_WinAPI_DeleteObject($hBitmap)
_GDIPlus_BitmapDispose($hImage)
_GDIPlus_Shutdown()
GUIDelete()

Func _test()
    WinActivate($hGUI2)
EndFunc

Func _WinAPI_BitmapDisplayTransparentInGUI(ByRef $hHBitmap, ByRef $hGUI, $iOpacity = 0xFF, $bReleaseGDI = True)
    If Not BitAND(GUIGetStyle($hGUI)[1], $WS_EX_LAYERED) = $WS_EX_LAYERED Then Return SetError(1, 0, 0)
    Local $tDim = DllStructCreate($tagBITMAP)
    If Not _WinAPI_GetObject($hHBitmap, DllStructGetSize($tDim), DllStructGetPtr($tDim)) Then Return SetError(2, 0, 0)
    Local $tSize = DllStructCreate($tagSIZE), $tSource = DllStructCreate($tagPOINT), $tBlend = DllStructCreate($tagBLENDFUNCTION)
    Local Const $hScrDC = _WinAPI_GetDC(0), $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC), $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
    $tSize.X = $tDim.bmWidth
    $tSize.Y = $tDim.bmHeight
    $tBlend.Alpha = $iOpacity
    $tBlend.Format = 1
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, DllStructGetPtr($tSize), $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteDC($hMemDC)
    If $bReleaseGDI Then _WinAPI_DeleteObject($hHBitmap)
    Return True
EndFunc

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndFunc   ;==>_WM_LBUTTONDOWN

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc

 

The other way where to create an invisible parent for each chid GUI .. but combined in one GUI would be awesome .. :D

Edited by Leo1906
Link to comment
Share on other sites

You have to modify the _WM_LBUTTONDOWN function accordingly:

#include <ButtonConstants.au3>
#include <MsgBoxConstants.au3>
#include <StructureConstants.au3>
#include <WinAPIConstants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


$hMain = GUICreate("Parent", 400, 400, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED,$WS_EX_TOPMOST))
;~ GUISetBkColor(0xABCDEF)
;~ _WinAPI_SetLayeredWindowAttributes($hMain, 0xABCDEF, 255)
GUISetState(@SW_SHOWNA, $hMain)

_GDIPlus_Startup()
Global Const $SC_DRAGMOVE = 0xF012
Global $iW, $iH, $hImage, $hBitmap, $hGUI_Child1, $hGUI_Child2
$hImage = _GDIPlus_BitmapCreateFromFile("C:\Program Files (x86)\AutoIt3\Examples\GUI\Torus.png")
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$iW = _GDIPlus_ImageGetWidth($hImage)
$iH = _GDIPlus_ImageGetHeight($hImage)

$hGUI_Child1 = GUICreate("", $iW, $iH, 0, 0, $WS_POPUP, $WS_EX_LAYERED)
_WinAPI_SetParent($hGUI_Child1, $hMain)

_WinAPI_BitmapDisplayTransparentInGUI($hBitmap, $hGUI_Child1)
GUISetState(@SW_SHOWNA, $hGUI_Child1)

$hGUI_Child2 = GUICreate("", $iW, $iH, 150, 150, $WS_POPUP, $WS_EX_LAYERED)
_WinAPI_SetParent($hGUI_Child2, $hMain)
_WinAPI_BitmapDisplayTransparentInGUI($hBitmap2, $hGUI_Child2)
GUISetState(@SW_SHOWNA, $hGUI_Child2)

;~ GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteObject($hBitmap2)
_GDIPlus_BitmapDispose($hImage)
_GDIPlus_Shutdown()
GUIDelete()

Func _WinAPI_BitmapDisplayTransparentInGUI(ByRef $hHBitmap, ByRef $hGUI_Child1, $iOpacity = 0xFF, $bReleaseGDI = True)
    If Not BitAND(GUIGetStyle($hGUI_Child1)[1], $WS_EX_LAYERED) = $WS_EX_LAYERED Then Return SetError(1, 0, 0)
    Local $tDim = DllStructCreate($tagBITMAP)
    If Not _WinAPI_GetObject($hHBitmap, DllStructGetSize($tDim), DllStructGetPtr($tDim)) Then Return SetError(2, 0, 0)
    Local $tSize = DllStructCreate($tagSIZE), $tSource = DllStructCreate($tagPOINT), $tBlend = DllStructCreate($tagBLENDFUNCTION)
    Local Const $hScrDC = _WinAPI_GetDC(0), $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC), $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
    $tSize.X = $tDim.bmWidth
    $tSize.Y = $tDim.bmHeight
    $tBlend.Alpha = $iOpacity
    $tBlend.Format = 1
    _WinAPI_UpdateLayeredWindow($hGUI_Child1, $hScrDC, 0, DllStructGetPtr($tSize), $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteDC($hMemDC)
    If $bReleaseGDI Then _WinAPI_DeleteObject($hHBitmap)
    Return True
EndFunc

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    Switch $hWnd
        Case $hGUI_Child1, $hGUI_Child2
            _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
    EndSwitch
EndFunc   ;==>_WM_LBUTTONDOWN

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc

 

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

This is just perfect! You really helped me a lot here :)
Thanks for that! :)

One last question: do you know about a way to stick those child GUIs relative to the parent GUI? So that when the position of the parent GUI changes, the child GUIs move too?
If this is not possible it's not so important, but it would be nice if there's a way .. :D 

Link to comment
Share on other sites

As you can see here:

#include <ButtonConstants.au3>
#include <MsgBoxConstants.au3>
#include <StructureConstants.au3>
#include <WinAPIConstants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


$hMain = GUICreate("Parent", 400, 400, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED,$WS_EX_TOPMOST))
;~ GUISetBkColor(0xABCDEF)
;~ _WinAPI_SetLayeredWindowAttributes($hMain, 0xABCDEF, 255)
GUISetState(@SW_SHOWNA, $hMain)

_GDIPlus_Startup()
Global Const $SC_DRAGMOVE = 0xF012
Global $iW, $iH, $hImage, $hBitmap, $hGUI_Child1, $hGUI_Child2
$sAutoItPath=StringReplace(StringReplace(@AutoItExe,'_64',''),'autoit3.exe','')
$hImage = _GDIPlus_BitmapCreateFromFile($sAutoItPath&"Examples\GUI\Torus.png")
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$iW = _GDIPlus_ImageGetWidth($hImage)
$iH = _GDIPlus_ImageGetHeight($hImage)

$hGUI_Child1 = GUICreate("", $iW, $iH, 0, 0, $WS_POPUP, $WS_EX_LAYERED)
_WinAPI_SetParent($hGUI_Child1, $hMain)

_WinAPI_BitmapDisplayTransparentInGUI($hBitmap, $hGUI_Child1)
GUISetState(@SW_SHOWNA, $hGUI_Child1)

$hGUI_Child2 = GUICreate("", $iW, $iH, 150, 150, $WS_POPUP, $WS_EX_LAYERED)
_WinAPI_SetParent($hGUI_Child2, $hMain)
_WinAPI_BitmapDisplayTransparentInGUI($hBitmap2, $hGUI_Child2)
GUISetState(@SW_SHOWNA, $hGUI_Child2)

;~ GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")
AdlibRegister('_MoveMain')

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteObject($hBitmap2)
_GDIPlus_BitmapDispose($hImage)
_GDIPlus_Shutdown()
GUIDelete()

Func _WinAPI_BitmapDisplayTransparentInGUI(ByRef $hHBitmap, ByRef $hGUI_Child1, $iOpacity = 0xFF, $bReleaseGDI = True)
    If Not BitAND(GUIGetStyle($hGUI_Child1)[1], $WS_EX_LAYERED) = $WS_EX_LAYERED Then Return SetError(1, 0, 0)
    Local $tDim = DllStructCreate($tagBITMAP)
    If Not _WinAPI_GetObject($hHBitmap, DllStructGetSize($tDim), DllStructGetPtr($tDim)) Then Return SetError(2, 0, 0)
    Local $tSize = DllStructCreate($tagSIZE), $tSource = DllStructCreate($tagPOINT), $tBlend = DllStructCreate($tagBLENDFUNCTION)
    Local Const $hScrDC = _WinAPI_GetDC(0), $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC), $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
    $tSize.X = $tDim.bmWidth
    $tSize.Y = $tDim.bmHeight
    $tBlend.Alpha = $iOpacity
    $tBlend.Format = 1
    _WinAPI_UpdateLayeredWindow($hGUI_Child1, $hScrDC, 0, DllStructGetPtr($tSize), $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteDC($hMemDC)
    If $bReleaseGDI Then _WinAPI_DeleteObject($hHBitmap)
    Return True
EndFunc

Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    Switch $hWnd
        Case $hGUI_Child1, $hGUI_Child2
            _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
    EndSwitch
EndFunc   ;==>_WM_LBUTTONDOWN

Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc

Func _MoveMain()
    $aMain=WinGetPos($hMain)
    $aMain[0]+=5
    If $aMain[0]>@DesktopWidth Then $aMain[0]=0
    WinMove($hMain,'',$aMain[0],$aMain[1])
EndFunc

the child's already moving with the main GUI.

Link to comment
Share on other sites

Ah you're right ..
I tried something different. I was increasing the height of the GUI expecting the child GUIs to change their position too .. :D
Thanks for pointing that out. Now all my questions have been answered just perfectly!

Thanks a lot for your support in this forum here guys! :)
Really appreciate it! ;) 

 

Edit: ok .. well there is unfortunately another thing .. It seems like I can't fix the position of the child GUIs anymore using this function:

GUIRegisterMsg($WM_WINDOWPOSCHANGING, 'WM_WINDOWPOSCHANGING')

Func WM_WINDOWPOSCHANGING($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam, $lParam
        Local $aWinGetPos = WinGetPos($hWnd)
        If @error Then Return $GUI_RUNDEFMSG
        Local $tWindowPos = DllStructCreate($tagWINDOWPOS, $lParam)
        If DLLStructGetData($tWindowPos, "X") < @DesktopWidth-235 Then
            DllStructSetData($tWindowPos, 'X', $aWinGetPos[0])
        EndIf
        DllStructSetData($tWindowPos, 'Y', $aWinGetPos[1])
        Return $GUI_RUNDEFMSG
EndFunc

Well .. im about to think that the whole thing with the invisible borders isn't really working out :/ :D
You guys know something? Otherwise I think I need to think about something else or just keep it the way it is .. :/

 

Edit2: got it .. the coordinates are now relative to the main GUI and not to the Desktop dimension .. :) 

Edited by Leo1906
Link to comment
Share on other sites

4 hours ago, AutoBert said:

Then you have tried to move outside @DesktopWidth or @DedsktopHeight. When Parent is inside both torus  are visible, maybe fragmented when you try to move him outside parent widow.

Nope. I was just slightly moving one of the toruses around (usually the left one). It would flicker and disappear. The OP wrote, "Whilst they are being dragged they change their transparency and at a certain point get deleted when you release them." so perhaps the disappearance is by design.

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