Dock - Attach a window to another

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Soft
Posts: 174
Joined: 07 Jan 2015, 13:18
Location: Seoul
Contact:

Dock - Attach a window to another

23 Apr 2017, 02:00

Dock uses SetWinEventHook functions to attach a window to another.

Since passing a func obj, or boundfunc(including methods) as a 'callback' is possible, you can create your own events handler like in 'Dock Example.ahk' on below
AutoHotkey & AutoHotkey_H v1.1.22.07
User avatar
noname
Posts: 515
Joined: 19 Nov 2013, 09:15

Re: Dock - Attach a window to another

23 Apr 2017, 04:15

Impressive code ! Thanks for sharing it .
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Dock - Attach a window to another

23 Apr 2017, 04:31

Nice one, thanks for sharing. :wave:
Regarding,

Code: Select all

__Delete()
;[...]
	this.Delete["hwnd"]
perhaps you mean this.Delete("hwnd") or this.hwnd:="", in any case, it is not needed.

Edit: I don't like those code boxes ;)
guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: Dock - Attach a window to another

23 Apr 2017, 07:09

Good job. For reference, user @majkinetor from the old forums also created functions Dock() and DockA() doing something similar:

https://github.com/majkinetor/mm-autoho ... aster/Dock
https://github.com/majkinetor/mm-autoho ... ster/DockA
https://autohotkey.com/board/topic/1785 ... ing-20-b3/

You may get some ideas there. I've used DockA() in the past. I forget what the difference was

User avatar
Soft
Posts: 174
Joined: 07 Jan 2015, 13:18
Location: Seoul
Contact:

Re: Dock - Attach a window to another

24 Apr 2017, 04:29

Helgef wrote:perhaps you mean this.Delete("hwnd") or this.hwnd:="", in any case, it is not needed.
Edit: I don't like those code boxes ;)
oh right.., I know it's not needed, but I've been habituated to do this since I start to use c :crazy:
AutoHotkey & AutoHotkey_H v1.1.22.07
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Dock - Attach a window to another

24 Apr 2017, 04:38

Soft wrote:oh right.., I know it's not needed, but I've been habituated to do this since I start to use c :crazy:
I do it too sometimes :angel:
User avatar
Soft
Posts: 174
Joined: 07 Jan 2015, 13:18
Location: Seoul
Contact:

Re: Dock - Attach a window to another

24 Apr 2017, 04:45

guest3456 wrote:...
You may get some ideas there. I've used DockA() in the past. I forget what the difference was
I also used his codes before, his code and mine act seemingly same, but differs in method.
Since DockA() doesn't use hook winevents, but register OnMessage via Gui, it can only attach AutoHotkey Gui (as far as I remember), while Dock hooks Winevnets so that it is possible to dock any application to another.
AutoHotkey & AutoHotkey_H v1.1.22.07
lblb
Posts: 190
Joined: 30 Sep 2013, 11:31

Re: Dock - Attach a window to another

24 Apr 2017, 15:06

Hi Soft,

This is a nice update to the old code.

Using the code in the example, if I want to dock multiple windows to the parent window, do I need to define for each docked window one new InitDockX, one new FuncObjX, and call OnMessage for each new FuncObjX?

Also, like was done by Majkinetor, would it be possible to add parameters for the position of the docked window? Right now, the window is docked to the top right corner of the parent window, but could you add the possibility to dock it to all predefined position like in Majkinetor's code (as one possible example, dock on the left side, with both the docked and parent windows being center aligned)? Also add the possibility to define relative X and Y offsets in pixels (for example, dock to the right side + align the bottom of the windows + 30 pixels horizontally)?

Thanks for your work on this.
User avatar
Soft
Posts: 174
Joined: 07 Jan 2015, 13:18
Location: Seoul
Contact:

Re: Dock - Attach a window to another

25 Apr 2017, 02:01

lblb wrote:Using the code in the example, if I want to dock multiple windows to the parent window, do I need to define for each docked window one new InitDockX, one new FuncObjX, and call OnMessage for each new FuncObjX?
Depends on what you want. I registered OnMessage only to re-pos notepad when user moves the gui, since WinEvents come from the Notepad, not the gui. You can just dock each other for same behavior. I may post an example for this on weekend.
lblb wrote:...the window is docked to the top right corner of the parent window, but could you add the possibility to dock it to all ...
It's simply because I wrote that code only for the example...
Having pre-defined options sounds like a good idea though, I'll update soon.
AutoHotkey & AutoHotkey_H v1.1.22.07
lblb
Posts: 190
Joined: 30 Sep 2013, 11:31

Re: Dock - Attach a window to another

26 Apr 2017, 01:17

Hi Soft,

Thanks for the quick reply, much appreciated. And thanks for the clarification about OnMessage. I look forward to future updates!
20170201225639
Posts: 144
Joined: 01 Feb 2017, 22:57

Re: Dock - Attach a window to another

26 Apr 2017, 08:23

this is great!
i tinkered with it a little bit and it seems possible to create two separate docks without needing new FuncObj and InitDock variables. Just reusing the old variables seems to work.
Spoiler

https://my.mixtape.moe/sjmdfn.webm

but i'll wait for the official implementation!
User avatar
Soft
Posts: 174
Joined: 07 Jan 2015, 13:18
Location: Seoul
Contact:

Re: Dock - Attach a window to another

05 May 2017, 19:39

Update 0.2

