Jump to content

Dockable Windows


GaryFrost
 Share

Recommended Posts

Was working on another project and ended up adding this in as an extra:

Though some find it useful, I believe Burrup was trying to figure this out at one time.

Gary

#include <GuiConstants.au3>

Opt ("GUIOnEventMode", 1)

Opt ('MustDeclareVars', 1)
Dim $Btn_Exit1, $Btn_Exit2, $GUI1, $GUI2
Dim $p_win1, $p_win2, $x1 = 10, $x2 = 315, $y1 = 10, $y2 = 10, $Dock = 1, $Dock_Location = 1
Dim $OptionsMenu1, $OptionsItem1,$OptionsItem2,$OptionsItem3,$OptionsItem4, $separator1

;===================================================================================================

=======================
$GUI1 = GUICreate("Left/Top Window", 300, 200, 10, 10)
$OptionsMenu1 = GUICtrlCreateMenu("Options")
$OptionsItem1 = GUICtrlCreateMenu("Docking", $OptionsMenu1)

$OptionsItem2 = GUICtrlCreateMenuItem("Docked", $OptionsItem1)
$separator1 = GUICtrlCreateMenuitem ("",$OptionsItem1)
$OptionsItem3 = GUICtrlCreateMenuItem("Side By Side", $OptionsItem1)
$OptionsItem4 = GUICtrlCreateMenuItem("Top And Bottom", $OptionsItem1)
GUICtrlSetState($OptionsItem2, $GUI_CHECKED)
GUICtrlSetState($OptionsItem3, $GUI_CHECKED)
GUICtrlSetOnEvent($OptionsItem2, "_SetDocking")
GUICtrlSetOnEvent($OptionsItem3, "_SetDockSideBySide")
GUICtrlSetOnEvent($OptionsItem4, "_SetDockTopAndBottom")

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

$Btn_Exit1 = GUICtrlCreateButton("Exit", 175, 140, 90, 25)
GUICtrlSetOnEvent($Btn_Exit1, "_Exit")

;===================================================================================================

=======================

$GUI2 = GUICreate("Right/Bottom Window", 300, 200, 315, 10)

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

$Btn_Exit2 = GUICtrlCreateButton("Exit", 175, 140, 90, 25)
GUICtrlSetOnEvent($Btn_Exit2, "_Exit")

;===================================================================================================

=======================

GUISetState(@SW_SHOW, $GUI2)
GUISetState(@SW_SHOW, $GUI1)

;===================================================================================================

=======================
While 1
   If $Dock Then _KeepWindowsDocked()
   Sleep(10)
WEnd

Func _SetDocking()
   If BitAND(GUICtrlRead($OptionsItem2), $GUI_CHECKED) = $GUI_CHECKED Then
      GUICtrlSetState($OptionsItem2, $GUI_UNCHECKED)
      $Dock = 0
   Else
      GUICtrlSetState($OptionsItem2, $GUI_CHECKED)
      $Dock = 2
   EndIf
    If $Dock Then _KeepWindowsDocked()
EndFunc
    
Func _SetDockSideBySide()   
   If BitAND(GUICtrlRead($OptionsItem3), $GUI_CHECKED) = $GUI_CHECKED Then
      GUICtrlSetState($OptionsItem3, $GUI_UNCHECKED)
      GUICtrlSetState($OptionsItem4, $GUI_CHECKED)
        $Dock_Location = 2
   Else
      GUICtrlSetState($OptionsItem3, $GUI_CHECKED)
      GUICtrlSetState($OptionsItem4, $GUI_UNCHECKED)
        $Dock_Location = 1
      If $Dock Then $Dock = 2
   EndIf
    If $Dock Then _KeepWindowsDocked()
EndFunc

Func _SetDockTopAndBottom()
   If BitAND(GUICtrlRead($OptionsItem4), $GUI_CHECKED) = $GUI_CHECKED Then
      GUICtrlSetState($OptionsItem4, $GUI_UNCHECKED)
      GUICtrlSetState($OptionsItem3, $GUI_CHECKED)
        $Dock_Location = 1
   Else
      GUICtrlSetState($OptionsItem4, $GUI_CHECKED)
      GUICtrlSetState($OptionsItem3, $GUI_UNCHECKED)
        $Dock_Location = 2
      If $Dock Then $Dock = 2
   EndIf
    If $Dock Then _KeepWindowsDocked()
EndFunc  ;==>_SetDocking1

Func _KeepWindowsDocked()
   $p_win1 = WinGetPos($GUI1)
   $p_win2 = WinGetPos($GUI2)
    If $Dock_Location == 1 Then
        If (($p_win1[0] <> $x1 Or $p_win1[1] <> $y1) And BitAND(WinGetState($GUI1),8) Or $Dock = 2) Then
            $x1 = $p_win1[0]
            $y1 = $p_win1[1]
            $x2 = $p_win1[2] + $x1
            $y2 = $y1
            WinMove($GUI2, "", $x2, $y2)
            $Dock = 1
        ElseIf (($p_win2[0] <> $x2 Or $p_win2[1] <> $y2) And BitAND(WinGetState($GUI2),8)) Then
            $x2 = $p_win2[0]
            $y2 = $p_win2[1]
            $x1 = $p_win2[0] - $p_win1[2]
            $y1 = $y2
            WinMove($GUI1, "", $x1, $y1)
        EndIf
    Else
        If (($p_win1[0] <> $x1 Or $p_win1[1] <> $y1) And BitAND(WinGetState($GUI1),8) Or $Dock = 2) Then
            $x1 = $p_win1[0]
            $y1 = $p_win1[1]
            $x2 = $x1
            $y2 = $p_win1[3] + $y1
            WinMove($GUI2, "", $x2, $y2)
            $Dock = 1
        ElseIf (($p_win2[0] <> $x2 Or $p_win2[1] <> $y2) And BitAND(WinGetState($GUI2),8)) Then
            $x2 = $p_win2[0]
            $y2 = $p_win2[1]
            $x1 = $x2
            $y1 = $p_win2[1] - $p_win1[3]
            WinMove($GUI1, "", $x1, $y1)
        EndIf
    EndIf
EndFunc  ;==>_KeepWindowsDocked

Func _Exit()
   Exit
EndFunc  ;==>_Exit

Func SpecialEvents()
   Select
      Case @GUI_CtrlId = $GUI_EVENT_CLOSE
         Exit
   EndSelect
EndFunc  ;==>SpecialEvents

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Very cool. Logical extension would also be to be able de-chrome the second window and have it iconify and de-iconify with its "host" window.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...