Jump to content

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

[module] Dock 1.0        (testing 2.0 b3)


  • Please log in to reply
367 replies to this topic
majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
D o c k
Dock desired top level windows (dock clients) to any top level window (dock host)

Download                 Documentation

 
Posted Image



Example
Run notepad,,,nPID
   WinWait ahk_pid %nPID%
   Dock_HostID := WinExist("ahk_pid " . nPID)

   Gui +LastFound -Caption +ToolWindow +Border
   Gui Add, Text,,Docked Window
   Gui Show

   Dock(WinExist(), "0,0,0,    0,-1,-5,    0,120,   0,30")      ; above, left, fixed width
return

[color=red]#include Dock.ahk[/color]

See also Title Button


History
v2.0 b3
- Fixed bug with "working cursor" and T clients.
- Removed "+" option. You should start dock with hidden windows, and Dock will show them after it positioned them correctly if they are hidden. So, Dock itself hides and shows the windows, you just need to Toggle it on once you set up the new host as it will still turn off when Host dies. To let the client be hidden, you must undock it. This is better anyway, as previously hidden clients were still aranged by the Dock, although they were invisible, so update was slower.

v2.0 b2
- Bug fix when host is alive in the moment of registration. Clients are now (hopefully) positioned correctly.

v2.0 b1
- Topmost clients reimplement. Now they work much faster. New example: _Bmcclure.ahk. It shows how to dock to the control. "Docking relative to the control" will be added in next version.

v2.0 a5     Screenshot1 Screenshot 2

- Dock definition alternative notation for shorter expressions
- Optimisation & bug fixes
- Dock definition changed to more clear notation. This intorduced some new docking shemes (X & Y class can be omitted now). See _Mini WIn.ahk & Roll.ahk
- TopMost clients added as 11th parameter of dock definition. See help in the archive for details about topmost clients. This feature allows new dimension of docking as you can dock inside the Host. This also makes possible to create arbitrary number of title buttons (you can see that in one of the samples in the archive)

1.0
- Final version
- Documentation updated (switched from mht to html, presets section added, dock defintion explained, remarks about topmost clients added, now available online)

1.0 rc4
- Activating client will now activate host. All in all, composite window now behaves like single window.

1.0 rc3
- Dock now also monitors SHOW and HIDE states of the Host (if DetectHiddenWindows is set). Furthermore, when Host terminates, all clients will be hidden from now on and you must explicitely show them if you re-enable dock with new Host. See _Test2.ahk for example.
- Dock_HostDied removed from API. Dock now automaticaly Toggle's itself OFF when Host dies (and hides the clients)
- New cool example added (set host and number of clients, can be used for mass client testing)
- Some bugs fixed:
  Improper Z-order if Host was active in the time script was executing
  Toggle improved so it returns error when you try to enable already enabled dock

1.0 rc2
- New function - Dock_Toggle. Dock_Enabled removed for optimisation reason. Dock_Toggle makes suspended state of module 100% idle.

1.0 rc1
Bugfixes:
- Removed "F" from RegisterCallback
- If you call Dock again for the same client it will update previous settings
- Shutdown will clean all internal data and module can be used again after shutdown is called.
- WinSetDelay doesn't influence module anymore
Addons:
- New global, Dock_Enabled to temporary disable dock
- Dock definition can now accept only X & Y parameters (first 6). W & H parameters can now be omited. Module will let the client keep its size. You can also omit only W or only H.
- Dock definition can now be entirely omited. In that case client will be docked relatively to already running Dock_Host, i.e. it will keep the distance it had from the Host at the moment Dock was callled.
- You can use "+" now when passing client's ID to make module show hidden client before docking it to the host.
- New _Test.ahk, demonstrating all the things mentioned above.

1.0 b2
- wineventhook.dll removed

1.0 b1
- Added another 2 global variables Dock_OnHostDeath and Dock_HostDied. Set first one to subroutine to make engine call it when host dies. This routine is called only once and it will change global Dock_HostDied to true. If you want to switch the host you will have to reenable Dock_OnHostDeath by setting HostDied to 0.

0.99
- Multidock implemented
- Dock syntax changed as of multidock feature
- Optimisation, stripped version of script is less then 100 lines (no comments, empty lines etc..)

0.96 - Another optimisation
0.95 - Encapsulation.
0.91 - New interface and optimisation (thx Laszlo)
0.00 - Initial[/list]


Reference
[*:2eelkclu]Explanation of dock definition string
[*:2eelkclu] Original idea.
[*:2eelkclu]How to set up out of context hoooks
[*:2eelkclu] WinEvents @ MSDN
[*:2eelkclu]WinEvents by JGR

Thank you
JGR, Laszlo, Joy2DWorld, bmcclure[/list]
Posted Image

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
Cool. Very nice :) .

In your example it might help demonstrate if you add a Run, notepad line. Also, could you have the script close once the notepad window that it docks to is closed?

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Yes, I will eventualy do everything like described in Dock wish.