Changed
  • 1. Subclassed EventsHandler to Dock.EventsHandler
  • 2. Dock.EventsHandler is now a default callback, thereby you can omit Callback
  • 3. several things... see codes and example for more information
Added
  • 1. AttachTo method, now you can set a position for docked window. See example
  • 2. CloseCallback, which will be called when main window is destroyed
  • 3. several things... see codes and example for more information
I haven't figured out a decent way to dock multiple windows
So for the moment, you should make a new instance of dock to control multiple windows
AutoHotkey & AutoHotkey_H v1.1.22.07
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Dock - Attach a window to another

06 May 2017, 16:06

These updates are good! :thumbup:
For consistency and functionallity, I suggest,

Code: Select all

this.Callback := IsObject(Callback) ? Callback : ObjBindMethod(Dock.EventsHandler, "Calls") ; IsObject instead of StrLen(...)
And, you need to call unhook() in __delete()

Code: Select all

__Delete()
{
	if this.hook
		this.Unhook()
	this.CloseCallback := ""
}
User avatar
Soft
Posts: 174
Joined: 07 Jan 2015, 13:18
Location: Seoul
Contact:

Re: Dock - Attach a window to another

06 May 2017, 21:20

Helgef wrote: And, you need to call unhook() in __delete()

Code: Select all

__Delete()
{
	if this.hook
		this.Unhook()
	this.CloseCallback := ""
}
Well I don't think I need to because __Delete() can never be called unless circular references are broken by Unhook()
AutoHotkey & AutoHotkey_H v1.1.22.07
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Dock - Attach a window to another

07 May 2017, 05:41

Hi soft. I hope you don't think I'm a pain now :wave:
Soft wrote: Well I don't think I need to because __Delete() can never be called unless circular references are broken by Unhook()
First, see pointers to objects and ObjRelease
There are no self references created in your __new.
You may,

Code: Select all

; Change,
this.hookProcAdr := RegisterCallback("_DockHookProcAdr",,, &this)
; to
this.hookProcAdr := RegisterCallback("_DockHookProcAdr",,, Object(this))
Now you have increased the reference count, then in Unhook() you do ObjRelease(&this), now, given that you have done a:= new Dock(...) and didn't keep any other references, you can safely do a:="" after a.Unhook() and __delete() is called, although I don't see any value of the this.CloseCallback:="". The benefit of incrementing the reference counter in __new() when you store the adress in RegisterCallback is that when you do

Code: Select all

_DockHookProcAdr(hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, dwmsEventTime)
{
	this := Object(A_EventInfo)
then the number in A_EventInfo is more likely to be a valid adress. Calling Object() with an invalid adress is likely to cause trouble.
Note, in _DockHookProcAdr, ObjRelease(this) does nothing (luckily). this is a local variable in _DockHookProcAdr, and
local variables wrote: All local variables which are not static are automatically freed (made empty) when the function returns
If you had called ObjRelease correctly, i.e., passed it an adress, you would decrement the reference count for your object twice in that function, but only incremented it once.

Cheers.
User avatar
Soft
Posts: 174
Joined: 07 Jan 2015, 13:18
Location: Seoul
Contact:

Re: Dock - Attach a window to another

07 May 2017, 06:08

Helgef wrote:...
oh right, class destructor can be called properly on this v0.2
I was testing with another build of Dock which was creating circular references . That's why I didn't implement Unhook() in __Delete() on public code :crazy:

Why do you think you are a pain? I'm truly thankful and glad because you are giving me helpful advices & tips
I had nothing bad, don't get me wrong :D
It seems that I got misunderstood quite a lot. perhaps because English is not my mother tongue.

Anyway, many thanks for your kind explanations! I'll revise my code soon
AutoHotkey & AutoHotkey_H v1.1.22.07
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Dock - Attach a window to another

07 May 2017, 06:35

I do not think I'm a pain, I just hoped you didn't :)
Lack of body language is the price we have to pay for this way of communication, regardless of native language. That's why we have these -> :D :) ;) ..., which certainly isn't part of my native language. (Non-english too)

Cheers.
User avatar
Relayer
Posts: 160
Joined: 30 Sep 2013, 13:09
Location: Delaware, USA

Re: Dock - Attach a window to another

08 May 2017, 08:23

Soft,

I would just like to check on what is expected behavior. I notice that if I move the Notepad window it undocks. It then JUMPS to re-dock when I go to move the parent window. Can you confirm that is intended.

Relayer
User avatar
Soft
Posts: 174
Joined: 07 Jan 2015, 13:18
Location: Seoul
Contact:

Re: Dock - Attach a window to another

09 May 2017, 10:10

Relayer wrote:Soft,

I would just like to check on what is expected behavior. I notice that if I move the Notepad window it undocks. It then JUMPS to re-dock when I go to move the parent window. Can you confirm that is intended.

Relayer
It was just not implemented. Now dock has that feature though. Test with a new code and let me know how it works :)
AutoHotkey & AutoHotkey_H v1.1.22.07
User avatar
Soft
Posts: 174
Joined: 07 Jan 2015, 13:18
Location: Seoul
Contact:

Re: Dock - Attach a window to another

09 May 2017, 10:18

update 0.2.2
  • -It is now possible to dock more than one window (still WIP, its code and style are provisional)
  • -changed some class properties's name for future consistency
  • -Now Host (formerly main window) and Client window(formerly attached window) dock each other
  • -several changes... see code and example to check out
AutoHotkey & AutoHotkey_H v1.1.22.07

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 127 guests