Jump to content

Recommended Posts

I am trying to do something, but it appears that I am having issues with trying to get the right functions called, in the right order.

What I want to do is move a window to a certain position and then move it back, but as stated, the order appears to be an issue, as if the window is minimized, the wingetclientsize is not able to pull the info, not is the wingetpos. It appears to be able to get the size and position of the window in question is activated, but I have to activate it first, but that defeats the purpose, as once activated, the functions called to get the position and size, are not correct, as the screen is now active. I have tried to use wingetstate, to get the state first, but I am not sure how to move the window back to the original location with the right state.

If window is minimized, I want it to go back to minimized state, as well as keeping the window size the same, so if the user activates the window, the user does not have to resize it.

If the window is active and is on another screen, it appears I do not have the same issue.

Here is my attempt, but I have tried other combinations. Has anyone got an idea on how to resolve this issue?

Func MoveVNC($Move)
    CreateLogEntry("Called MoveVNC($Move) $Move = " & $Move)
    Local $aStartBar = StartBar()
    Local $bMove = False
    Local $VNC = 'NAMEOFWINDOW'
    Static $aWin_VNC_Pos = ''
    Static $iWin_VNC_State = ''
    Static $aWin_VNC_Size = ''

    #cs
        ;$aWin_VNC_Pos = WinGetPos($VNC, '')
        MsgBox('','VNC POS','')
        _ArrayDisplay(WinGetPos($VNC, ''))
        MsgBox('','VNC STATE',WinGetState($VNC, ''))
        WinActivate($VNC)
        Sleep(20)
        WinWaitActive($VNC, '', 10)
        Sleep(20)
        Local $aSize = WinGetClientSize($VNC, '')
        MsgBox('','VNC SIZE','')
        _ArrayDisplay($aSize)
    #ce


    If $Move = 'Get' Then
        Opt("WinTitleMatchMode", -1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
        If WinExists($VNC) Then
            WinActivate($VNC)
            Sleep(20)
            WinWaitActive($VNC, '', 10)
            Sleep(20)

            $aWin_VNC_Pos = WinGetPos($VNC, '')
            Sleep(20)
            ;_ArrayDisplay($aWin_VNC_Pos, '$aWin_VNC_Pos')

            $iWin_VNC_State = WinGetState($VNC, '')
            Sleep(20)

            $aWin_VNC_Size = WinGetClientSize($VNC, '')
            ;_ArrayDisplay($aWin_VNC_Size)
            ;MsgBox('','$VNC',$VNC)


            ;MsgBox('', '$iWin_VNC_State', $iWin_VNC_State)
            ;WinSetState($VNC, '', @SW_MAXIMIZE)
            ;Sleep(20)

            WinMove($VNC, '', 0, 0, 1600, 950) ;  - (3 * $aStartBar[3])
            Sleep(20)

            ;MouseClick('Left', 1764, 174)
            $bMove = True
        Else
            MsgBox($MB_TOPMOST, 'ERROR GET', 'Window ' & $VNC & ' Does not exists - VNC is not running!')
        EndIf

        If Not $bMove Then
            CreateLogEntry("MoveVNC(GET) FAILED")
            Return False
        Else
            CreateLogEntry("MoveVNC(GET) PASSED")
            Return True
        EndIf
    ElseIf $Move = 'Put' Then
        CreateLogEntry("Called MoveVNC($Move) $Move = " & $Move)
        If WinExists($VNC) Then

            ;WinSetState($VNC, '', @SW_RESTORE)
            ;If @error Then MsgBox('', '', @error)
            ;Sleep(20)
            WinMove($VNC, '', $aWin_VNC_Pos[0], $aWin_VNC_Pos[1], $aWin_VNC_Pos[2], $aWin_VNC_Pos[3])
            If @error Then MsgBox('', '', @error)
            Sleep(20)
            ;WinSetState($VNC, '', $iWin_VNC_State)
            ;If @error Then MsgBox('', 'Not setting state', @error & ' ' & $VNC)
            ;Sleep(20)
            $bMove = True
        Else
            MsgBox($MB_TOPMOST, 'ERROR PUT', 'Window ' & $VNC & ' Does not exists - VNC is not running!')
        EndIf

        If Not $bMove Then
            CreateLogEntry("MoveVNC(PUT) FAILED")
            Return False
        Else
            CreateLogEntry("MoveVNC(PUT) PASSED")
            Return True
        EndIf
    EndIf
    CreateLogEntry("    Returned from MoveVNC()")
EndFunc   ;==>MoveVNC

 

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

There may be a clue in the remarks for WinGetClientSize.  It says minimized windows return 0s for the client measurements.  However non-minimized hidden windows return the correct dimensions.  You could try hiding the minimized windows then setting their state to normal after moving them off screen.  Never did it myself but there must be a way to "restore" a minimized window invisibly and move it out of the screen area without flicker.

I have never had a multi-monitor setup so I can't help with that aspect(no pun intended.)

 

Link to comment
Share on other sites

So I am still testing, but there needs to be a change in the help file, unless the window is activated first, the hiding of it makes no difference - meaning you will still get ZEROs for a hidden window, which means you have to activate it first (bring window up) then Hide it?

 

I have found these, but not sure if it pertains to this, and if so, is this the type of code that Autoit is using?
http://stackoverflow.com/questions/2766709/minimized-window-position-in-wpf

http://stackoverflow.com/questions/5531548/how-to-restore-a-minimized-window-in-code-behind

 

I have created this code below, and it appears to work, though I do not like the flashing screens - using double monitors...are the links above something that will help find info for even minimized windows?

 

Func MoveVNC($Move)

    CreateLogEntry("Called MoveVNC($Move) $Move = " & $Move)
    Local $aStartBar = StartBar()
    Local $bMove = False
    Local $VNC = 'name' ;|0x052D1378
    Static $aWin_VNC_Pos = ''
    Static $iWin_VNC_State = ''
    Static $aWin_VNC_Size = ''

    If $Move = 'Get' Then
        Opt("WinTitleMatchMode", -1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
        If WinExists($VNC) Then
            $iWin_VNC_State = WinGetState($VNC, '')
            ;MsgBox('','Window State',$iWin_VNC_State)
            WinActivate($VNC, '')
            WinWaitActive($VNC, '', 10)
            If @error Then
                MsgBox(0, 'ERROR 0', 'Window timed out or does not exist')
                Return
            EndIf

            WinSetState($VNC, '', @SW_HIDE)
            $aWin_VNC_Pos = WinGetPos($VNC, '')
            Sleep(20)
            WinSetState($VNC, '', @SW_SHOW)
            WinMove($VNC, '', 0, 0, 1600, 950) ; MAX size for the VNC Client - for larger, it would have to be changed on the VNC Server
            $bMove = True
        Else
            MsgBox($MB_TOPMOST, 'ERROR GET', 'Window ' & $VNC & ' Does not exists - VNC is not running!')
        EndIf

        If Not $bMove Then
            CreateLogEntry("MoveVNC(GET) FAILED")
            Return False
        Else
            CreateLogEntry("MoveVNC(GET) PASSED")
            Return True
        EndIf
    ElseIf $Move = 'Put' Then
        CreateLogEntry("Called MoveVNC($Move) $Move = " & $Move)
        If WinExists($VNC) Then

            If $iWin_VNC_State = 23 Then ; if minimized, set size preexisting size and then minimize
                WinMove($VNC, '', $aWin_VNC_Pos[0], $aWin_VNC_Pos[1], $aWin_VNC_Pos[2], $aWin_VNC_Pos[3])
                WinSetState($VNC, '', @SW_MINIMIZE)
            Else
                ; just put the window in its previous location
                WinMove($VNC, '', $aWin_VNC_Pos[0], $aWin_VNC_Pos[1], $aWin_VNC_Pos[2], $aWin_VNC_Pos[3])
            EndIf
            $bMove = True
        Else
            MsgBox($MB_TOPMOST, 'ERROR PUT', 'Window ' & $VNC & ' Does not exists - VNC is not running!')
        EndIf
        Opt("WinTitleMatchMode")
        If Not $bMove Then
            CreateLogEntry("MoveVNC(PUT) FAILED")
            Return False
        Else
            CreateLogEntry("MoveVNC(PUT) PASSED")
            Return True
        EndIf
    EndIf
    CreateLogEntry("    Returned from MoveVNC()")
EndFunc   ;==>MoveVNC

If anyone can improve this, I would be grateful!

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

So I am still testing, but there needs to be a change in the help file, unless the window is activated first, the hiding of it makes no difference - meaning you will still get ZEROs for a hidden window, which means you have to activate it first (bring window up) then Hide it?

I was thinking more along the lines of WinSetState using @SW_RESTORE, then hiding it or moving it off screen.  The idea being it may be less of a flicker than activation.  But since I haven't had a need to do this I would have to experiment just as you are.  No real time saving there I'm afraid.

 

Edited by MilesAhead
Link to comment
Share on other sites

That really does the same thing as activating the screen (as far as I was able to see), so really no change that I noticed.

 

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

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

×
×
  • Create New...