Jump to content

WinMove doesn't work on these msg boxes; fix for this pls?


Recommended Posts

Good Morning! I've put WinMove, recently learned, to work a lot since the post teaching me about it. However, came across a script where neither of the 2 boxes contained in it are moved no matter where I put the commands. Hoping someone here knows why.

;
; AutoIt v3.0
;
; this allows partial window titles to be valid!
AutoItSetOption("WinTitleMatchMode", 2)

SoundPlay ("..\Scripts\WAVs\Bladerunner.wav")
Sleep(500)

;---------------------------------------------------------------
Sleep(3000)
Send("###")

If MsgBox(4096+64+0, 'Info ...', "Once this field populated, click on the GO button to go to the next screen." & @CR & "Then come back to this box and press OK for next script.") == 7 Then
    Exit
Sleep(250)
;WinMove("Info", "", right=500, down=15)
WinMove("Info", "", 500, 15)
EndIf
;---------------------------------------------------------------

Sleep(1000)
Send("###")

$return = MsgBox(8192+64+0, 'Done ...', "You're done." & @CR & @CR & "Press OK to exit.")
;WinMove("Done", "", right=500, down=15)
WinMove("Done", "", 500, 15)
;---------------------------------------------------------------
Exit
; finished
I've moved the code around and placed in different spots re the first box. After the EXIT, after the ENDIF, even before the whole IF code, etc., etc., but nothing works. Both boxes no matter what still show up dead-center, blocking the webpage boxes I need to input into. I'd like to move them via WinMove so that I don't have to keep moving the boxes out of the way manually each time. WinMove has worked with other boxes that I've used but this doesn't and I don't know why. Pls help. <g>

Thanks! :whistle:

Edited by Diana (Cda)
Link to comment
Share on other sites

A MsgBox (or input box and some other functions) halts the script waiting for a user's input. If no timeout is specified for the MsgBox, the script just sits there waiting for the user to respond. After the user clicks okay, the script can continue - but by that time, there will be no MsgBox for the WinMove line to work on.

The work around is to dive into the world of GUIs (make your own MsgBox*) or use code like in this post: http://www.autoitscript.com/forum/index.php?showtopic=22531

That code will launch a second script - the second script will move the MsgBox.

*There should be several of these in the Example Scripts forum - I just don't have a link atm.

-MSP-

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

For future reference, you can add up the flag numbers your self, and also, the return for "No" and "Cancel" are different.

So for your first message box should be like this

If MsgBox(4133, 'Info ...', "Once this field populated, click on the GO button to go to the next screen." & @CR & "Then come back to this box and press OK for next script.") == 2 Then Exit
Sleep(250)
Link to comment
Share on other sites

  • 3 weeks later...

Thanks so much to everyone for their replies. RL got in the way with many things happening (good things, for a change! <g>) so only now getting back to these issues.

Will look at all of this and report back.

Thanks! :whistle:

p.s., thank you re WinMove. We noobs don't always know what's happening behind the scenes, so I really appreciate the education. Cheers.

Link to comment
Share on other sites

For future reference, you can add up the flag numbers your self, and also, the return for "No" and "Cancel" are different.

I have a hard time with this concept. Intellectually I understand about flags and such, but in reality, I need to see examples of working code as I'm very stupid when it comes to rather drastically modifying code. The syntax in the help files is of some use, of course, but even after years of dealing with syntax, I'm still not good at making changes until I've seen adequate examples. For instance, this new box (which still doesn't work, btw, for some reason), now has RETRY and CANCEL on them when I only need one button that says OK <grin>. Back to the drawing board. I'll hunt around for more msgbx examples yet again to see if I can figure out what's up with that.

So for your first message box should be like this

If MsgBox(4133, 'Info ...', "Once this field populated, click on the GO button to go to the next screen." & @CR & "Then come back to this box and press OK for next script.") == 2 Then Exit
Sleep(250)
Well, I tried this, and thanks much for the code. The box still doesn't move and it still covers the input box the data must be dumped into. Various changes to the co-ordinates show no difference at all in the msgbox's position whatsoever, so I'm still not doing something right <sigh>.

