Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Change Ownership of Windows


  • Please log in to reply
6 replies to this topic
  • Guests
  • Last active:
  • Joined: --
Hello,

I'm wondering if it is possible to remove a window from the owning windo and set it to be owned/parented by GUI created by the script.

For example, the tray tip window is owned by the task bar. It can be confirmed with this code.
DetectHiddenWindows, On
TrayTip, TrayTip Sample, This will be displayed for 5 seconds., 5, 1
hTrayTip := WinExist("ahk_class tooltips_class32")
hOwner := GetOwnerWindow(hTrayTip)

If WinExist("ahk_id " hOwner)
{
	WinGetTitle, OwnerTitle, ahk_id %hOwner%
	WinGetClass, OwnerClass, ahk_id %hOwner%
	msgbox % OwnerClass

}
	
GetOwnerWindow(hwnd) {
	return DllCall("User32\GetWindow"
		, ptr, hwnd
		, uint, GW_OWNER := 4 
		, ptr)
}
So is it possible to detach the tray window and attach it to my custom Gui? Thanks for your info.

  • Guests
  • Last active:
  • Joined: --
http://www.autohotke.../topic8906.html

  • Guests
  • Last active:
  • Joined: --
No, SetParent won't work.

#
  • Guests
  • Last active:
  • Joined: --
SetOwner(hwnd, newOwner) {

    static GWL_HWNDPARENT := -8

    if A_PtrSize = 8

        DllCall("SetWindowLongPtr", "ptr", hwnd, "int", GWL_HWNDPARENT, "ptr", newOwner)

    else

        DllCall("SetWindowLong", "int", hwnd, "int", GWL_HWNDPARENT, "int", newOwner)

}


  • Guests
  • Last active:
  • Joined: --
Thanks. The function works for changing the window owner.

By the way, although the main part of the initial question has been answered, do you happen to know why this code does not embed the tray tip window into the AutoHotkey Gui window?

Caution: This code may change the windows behavior regarding TrayTip and may require system restart to revert the change.
DetectHiddenWindows, On
TrayTip, TrayTip Sample, This will be displayed for 5 seconds., 5, 1
hTrayTip := WinExist("ahk_class tooltips_class32")

Gui, Sample: +HwndhSample

SetOwner(hTrayTip, hSample)
SetParent(hTrayTip, hSample)

WinMove, ahk_id %hTrayTip%,, 0, 0
Gui, Sample: Show, w%200% h%200%
	
Return

Esc::ExitApp

SetOwner(hwnd, newOwner) {
    static GWL_HWNDPARENT := -8
    if A_PtrSize = 8
        DllCall("SetWindowLongPtr", "ptr", hwnd, "int", GWL_HWNDPARENT, "ptr", newOwner)
    else
        DllCall("SetWindowLong", "int", hwnd, "int", GWL_HWNDPARENT, "int", newOwner)
}

SetParent(hWndChild, hWndParent) {
	return DllCall("SetParent"
		, ptr, hWndChild
		, ptr, hWndParent
		, ptr)
}


#
  • Guests
  • Last active:
  • Joined: --

By the way, although the main part of the initial question has been answered, do you happen to know why this code does not embed the tray tip window into the AutoHotkey Gui window?

There is no correct answer to that question, because that code does in fact embed the tray tip window into the Gui window successfully. However, the Gui is never shown because the options are invalid, and even if the Gui is shown, the tray tip window is invisible to the naked eye (but not to spy tools).

The real question is why it becomes invisible once it is embedded into another window, and the answer lies in the window's ExStyle. Specifically, WS_EX_LAYERED.

There are also other unrelated problems with your script. It is not possible for a window to have both an owner and a parent. Having an owner implies that it is a popup window, while having a parent implies that it is a child window. In other situations, be aware that using SetParent without correctly applying or removing the WS_CHILD and WS_POPUP styles can cause problems.

  • Guests
  • Last active:
  • Joined: --
Thank you so much for the answer that reveals the problem.

The tray window seems to be shared with other programs so I concluded it's not a good idea to edit it. I'll look for alternatives for what I'd like to achieve.