Jump to content

Recommended Posts

Posted

My friends i am trying to dock 2 windows but i have 2 warnings so i cant run the script..

I know probably is easy for you...

can you check this script please...

These are the 2 warnings

WARNING: $iCmd_PID possibly not declared/created yet
$iCmd_PID = Run(@ComSpec & " /k CD " & $Init_Dir, "", @SW_HIDE)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
WARNING: $Embed_hWnd possibly not declared/created yet
$Embed_hWnd = _GetHWndByPID($iCmd_PID)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

This is the script

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Opt ('MustDeclareVars', 1)
Global $Init_Dir = "C:\"
Dim $GUI1, $GUI2
Dim $p_win1, $p_win2, $x1 = 10, $x2 = 315, $y1 = 10, $y2 = 10, $Dock = 1, $Dock_Location = 1
;================================
$GUI1 = GUICreate("Embedded CMD", 800, 600, 10, 10,BitOr($Gui_SS_DEFAULT_GUI,$WS_CLIPCHILDREN))
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
GUIRegisterMsg(0xF, "WM_PAINT")
$iCmd_PID = Run(@ComSpec & " /k CD " & $Init_Dir, "", @SW_HIDE)
ProcessWait($iCmd_PID)
$Embed_hWnd = _GetHWndByPID($iCmd_PID)
WinMove($Embed_hWnd, "", -2, -23, 800, 500)
WinSetState($Embed_hWnd, "", @SW_SHOWMINIMIZED)
GUISetState(@SW_SHOW, $GUI1)
DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $Embed_hWnd, "hwnd", $GUI1)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
;=================================

;=================================
$GUI2 = GUICreate("Right/Bottom Window", 300, 200, 315, 10)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
;==================================
;=============================
GUISetState(@SW_SHOW, $GUI2)
GUISetState(@SW_SHOW, $GUI1)
;=============================
While 1
    Sleep(100)
    If WinActive($GUI1) Then WinActivate($Embed_hWnd)
WEnd
Func Quit()
    ProcessClose($iCmd_PID)
    Exit
EndFunc
Func _GetHWndByPID($iPID)
    Local $aWinList = WinList()
    For $i = 1 To UBound($aWinList)-1
        If WinGetProcess($aWinList[$i][1]) = $iPID Then Return $aWinList[$i][1]
    Next
    Return 0
EndFunc
Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    DllCall("user32.dll", "int", "InvalidateRect", "hwnd", $hWnd, "ptr", 0, "int", 0)
EndFunc
While 1
   If $Dock Then _KeepWindowsDocked()
   Sleep(10)
WEnd
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

[font="verdana, geneva, sans-serif"] [/font]

Posted (edited)

The clue is in using this Opt('MustDeclareVars', 1). Declare the variable(s) e.g. Local or Global.

Edited by guinness

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

Posted (edited)

The clue is in using this Opt('MustDeclareVars', 1). Declare the variable(s) e.g. Local or Global.

Yes correct guinness that was it i executed the script ....Thank you

Now i have to found out why it's not doing what it is suppose to do

Edited by armoros

[font="verdana, geneva, sans-serif"] [/font]

Posted (edited)

Ok i made it run correct

Thank you guinness

is ugly but works

#include <GUIConstants.au3>
#include <WindowsConstants.au3>

Opt ("GUIOnEventMode", 1)
Opt ('MustDeclareVars', 1)
Global $Init_Dir = "C:"
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("Embedded CMD", 800, 600, 10, 10,BitOr($Gui_SS_DEFAULT_GUI,$WS_CLIPCHILDREN))
$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")
GUIRegisterMsg(0xF, "WM_PAINT")
Global $iCmd_PID = Run(@ComSpec & " /k CD " & $Init_Dir, "", @SW_HIDE)
ProcessWait($iCmd_PID)
Global $Embed_hWnd = _GetHWndByPID($iCmd_PID)
WinMove($Embed_hWnd, "", -2, -23, 800, 500)
WinSetState($Embed_hWnd, "", @SW_SHOWMINIMIZED)
GUISetState(@SW_SHOW, $GUI1)
DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $Embed_hWnd, "hwnd", $GUI1)
;===================================================================================================

$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
While 1
    Sleep(100)
    If WinActive($GUI1) Then WinActivate($Embed_hWnd)
WEnd
Func Quit()
    ProcessClose($iCmd_PID)
    Exit
EndFunc
Func _GetHWndByPID($iPID)
    Local $aWinList = WinList()
    For $i = 1 To UBound($aWinList)-1
        If WinGetProcess($aWinList[$i][1]) = $iPID Then Return $aWinList[$i][1]
    Next
    Return 0
EndFunc
Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    DllCall("user32.dll", "int", "InvalidateRect", "hwnd", $hWnd, "ptr", 0, "int", 0)
EndFunc

ps: the docking example is not mine if anyone want can search the forum for --docking windows--

Edited by armoros

[font="verdana, geneva, sans-serif"] [/font]

Posted (edited)

Don't use Dim, try to use either Local or IF necessary Global.

Edit: By the looks of things most are in Local scope.

Edited by guinness

UDF List:

 
_AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples...

Updated: 22/04/2018

Posted

Don't use Dim, try to use either Local or IF necessary Global.

Edit: By the looks of things most are in Local scope.

Thank you for the tip guinness..

no words just thank you ;)

[font="verdana, geneva, sans-serif"] [/font]

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
×
×
  • Create New...