- Hide/Show dock client with dock host. User handler when dockHost exits so you can terminate app or do other things.
- Expressions in sizeX and sizeY so you can say something like A_DockHostWidt//2
Posted Image

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
Very nice script, majkinetor. I like the idea.

For others who read this thread, please note that AHK version 1.0.46.13+ is required.

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
The only other thing I could ask for is some way for the Dock Client to detect when it has been moved relative to it's docked position, as if it has (have the option to) remember the new Dock_dx and Dock_dy value.

majkinetor !
  • Guests
  • Last active:
  • Joined: --
Well, I created this so to show to Chris it is very easy to implement (counting hook dll)

However, I am planning to update this. One option I forgot is to dock based on child control in dock client. This is very useful in some situations. For instance, if you set the little gui to dock bellow Total Commander left Panel (TMyPanel3) the one can replace entire TC panel with its own GUI so it looks like QuickView of TC. I already demonstrated this in QuickView script, but using much more complex script.

freakkk
  • Members
  • 182 posts
  • Last active: Dec 16 2014 06:23 PM
  • Joined: 29 Jul 2005
This is excellent!! This is something i've sought after for quite some time w/ no satisfactory success. I suppose this provides a simple means for creating custom skins for gui's too! I'll be sure to keep my eyes glued to this post for any updates :D

Thanks majkinetor !!

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
LOL


Create any GUI you like, you just need to pass its handle to the dock command.
Posted Image

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Very nice demo of a new toolset! However, you can have similar effects in much simpler way, so the real value of the hooks could be seen in more complex examples.
Gui -Caption +Border

Gui Show, x200 y50 w600 h500

WinGet gID, ID, %A_ScriptName%



Run notepad,,,nPID

WinWait ahk_pid %nPID%

WinMove ahk_pid %nPID%,,0, 0, 600, 300

WinGet nID, ID, ahk_pid %nPID%



DllCall("SetParent", UInt,nID, UInt,gID)

WinActivate ahk_id %gID%

WinActivate ahk_id %nID%
Here a larger Gui window is created and Notepad is docked to it with the SetParent dll call. The visible part of the Gui can have information texts, buttons, menus, etc.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Well, I am sorry to dissapoint you, but that "method" is very bad (no offense, this is well known method for long time), and very limited. I already played with it a lot previously. It is also not documented as such on MSDN, it is buggy, and it has nothing to do with docking.

You also can't do any feature of Dock wish with it, u acctually pined Notepad inside your GUI, not your GUI aside Notepad. While you can easily do the oposite, try to pin your gui inside notepad ( Dock("M","M") ) and you will see that Edit1 of Notepad will always hide Gui. Success depend on internals of app (i.e. how dock host handle its children)

If you still think I am wrong, please recreate Dock function with SetParent (with all its current features).

Unfortunately, without hooking or subclasing this is not possible to do. In QuickView script I used another technique with 1s timer. Here timer is 0ms adn it is active only while you move your window. This is the reason for GUI repositioning so fast, but "chacing" the Dock Host is visible even with this type of hook (as of WinEventHook limiation)
Posted Image

JGR
  • Members
  • 59 posts
  • Last active: Feb 07 2012 08:49 PM
  • Joined: 15 Jun 2006
Win32 programmer's Reference:

The SetParent function changes the parent window of the specified child window.
...
Remarks

An application can use the SetParent function to set the parent window of a pop-up, overlapped, or child window. The new parent window and the child window must belong to the same application.
...


The main thing however, is that you haven't actually "docked" anything, you've just reduced the amount of screen which notepad can use.

To see what we mean by "docking", try Winamp.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Exactly.
Posted Image

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
2Laszlo
Ah, my research about SetParent is even documented :D
Posted Image

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005

that "method" is very bad (no offense, this is well known method for long time), and very limited.

There were scripts posted to the Forum already two years ago, which used SetParent. I did not find any bugs in my scripts using it. There are trivial things you have to keep in mind: WinSet Region is sometimes necessary, because some windows occupy larger (transparent) area than meets the eye. You want to prevent moving the docked window, or even remove its title bar.

u acctually pined Notepad inside your GUI, not your GUI aside Notepad.

This is the right way, because you can reserve room for Notepad in your GUI, not the other way around.

recreate Dock function with SetParent (with all its current features).

What are these features? I have many uses of SetParent, and it was sufficient for providing tabs, buttons, info fields, etc. around simple applications. It works. And moving around the GUI moves the docked window smoothly, while the movement of your docked window is jerky.

I did not say that hooks are not important, but often you can have even better results with SetParent, than docking.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006

What are these features?

See the function above.

In your example above Notepad is half paint in my situation. WHen I move it, picture becomes garbage.

SetParent can not be made to work generaly good. You can just try to use it for particular app and see how it works, and if placement, size and everything is correct, it might work...

Other then that, its general usage is equal to 0.
Posted Image