Jump to content

Window Positionings


mr-es335
 Share

Go to solution Solved by mr-es335,

Recommended Posts

Good day,

For a considerable period of time, I was employing "nircmd" in all of my scripts. For various reasons, nircmd was not able to do the tasks that I was requiring, so I looked into "other" alternatives. This is when I discovered "AutoIt!" Thus far, things have been going very well.

However, I have written a scripts that positions tow windows side-by-side. During testing, I was able to have these positioning to display very consistently. Then there are those times where the window positionings are simply not being positioned properly - and I have no idea why?

I have attached a sampling of the script and am wondering what it is that I am doing wrong.

Any assistance would be appreciated!

shell.au3

Edited by mr-es335
Link to comment
Share on other sites

 shell.au3

; -----------------------------------------------
#include <AutoItConstants.au3>
#include <Constants.au3>
#include <FileConstants.au3>
; -----------------------------------------------
WinClose("[folder_path_1]", "")
WinClose("[name_1].txt - metapad", "")
; -----------------------------------------------
ShellExecute("[folder_path_2]")
Sleep(150)
WinMove ("[folder_path_2]", "", 460, 100, 550, 650)
Sleep(150)
; -----------------------------------------------
ShellExecute("[name_2].txt")
Sleep(150)
WinMove ("[name_2].txt - metapad", "", 1010, 100, 550, 650)
; -----------------------------------------------

 

what did you say it does that?

 

 

how-to-post-code-on-the-forum

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

Let's try this script:

#NoTrayIcon
Global $iTestMode = True
Global $sWorkingDir = @ScriptDir
Global $sNotepadFile_1 = '[name_1].txt'
Global $sNotepadFile_Path_1 = $sWorkingDir & '\' & $sNotepadFile_1
Global $sNotepadFile_2 = '[name_2].txt'
Global $sNotepadFile_Path_2 = $sWorkingDir & '\' & $sNotepadFile_2
Global $sNotepad_exe = FileExists(@WindowsDir & '\System32\Notepad.exe') ? @WindowsDir & '\System32\Notepad.exe' : @WindowsDir & '\Notepad.exe'
If $iTestMode Then _OpenTestFile()
OnAutoItExitRegister("Terminate")
Global $g_bPaused = False
; Press Esc to terminate script,
HotKeySet("{PAUSE}", "TogglePause")
; Press Pause/Break to "pause"
HotKeySet("{ESC}", "Terminate")
; Press F5 to "Snap"
HotKeySet("{F5}", "SnapNotepad")
If $iTestMode Then WinWait($sNotepadFile_2, "", 2)
SnapNotepad()
While 1
    Sleep(100)
WEnd
Func SnapNotepad()
    Local $aWin = WinList("[CLASS:Notepad]")
    If $aWin[0][0] > 2 Then
        MsgBox(48 + 262144, "Error", "Open 2 instances (C: " & $aWin[0][0] & ") of Notepad only ", 2)
        _OpenTestFile()
    EndIf
    Local $iW = Int(@DesktopWidth / $aWin[0][0])
    Local $iH = @DesktopHeight - 40
    For $i = 1 To $aWin[0][0]
        WinActivate($aWin[$i][1])
        WinMove($aWin[$i][1], "", ($i - 1) * $iW, 0, $iW, $iH, 1)
    Next
EndFunc   ;==>SnapNotepad
Func TogglePause()
    $g_bPaused = Not $g_bPaused
    While $g_bPaused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause
Func Terminate()
    If $iTestMode Then
        _Close_Notepad_NoSave()
        FileDelete($sNotepadFile_Path_1)
        FileDelete($sNotepadFile_Path_2)
    EndIf
    Exit
EndFunc   ;==>Terminate
Func _OpenTestFile()
    If $iTestMode Then _Close_Notepad_NoSave()
    If Not FileExists($sNotepadFile_Path_1) Then FileWriteLine($sNotepadFile_Path_1, "Tab 1")
    If Not FileExists($sNotepadFile_Path_2) Then FileWriteLine($sNotepadFile_Path_2, "Tab 2")
    If Not ProcessExists("notepad.exe") Or Not WinExists($sNotepadFile_1) Then ShellExecute($sNotepad_exe, $sNotepadFile_Path_1, $sWorkingDir)
    If Not WinExists($sNotepadFile_2) Then ShellExecute($sNotepad_exe, $sNotepadFile_Path_2, $sWorkingDir)
EndFunc   ;==>_OpenTestFile
Func _Click_Notepad_NoSave()
    WinClose($sNotepadFile_1)
    WinClose($sNotepadFile_2)
    Local $aWin = WinList("[CLASS:Notepad]")
    If $aWin[0][0] > 0 Then
        For $i = 1 To $aWin[0][0]
            WinActivate($aWin[$i][1])
            WinClose($aWin[$i][1], "")
        Next
    EndIf
    Local $iCount = 99
    While WinExists("Notepad", "&Save")
        WinActivate("Notepad", "&Save")
        ControlClick("Notepad", "&Save", "[CLASS:Button; INSTANCE:2]")
        $iCount = $iCount - 1
        If $iCount < 2 Then ExitLoop
    WEnd
