AutoHotkey Community

It is currently May 26th, 2012, 10:48 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: March 26th, 2006, 7:04 pm 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
Here is a function to make a gui window belong to another program's window (it will then get minimized/moved along with the other parent window without needing to use a timer). Some program's don't work well with this method, like notepad and calculator, you also can't position the gui on the titlebar.

(The original code came from Laszlo's taskbar clock).

You can either use the title of a program's window to identify the parent or if you use the function I commented out below instead, then you can use the class's name.

Code:
; e.g. run an internet explorer window and go to the page: "about:blank" so that is the start of the title text
;   then run this script and it adds a gui window onto the internet explorer window.
; Some programs, such as notepad and calculator, don't seem to work properly with this technique.

Gui, 7: Margin, 0, 0
Gui, 7: +ToolWindow ; -Caption ; no title, no taskbar icon
Gui, 7: Add, Text,, This gui is stuck to the parent... `nbut I haven't programmed it to do anything `;-)

Set_Parent_by_title("about:blank", 7) ; can be done before or after showing the gui
Gui, 7: Show, x200 y200
Return



/*
or to use the window id of the parent instead of the title:

Set_Parent_by_id(Window_ID, Gui_Number) ; title text is the start of the title of the window, gui number is e.g. 99
{
  Gui, %Gui_Number%: +LastFound
  Return DllCall("SetParent", "uint", WinExist(), "uint", Window_ID) ; success = handle to previous parent, failure =null
}
*/



Set_Parent_by_title(Window_Title_Text, Gui_Number) ; title text is the start of the title of the window, gui number is e.g. 99
{
  WinGetTitle, Window_Title_Text_Complete, %Window_Title_Text%
  Parent_Handle := DllCall( "FindWindowEx", "uint",0, "uint",0, "uint",0, "str", Window_Title_Text_Complete)
  Gui, %Gui_Number%: +LastFound
  Return DllCall( "SetParent", "uint", WinExist(), "uint", Parent_Handle ) ; success = handle to previous parent, failure =null
}



/*
or to use the class instead of the title:

Set_Parent_by_class(Window_Class, Gui_Number) ; class e.g. Shell_TrayWnd, gui number is e.g. 99
{
  Parent_Handle := DllCall( "FindWindowEx", "uint",0, "uint",0, "str", Window_Class, "uint",0)
  Gui, %Gui_Number%: +LastFound
  Return DllCall( "SetParent", "uint", WinExist(), "uint", Parent_Handle ) ; success = handle to previous parent, failure =null
}
*/


Last edited by evl on March 28th, 2006, 12:11 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 26th, 2006, 7:10 pm 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
Here's an example which sticks a gui to the desktop:

Code:
Gui, 7: Margin, 0, 0
Gui, 7: +ToolWindow ; -Caption ; no title, no taskbar icon
Gui, 7: Add, Text,, This gui is stuck to the parent... `nbut I haven't programmed it to do anything `;-)
Set_Parent_by_class("Progman", 7)
Gui, 7: Show, x200 y200
Return

Set_Parent_by_class(Window_Class, Gui_Number) ; class e.g. Shell_TrayWnd, gui number is e.g. 99
{
  Parent_Handle := DllCall( "FindWindowEx", "uint",0, "uint",0, "str", Window_Class, "uint",0)
  Gui, %Gui_Number%: +LastFound
  Return DllCall( "SetParent", "uint", WinExist(), "uint", Parent_Handle )
}





Here's another example that creates a GUI within a GUI (i.e. a window within a window so you can have multiple windows but all inside one interface):

Code:
Gui, add, text, x-10 y-10, ; need something in the parent window to enable minimizing
Gui, +lastfound
Gui_1_ID := WinExist()

Gui, Show, h140 w200, Parent
Set_Parent_by_id(Gui_1_ID, 2) ; Window_ID, Gui_Number
Gui, 2: Show, x5 y5 h80 w150, Child
Return

Set_Parent_by_id(Window_ID, Gui_Number) ; title text is the start of the title of the window, gui number is e.g. 99
{
  Gui, %Gui_Number%: +LastFound
  Return DllCall("SetParent", "uint", WinExist(), "uint", Window_ID) ; success = handle to previous parent, failure =null
}


Last edited by evl on April 12th, 2006, 12:25 am, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 28th, 2006, 12:15 am 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
Updated my first post a bit with some slight improvements and another function for using the parent windows ahk_id directly, thanks to Goyyah, who wrote a script for sticking a clock to the desktop, here:

http://www.autohotkey.com/forum/viewtop ... 4403#54403


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 28th, 2006, 7:37 am 
Offline

Joined: July 12th, 2005, 1:21 pm
Posts: 633
This can create really nice effects!
Also if it is simple you brought me to the idea of "window-collections" :D

It could be also a way to hide the window from taskbar (as sometimes mentioned)..

Thalon

