Layered window gui SetParent NULL breaks. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
MiM
Posts: 61
Joined: 20 Apr 2021, 04:31

Layered window gui SetParent NULL breaks.

Post by MiM » 23 May 2022, 15:02

Anyone familiar with layered windows, when setting

Code: Select all

DllCall("User32.dll\SetParent", "Ptr", GuiHwnd, "Ptr", 0)
(unparenting) the gui, it disappears, i'm guessing UpdateLayeredWindow from the gdip library is relevant here?


I guess this demonstrates the issue:

Code: Select all

#SingleInstance, Force

Gui, Show, w300 h300
Gui, +hwndGuiHwnd +E0x80000
Gui, Color, Red
Return

F1::
DllCall("User32.dll\SetParent", "Ptr", GuiHwnd, "Ptr", WinExist("A"))
Return

F2::
DllCall("User32.dll\SetParent", "Ptr", GuiHwnd, "Ptr", 0)
Return
So, run the script, click the desktop, press F1 and press F2, the gui client area freaks out.

iseahound
Posts: 1444
Joined: 13 Aug 2016, 21:04
Contact:

Re: Layered window gui SetParent NULL breaks.

Post by iseahound » 23 May 2022, 16:17

Code: Select all

#SingleInstance, Force
#include ImagePut.ahk

; Success
guihwnd := ImagePutWindow({wallpaper: True, crop:[500,500,300,300]})

; Fails
;guihwnd := ImageShow({wallpaper: True, crop:[500,500,300,300]})
Return

F1:: DllCall("User32.dll\SetParent", "Ptr", GuiHwnd, "Ptr", WinExist("A"))

F2:: DllCall("User32.dll\SetParent", "Ptr", GuiHwnd, "Ptr", 0)

; does nothing
F3:: DllCall("InvalidateRect", "ptr", GuiHwnd, "ptr", 0, "int", 1)
If you use my function ImagePutWindow it works. I imagine that setting a layered window as a child requires the WS_CHILD flag. Actually I tested further, and I don't know why my implementation works, and using AHK doesn't.

https://github.com/iseahound/ImagePut/blob/master/ImagePut%20(for%20v1).ahk
not working

User avatar
MiM
Posts: 61
Joined: 20 Apr 2021, 04:31

Re: Layered window gui SetParent NULL breaks.  Topic is solved

Post by MiM » 23 May 2022, 21:08

Figured it out, gotta -E0x80000 before setparenting to null and then can just do +E0x80000 right after.
In the SetParent function docs the remarks section explains it.

Post Reply

Return to “Ask for Help (v1)”