EndFunc   ;==>_Click_Notepad_NoSave
Func _Close_Notepad_NoSave()
    _Click_Notepad_NoSave()
    Local $iCount = 99
    While ProcessExists("notepad.exe")
        ProcessClose("notepad.exe")
        $iCount = $iCount - 1
        If $iCount < 2 Then ExitLoop
    WEnd
EndFunc   ;==>_Close_Notepad_NoSave

 

Regards,
 

Link to comment
Share on other sites

  • mr-es335 changed the title to Window Positionings

Trong,

WOW! That is quite the listing!! But this is more than I really require...

Please see attached...
* Requirements: A folder called "Me" and a text files called "Me" placed on the  desktop...

1. I have a number of previously created folders/text that I need positioned in the same location
2. All that is changing is the name of the folder and the name of text
3. The positionings as noted - always remain the same

My issue is that the positions of the folders and text are never consistent, and therefore, at times, appear in random locations on the display.

shell_2.au3

Link to comment
Share on other sites

Now that I understand, I also have an example

; -----------------------------------------------
ShellExecute("E:\Desktop\Me")
;~ WinMove ("E:\Desktop\Me", "", 450, 100, 550, 650)
$hWinFolder = WinWait("E:\Desktop\Me")
; -----------------------------------------------
ShellExecute("E:\Desktop\Me.txt")
;~ WinMove ("E:\Desktop\Me.txt - metapad", "", 1020, 100, 550, 650)
$hWinMetapad = WinWait("E:\Desktop\Me.txt - metapad")
; -----------------------------------------------

;$hWinMetapad with 60% of @DesktopWidth
_WinSideBySide($hWinMetapad, $hWinFolder, 60)
ToolTip("$hWinMetapad with 60% of @DesktopWidth")
Sleep(5000)

;$hWinMetapad with 40% of @DesktopWidth
_WinSideBySide($hWinMetapad, $hWinFolder, 40)
ToolTip(";$hWinMetapad with 40% of @DesktopWidth")
Sleep(5000)

;with out parameter $iView1 = 65%
_WinSideBySide($hWinMetapad, $hWinFolder)
ToolTip(";with out parameter $iView1 = 65%")
Sleep(5000)


;----------------------------------------------------------------------------------------
Func _WinSideBySide($hWin1, $hWin2, $iView1 = 65)
    ;Get DeskTop size
    Local $DTs = WinGetPos("[CLASS:Shell_TrayWnd]")
    ConsoleWrite("X=" & $DTs[0] & " Y=" & $DTs[1] & " W=" & $DTs[2] & " H=" & $DTs[3] & @CRLF)

    Local $iScale = (@DesktopWidth / 100)
    ConsoleWrite("$iScale=" & $iScale & @CRLF)
    WinMove($hWin1, "", @DesktopWidth - ($iScale * $iView1), 0, ($iScale * $iView1) + 7, $DTs[1] + 7)
    WinMove($hWin2, "", -7, 0, @DesktopWidth + 21 - ($iScale * $iView1), $DTs[1] + 7)
    WinActivate($hWin1)
EndFunc   ;==>_WinSideBySide

 

Edited by ioa747
prettify

I know that I know nothing

Link to comment
Share on other sites

  • Solution

Good day,

Thanks to you both for the efforts...however, both of the examples have the folder and text maximized.

In my example, the left folder is positioned at 450,100,550,650 and the text is positioned at 1050,100,550,650.

[UPDATE!!]
Apparently the following is now working....all that was required was to increase Sleep by 100...

; -----------------------------------------------
#include <AutoItConstants.au3>
#include <Constants.au3>
#include <FileConstants.au3>
; -----------------------------------------------
ShellExecute("E:\Desktop\Me")
Sleep(250)
WinMove ("E:\Desktop\Me", "", 450, 100, 550, 650)
Sleep(250)
; -----------------------------------------------
ShellExecute("E:\Desktop\Me.txt")
Sleep(250)
WinMove ("E:\Desktop\Me.txt - metapad", "", 1020, 100, 550, 650)
; -----------------------------------------------

Edited by mr-es335
Addition
Link to comment
Share on other sites

; -----------------------------------------------
ShellExecute("E:\Desktop\Me")
$hWinFolder = WinWait("E:\Desktop\Me")
WinMove ($hWinFolder, "", 450, 100, 550, 650)
; -----------------------------------------------
ShellExecute("E:\Desktop\Me.txt")
$hWinMetapad = WinWait("E:\Desktop\Me.txt - metapad")
WinMove ($hWinMetapad, "", 1020, 100, 550, 650)
; -----------------------------------------------

 

I know that I know nothing

Link to comment
Share on other sites

..give credit where credit is due. I like that. Also like that every question you ever posted, you are the one that brought the solution. Remarkable !.
One thing that would be appreciated is that the code is in the code box, the icon with the "<>" symbol, click that before pasting your code.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Link to comment
Share on other sites

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...