Page 1 of 2

Dock - Attach a window to another

Posted: 23 Apr 2017, 02:00
by Soft
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

Re: Dock - Attach a window to another

Posted: 23 Apr 2017, 04:15
by noname
Impressive code ! Thanks for sharing it .

Re: Dock - Attach a window to another

Posted: 23 Apr 2017, 04:31
by Helgef
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 ;)

Re: Dock - Attach a window to another

Posted: 23 Apr 2017, 07:09
by guest3456
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

Re: Dock - Attach a window to another

Posted: 24 Apr 2017, 04:29
by Soft
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:

Re: Dock - Attach a window to another

Posted: 24 Apr 2017, 04:38
by Helgef
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:

Re: Dock - Attach a window to another

Posted: 24 Apr 2017, 04:45
by Soft
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.

Re: Dock - Attach a window to another

Posted: 24 Apr 2017, 15:06
by lblb
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.

Re: Dock - Attach a window to another

Posted: 25 Apr 2017, 02:01
by Soft
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.

Re: Dock - Attach a window to another

Posted: 26 Apr 2017, 01:17
by lblb
Hi Soft,

Thanks for the quick reply, much appreciated. And thanks for the clarification about OnMessage. I look forward to future updates!

Re: Dock - Attach a window to another

Posted: 26 Apr 2017, 08:23
by 20170201225639
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!

Re: Dock - Attach a window to another

Posted: 05 May 2017, 19:39
by Soft
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

Re: Dock - Attach a window to another

Posted: 06 May 2017, 16:06
by Helgef
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 := ""
}

Re: Dock - Attach a window to another

Posted: 06 May 2017, 21:20
by Soft
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()

Re: Dock - Attach a window to another

Posted: 07 May 2017, 05:41
by Helgef
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.

Re: Dock - Attach a window to another

Posted: 07 May 2017, 06:08
by Soft
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

Re: Dock - Attach a window to another

Posted: 07 May 2017, 06:35
by Helgef
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.

Re: Dock - Attach a window to another

Posted: 08 May 2017, 08:23
by Relayer
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

Re: Dock - Attach a window to another

Posted: 09 May 2017, 10:10
by Soft
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 :)

Re: Dock - Attach a window to another

Posted: 09 May 2017, 10:18
by Soft
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