_________________
AHK-Icon-Changer
AHK-IRC
deutsches Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 16th, 2006, 9:42 pm 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
Attaching (docking) a gui window to a specific toolbar (e.g. Quick Launch):

This is an example I customised from an idea by jonib:
http://www.autohotkey.com/forum/viewtopic.php?t=9844
http://www.autohotkey.com/forum/viewtopic.php?t=8044

Code:
; Note that a toolbar title can be hidden by right-clicking & un-locking the Taskbar and then properties of the toolbar.


Gui, 7: Margin, 0, 0
Gui, 7: -Caption +ToolWindow  ; no title, no taskbar icon
Gui, 7: Add, Text,, BAR TEXT HERE!

Set_Parent_to_Toolbar("Quick Launch", 7) ; (Toolbar title (name) to attach to, gui number)

Gui, 7: Show, x0 y4
Return



Set_Parent_to_Toolbar(ToolbarName, Gui_Number) ; title text is the start of the title of the window, gui number is e.g. 99
{
  hw_tray:=FindToolbar(ToolbarName)
  If ! hw_tray
    {
    Msgbox, Toolbar "%ToolbarName%" not found! Exiting.
    Exitapp
    }
  Gui, %Gui_Number%: +LastFound
  Return DllCall("SetParent", "uint", WinExist(), "uint", hw_tray) ; success = handle to previous parent, failure =null
}

FindToolbar(ToolbarName)
{   
  WinExist("ahk_class Shell_TrayWnd") ; Find Systemtray
  WinGet, Controls ,ControlList ;Get list of all controls
  Loop, Parse, Controls, `n
  {
    ControlGetText, CurControl , %A_LoopField%
    if CurControl=%ToolbarName% ;Find the toolbar we want by comparing controls Text
       ControlGet, hwnd, Hwnd,,%A_LoopField% ;Get the handle for the toolbar
  }
  Return hwnd
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 20th, 2008, 3:26 pm 
Offline

Joined: September 19th, 2005, 1:31 am
Posts: 115
As stated, why doesn't this work with some programs (like notes or Lotus Notes)?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 9th, 2010, 2:08 am 
sorry for posting in an old topic but i think this is worth knowing.

For compatibility reasons, SetParent does not modify the WS_CHILD or WS_POPUP window styles of the window whose parent is being changed. Therefore, if hWndNewParent is NULL, you should also clear the WS_CHILD bit and set the WS_POPUP style after calling SetParent. Conversely, if hWndNewParent is not NULL and the window was previously a child of the desktop, you should clear the WS_POPUP style and set the WS_CHILD style before calling SetParent.

http://msdn.microsoft.com/en-us/library ... 85%29.aspx


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 11th, 2010, 8:42 pm 
Offline

Joined: October 5th, 2010, 6:27 am
Posts: 69
Nice job with this. Is there a way to set it so I can place the child window so it overlaps the title blue section on top of the screen? I tried alwaysontop but that didn't seem to work.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 12th, 2010, 12:15 am 
Offline

Joined: October 11th, 2006, 5:27 am
Posts: 27
Nice try but this function can be found in majkinetor's standart library "Win - Set of window functions"

http://www.autohotkey.com/forum/viewtopic.php?t=47856

Example
Code:
Gui, 7: Margin, 0, 0
Gui, 7: +ToolWindow
Gui, 7: Add, Text,, This gui is stuck to the parent... `nbut I haven't programmed it to do anything `;-)

Gui, 7: +LastFound
Win_SetParent(WinExist(), WinExist("about:blank"))


Gui, 7: Show, x200 y200
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 12th, 2010, 2:26 am 
Offline

Joined: March 10th, 2008, 12:55 am
Posts: 1907
Location: Minnesota, USA
ZeLen1y your point is? It's always good t have options.
and fyi, this one is about 3 years older.

_________________
rawr. be very afraid
*poke*
Note: My name is all lowercase for a reason.
"I think Bigfoot is blurry, that's the problem. It's not the photographer's fault, Bigfoot is blurry. So there's a large, out-of-focus monster roaming the countryside."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 17th, 2010, 8:39 am 
Offline

Joined: October 5th, 2010, 6:27 am
Posts: 69
Nice work with this. Can you advise how I can make the child window overlaps the title blue bar on top of the screen? It seems when I use a negative number to move the GUI up it goes under the Title bar instead of over the top. Your help would be appreciated.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 29th, 2010, 6:18 pm 
Offline

Joined: February 21st, 2007, 5:26 pm
Posts: 15
Location: Hungary
Hi!

So is it maybe possible to grouping some processes into one tabbed group?
I mean, to make a tabbed interface to Putty.
A very simple way would be also enough, just to group the same processes into one window, which has 1 taskbar button only, and then you can select from the Putty windows with a simple clicking on a tab at the upper part.

I mean a function like the below program:
http://www.windowtabs.com/

Maybe the mentioned library "Win 1.25 - Set of window functions" could do that?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], sks, toddintr and 10 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group