Will keep trying. Thanks.

Cheers. :whistle:

Link to comment
Share on other sites

...The box still doesn't move...

Run this code (credit SmOke_N):
$ret = _MoveMsgBox(4096 + 64 + 0, "Info ...", "Once this field populated, click on the GO button to go to the next screen." & @CR & "Then come back to this box and press OK for next script.", 100, 0, 10)

MsgBox(0, "returned", $ret)

Func _MoveMsgBox($MBFlag, $MBTitle, $MBText, $MBTimeOut, $MBxPos, $MByPos, $MBContinue = 0)
    Local $MBFile = FileOpen(EnvGet("temp") & "\MiscMMB.xxx", 2)
    Local $MBFile2 = FileOpen(EnvGet("temp") & "\MiscMMB2.xxx", 2)
    If $MBFile = -1 Or $MBFile2 = -1 Then Return

    Local $LineDelimter = '', $MBPID1 = '', $MBPID2 = ''

    If UBound(StringSplit($MBText, @CRLF, 1)) - 2 > 0 Then
        $LineDelimter = @CRLF
    ElseIf UBound(StringSplit($MBText, @CR, 1)) - 2 > 0 Then
        $LineDelimter = @CR
    ElseIf UBound(StringSplit($MBText, @LF, 1)) - 2 > 0 Then
        $LineDelimter = @LF
    EndIf

    Local $SSpMB = StringSplit($MBText, $LineDelimter, 1)
    If UBound($SSpMB) - 2 > 0 And $LineDelimter <> '' Then
        Local $MBLine1 = '#NoTrayIcon'
        Local $MBLine2 = 'AutoItSetOption(' & '"WinWaitDelay", 0' & ')'
        FileWriteLine($MBFile, $MBLine1 & @CRLF & $MBLine2)

        $MsgBoxLine1 = '#NoTrayIcon'
        FileWriteLine($MBFile2, $MsgBoxLine1)

        Local $MsgBoxLine[UBound($SSpMB) ]
        Local $LinesToShow = ''
        For $iCount = 1 To UBound($SSpMB) - 1
            FileWriteLine($MBFile, '$MsgBoxLine' & $iCount & ' = "' & $SSpMB[$iCount] & '"')
            FileWriteLine($MBFile2, '$MsgBoxLine' & $iCount & ' = "' & $SSpMB[$iCount] & '"')
            If $iCount < UBound($SSpMB) - 1 Then
                $LinesToShow &= '$MsgBoxLine' & $iCount & ' & @CRLF & '
            Else
                $LinesToShow &= '$MsgBoxLine' & $iCount
            EndIf
        Next

        Local $MBLine3 = 'WinWait("' & $MBTitle & '", ' & '$LinesToShow' & ')'
        Local $MBLine4 = 'WinMove("' & $MBTitle & '", ' & '$LinesToShow' & ', ' & $MBxPos & ', ' & $MByPos & ')'
        FileWriteLine($MBFile, '$LinesToShow = ' & $LinesToShow & @CRLF & $MBLine3 & @CRLF & $MBLine4)
        FileWriteLine($MBFile2, '$LinesToShow = ' & $LinesToShow)

        Local $MsgBoxLine2 = '$MsgBoxValue = MsgBox(' & $MBFlag & ', ''' & $MBTitle & ''', ' & '$LinesToShow' & ', ''' & $MBTimeOut & ''')'
        Local $MsgBoxLine3 = 'ConsoleWrite(' & "'MsgBoxSays'" & ' & $MsgBoxValue & ' & "'Return'" & ')'
        FileWriteLine($MBFile2, $MsgBoxLine2 & @CRLF & $MsgBoxLine3)
        FileClose($MBFile)
        FileClose($MBFile2)
    Else
        Local $MBLine1 = '#NoTrayIcon'
        Local $MBLine2 = 'AutoItSetOption(' & '"WinWaitDelay", 0' & ')'
        Local $MBLine3 = 'WinWait("' & $MBTitle & '", "' & $MBText & '")'
        Local $MBLine4 = 'WinMove("' & $MBTitle & '", "' & $MBText & '"' & ', ' & $MBxPos & ', ' & $MByPos & ')'
        FileWrite($MBFile, $MBLine1 & @CRLF & $MBLine2 & @CRLF & $MBLine3 & @CRLF & $MBLine4)
        FileClose($MBFile)

        Local $MsgBoxLine1 = '#NoTrayIcon'
        Local $MsgBoxLine2 = '$MsgBoxValue = MsgBox(' & $MBFlag & ', ''' & $MBTitle & ''', ''' & $MBText & ''', ''' & $MBTimeOut & ''')'
        Local $MsgBoxLine3 = 'ConsoleWrite(' & "'MsgBoxSays'" & ' & $MsgBoxValue & ' & "'Return'" & ')'
        FileWrite($MBFile2, $MsgBoxLine1 & @CRLF & $MsgBoxLine2 & @CRLF & $MsgBoxLine3)
        FileClose($MBFile2)
    EndIf

    $MBPID1 = Run(@AutoItExe & " /AutoIt3ExecuteScript " & EnvGet("temp") & "\MiscMMB.xxx")
    $MBPID2 = Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & EnvGet("temp") & "\MiscMMB2.xxx", @WorkingDir, 0, 6)

    WinWait($MBTitle, $MBText, 2)
    While (Not FileDelete(EnvGet("temp") & "\MiscMMB.xxx") Or Not FileDelete(EnvGet("temp") & "\MiscMMB2.xxx"))
        Sleep(10)
    WEnd

    If $MBContinue Then
        While 1
            $StdOutReadValue = StdoutRead($MBPID2)
            If StringInStr($StdOutReadValue, 'MsgBoxSays') Then
                $a_Array = StringRegExp($StdOutReadValue, '(?:MsgBoxSays)(.*?)(?:Return)', 3)
                If Not @error Then Return $a_Array[0]
                Return 0
            EndIf
            Sleep(10)
        WEnd
    EndIf
    Return 0
EndFunc   ;==>_MoveMsgBox
You don't have to edit (or understand) the code inside the UDF, just use _MoveMsgBox(...) each time you want a MsgBox that moves out of your way.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Wow! That's impressive. Thanks for the code.

It feels like overkill, somehow. Does anyone know why WinMove might not work? I've tried to use this code above in my particular script but I've not had any luck. It appears jammed up to the top corner of the screen; should it do that?

Anyway, thanks. It's a shame that WinMove has done what's needed as I managed to get a handle on that script. As you say, I don't need to understand the code (which is what often happens anyway <g>), but I'd need to have at least a glimmer of understanding how to work with it so I can actually modify and use to my needs. I'm not there yet. It's a good thing I persevere because I often get discouraged. VB scripting and AI can make me feel really stupid <g>. Believe it or not, I'm a power user, so imagine real noobs at computers, how they would feel? <lol>

Thanks. I'll put this one to rest for now and come back to look at it again sometime. Maybe I can then get a handle on what might work. The only thing wrong with my original code is that the webpage boxes keep getting covered by the AI msgbx and it's a pain to constantly move them out of the way. But I can live with that behaviour some more for now.

Cheers. :whistle:

Link to comment
Share on other sites

Wow! That's impressive. Thanks for the code....

You are welcome.

...Does anyone know why WinMove might not work?...

If you are asking why you cannot have a MsgBox line followed by a WinMove line inside the same script - I attempted to answer that in post #2:

http://www.autoitscript.com/forum/index.ph...st&p=367488

...I've tried to use this code above in my particular script but I've not had any luck. It appears jammed up to the top corner of the screen; should it do that?...

It will go anywhere you tell it to go:

$ret = _MoveMsgBox(4096 + 64 + 0, "Info ...", "Once ....", 100, 500, 500)

Just change the X and Y coordinates on the end of the function call.

(Sorry that I failed to explain that earlier.)

...it's a pain to constantly move them out of the way. But I can live with that behaviour some more for now....

There are very few things that you have to "live with" in AutoIt :-)

-MSP-

[size="1"][font="Arial"].[u].[/u][/font][/size]

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