Jump to content

WinClose


Recommended Posts

  • Developers

@19dman73,

This is for sure not enough information to understand your issue!
Please try explaining it with more details.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

When I run the script seen below, it does not close the window. It waits for me to close it manually then finishes the script with no problem.

I don't think it is stopping at the WinClose command. It seems like it is ignoring, or skipping the command.

 

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author: Donald Brockstedt

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("This is some text")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "Save")
;WinWaitActive("Notepad", "Do you want to save") ; When running under Windows XP
Send("!n")

 

 

 

Edited by 19dman73
Link to comment
Share on other sites

  • Developers

Didn't the Window title of notepad change after you send() the text, so shouldn't winclose() reflex that change?

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 2 weeks later...

The window title doesn't change for me. The script works so I don't see a problem.

Maybe there is some problem because of a different language - my PC is Windows 10 and the language is English (UK).

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I'd probably do it more like this

; Run Notepad.
Local $iPID = Run("notepad.exe", "", @SW_SHOWNORMAL)

; Wait 10 seconds for the Notepad window to appear.
$hWnd = _GetHwndFromPID($iPID, 10)

ControlSend($hWnd, "", "", "This is some text")
sleep(1000)
; Close the Notepad process using the PID returned by Run.
ProcessClose($iPID)

Func _GetHwndFromPID($PID, $iTimeout_secs) ;;https://www.autoitscript.com/forum/topic/86680-pid-window-handle-hwnd-conversion/
    $iTimeout_secs = $iTimeout_secs * 100
    local $hWnd = 0
    local $stPID = DllStructCreate("int")
    Do
        $winlist2 = WinList()
        For $i = 1 To $winlist2[0][0]
            If $winlist2[$i][0] <> "" Then
                DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i][1], "ptr", DllStructGetPtr($stPID))
                If DllStructGetData($stPID, 1) = $PID Then
                    $hWnd = $winlist2[$i][1]
                    ExitLoop
                EndIf
            EndIf
        Next
        Sleep(100)
        $iTimeout_secs -= 100
    Until $hWnd <> 0 Or $iTimeout_secs <= 0
    Return $hWnd
EndFunc

 

Link to comment
Share on other sites

  • 1 year later...

I had the same issue, just trying to follow the 'Simple Notepad Automation' tutorial in AutoIt Help. I think Jos' answer is the solution. After typing something in notepad the title changes from "Untitled - Notepad" to "*Untitled - Notepad" (the '*' indicates you have unsaved changes). So you need to change the WinClose command to:

WinClose("*Untitled - Notepad")

And then it works.

The AutoIt Help should probably be updated to reflect this?

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