Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

How to bring a child of the desktop in front?



  • Please log in to reply
6 replies to this topic
Zvonko
  • Members
  • 173 posts
  • Last active: Jan 24 2016 05:21 PM
  • Joined: 17 Oct 2014

I use a gui which is a child of the desktop, as to be always in the background of all other windows. (See my simplified script below.)

 

However, sometimes I would like to bring this child window temporarily in front of all other windows.

 

I can see that this is possible: Via Alt-Tab the child window can be accessed manually and displayed on top.

 

How this could be achieved in an ahk script?

WinGet, IdDesktop, ID, ahk_class Progman

Gui Child: -dpiscale -Caption 0x400000 	
Gui Child: Add, Text,, I am a Child

Gui Child: +LastFound
IdChild := WinExist()

DllCall("SetParent", ptr, IdChild, ptr, IdDesktop)  

Gui Child: Show


Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
WinGet, IdDesktop, ID, ahk_class Progman

Gui Child: -dpiscale -Caption 0x400000 +parent%IdDesktop%
Gui Child: Add, Text,, I am a Child

Gui Child: Show

ToolTip, Gui is shown and is child of desktop
sleep 1000

ToolTip, Gui will be set as a toplevel window again
sleep 1000

Gui Child: -parent +AlwaysOnTop
Gui Child: Show

sleep 1000
ToolTip, like that...
return

Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

Zvonko
  • Members
  • 173 posts
  • Last active: Jan 24 2016 05:21 PM
  • Joined: 17 Oct 2014

Thank you, Blackholyman.

 

Is this script working on your PC???

On my (Win 8.1) the first window (child) is not displayed!



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
i modifyed it a little before posting this is tested and works for me

WinGet, IdDesktop, ID, ahk_class Progman

Gui Child: -dpiscale -Caption 0x400000
Gui Child: +parent%IdDesktop%
Gui Child: Add, Text,, I am a Child

Gui Child: Show

ToolTip, Gui is shown and is child of desktop
sleep 1000

ToolTip, Gui will be set as a toplevel window again
sleep 1000

Gui Child: -parent +AlwaysOnTop
Gui Child: Show

sleep 1000
ToolTip, like that...
return

Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

Zvonko
  • Members
  • 173 posts
  • Last active: Jan 24 2016 05:21 PM
  • Joined: 17 Oct 2014
✓  Best Answer

Just awesome! Thank you, Blackholyman, you are a schatz!!!

 

After this your knowledge input I also discovered that this works with both methods for child windows:

WinGet, IdDesktop, ID, ahk_class Progman

Gui Child: -dpiscale -Caption 0x400000
Gui Child: +parent%IdDesktop%
Gui Child: Add, Text,, I am a Child

Gui Child: Show

return 

F8:: ;Bring in front temporarily! 
Gui Child: -parent 
Gui Child: Show
SetTimer, ChildBack, 5000
return

F9:: ;Bring in Background again! 
Gui Child: +parent%IdDesktop%	
Gui Child: Show
return

ChildBack:
SetTimer, ChildBack, off
Gui Child: +parent%IdDesktop%	
Gui Child: Show
return

Or:

WinGet, IdDesktop, ID, ahk_class Progman

Gui Child: -dpiscale -Caption 0x400000
Gui Child: Add, Text,, I am a Child

Gui Child: +LastFound
IdChild := WinExist()

DllCall("SetParent", ptr, IdChild, ptr, IdDesktop)  

Gui Child: Show

return 

F8:: ;Bring in front temporarily! 
DllCall("SetParent", ptr, IdChild, ptr, 0)  
SetTimer, ChildBack, 5000
return

F9:: ;Bring in Background again! 
DllCall("SetParent", ptr, IdChild, ptr, IdDesktop)  
return

ChildBack:
SetTimer, ChildBack, off
DllCall("SetParent", ptr, IdChild, ptr, IdDesktop)  
return

Thank you!!!

 

By the way, the DllCall method is much faster than the +parent method when showing a larger number of child windows.



Xtra
  • Members
  • 954 posts
  • Last active: Jul 23 2016 09:04 PM
  • Joined: 29 Sep 2013

You can shorten it:

WinGet, IdDesktop, ID, ahk_class Progman

Gui Child: -dpiscale -Caption 0x400000
Gui Child: Add, Text,, I am a Child

Gui Child: +LastFound
IdChild := WinExist()

DllCall("SetParent", ptr, IdChild, ptr, IdDesktop)  

Gui Child: Show

return 

F8:: ;Bring in front temporarily! 
DllCall("SetParent", ptr, IdChild, ptr, 0)  
SetTimer, F9, 5000
return

F9:: ;Bring in Background again!
SetTimer, F9, Off
DllCall("SetParent", ptr, IdChild, ptr, IdDesktop)  
return


Zvonko
  • Members
  • 173 posts
  • Last active: Jan 24 2016 05:21 PM
  • Joined: 17 Oct 2014

 

@Xtra

You can shorten it ...

 

Nice, thank you!