Maximize and Aero snap on DockableFloatingWindow
Asked Answered
S

3

26

I have the following code to give a undocked floating AvalonDock window the ability to maximize:

class MaximizableDockableContent : AvalonDock.DockableContent
{
    public MaximizableDockableContent()
        : base()
    {
         base.StateChanged += MaximizableDockableContent_StateChanged;
    }

    private void MaximizableDockableContent_StateChanged(
        object sender, RoutedEventArgs e)
    {
        MaximizableDockableContent mdc = (MaximizableDockableContent)sender;
        if (mdc.State == DockableContentState.DockableWindow)
        {
            base.FloatingWindowSizeToContent = SizeToContent.WidthAndHeight;
            FloatingDockablePane fdp = (FloatingDockablePane)base.Parent;
            DockableFloatingWindow dfw = (DockableFloatingWindow)fdp.Parent;

            //dfw.WindowState = WindowState.Maximized;
            dfw.WindowStyle = WindowStyle.ThreeDBorderWindow;
            dfw.ResizeMode = ResizeMode.CanResize;

            //disable minimize button
            ControlBox.SetHasMinimizeButton(dfw, false);
        }
    }
}

How do I go about adding Aero Snap functionality to this?

Selfsealing answered 27/5, 2011 at 16:58 Comment(9)
Snap is functionality implemented by the OS, not the Windows. You'd probably want to go about editing or deriving from DockingManager.Menticide
the important class seems to be "WindowInteropWrapper.cs". I hope someone can point out the aero snap important lines.Selfsealing
Do you want it to be able to snap to the whole screen or just a DockingManager?Menticide
I want to be able to aero snap the (undocked floating) DockableContent to the edges of the whole screen, like it is possible with visual studio 2010. (For excample snap to the top edge it get maximized; snap to the right end left edge it it fills out half of the screen.) Thanks in advance.Selfsealing
Each undocked floating panel in VS2010 is an OS Window; therefore, the reason it can snap is because the OS detects the Window and does its thing. This functionality should come by default for Windows 7. If you want this to happen in other OSs as well, you might want to start looking in DockingManager in the methods: IDropSurface.OnDragEnter, Drag(FloatingWindow, Point, Point).Menticide
Many thanks for your help. I just want aero snap in windows 7. But unfortunately Win7 does not recognize my floating Avalondock content as a normal OS window and therefore does not snap it. It would be great if you could explain me which part of the code I have to edit. If you comment the line 483 (version1.3 from svn) in FloatingWindow.cs “wih.FilterMessage += new EventHandler<FilterMessageEventArgs>(FilterMessage);” the dockable content aero snaps but unfortunately does not longer dock into the manager.Selfsealing
It seems like the WindowInteropHelper Class causes the WindowMessages to be handled by the HookHandler exclusively and therefore the WindowMessages cannot trigger AeroSnap Events.Selfsealing
In FloatingWindow.cs, lines 508, 510, 511; it seems to be exiting the switch if there's a WM_SIZE, WM_MOVE message. You might want to log these or check what's going on in there.Menticide
thx for your fast answer. I will take a look at this.Selfsealing
S
1

For who is interested latest version of AvalonDock (version 2) natively supports floating window aero snap feature. AvalonDock 2.0 is still in beta, more info: http://avalondock.codeplex.com/ New features: http://avalondock.codeplex.com/wikipage?title=Version2Concept

Stepup answered 2/4, 2012 at 20:38 Comment(0)
G
1

you could run an external process, using runtime:

download nircmd.exe from: http://www.nirsoft.net/utils/nircmd.html and make sure it is in the same directory as the .class file or in the windows PATH environment variable

then use Runtime.exec() to run it several times:

Runtime r=Runtime.getRuntime();
r.exec("nircmd.exe sendkey lwin down");
r.exec("nircmd.exe sendkey "+direction+" press");
//change direction to "right" (for right side), "left" (for left side), or "up" (for full window).
r.exec("nircmd.exe sendkey lwin up");

note that this can throw an IOException, so a try/catch block might be necessary.

note:this assumes that the window is the active one.

Glycolysis answered 13/9, 2011 at 1:35 Comment(0)
P
1

anon said “Unfortunately is also disables, Windows + Up or Down arrow for Max./Min. the active Window.”

vIBIUS said “This also disables the Windows Key + Shift and Left/Right option!”

Kermonk said “unfortunately that also disables the “shake window to close all other windows” feature…”

Try this:

[HKEY_CURRENT_USER\Control Panel\Desktop]
"DockMoving"="0"

It disables the mouse action to maximise windows and snap windows to the side but not the keyboard shortcuts. It does not affect AeroPeak or AeroShake. It also does not affect ‘maximising a window in a verticle direction only’.

Plication answered 21/10, 2011 at 19:9 Comment(0)
S
1

For who is interested latest version of AvalonDock (version 2) natively supports floating window aero snap feature. AvalonDock 2.0 is still in beta, more info: http://avalondock.codeplex.com/ New features: http://avalondock.codeplex.com/wikipage?title=Version2Concept

Stepup answered 2/4, 2012 at 20:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.