Sign in to follow this  
Followers 0
ariestav

Closing all documents without saving not working. Need some help. . .

4 posts in this topic

Hi There,

I've got an app (a basic text editor) that allows me to open multiple documents as tabs within the main window.  The File menu of the app has a "Close All" command which is set to Ctrl+Alt+W.  If there are unsaved changes in any document, and I execute the Close All command from the FIle menu the app naturally asks if I want to save changes.  For my script, I do not want to save changes for any file that is open and that has edits.  The pop-up confirm window that asks this question does not have a consistent title in the title bar, but it does have a consistent class identifier which is #32770.  I am able to successfully close the file without saving changes by sending the app an Alt+N command since "No" is an option.

The problem is that I cannot figure out how to do this for all documents.  Well, it seems to work, but then it gets locked up.  Here is the code of my script that is attempting to do this:

Send("^!w") ;Sending shortcut key command to "Close All Documents"
While WinExists("[CLASS:#32770]") ;As long as a confirm popup exists
    Send("!n") ;Send shortcut key command to answer "No"
WEnd ;Exit the loop when the window cannot be found.

So, all the documents DO close, but the problem is the loop never exits.  I'm not sure why since after the last document closes, there is no more Window with [CLASS:#32770] identifier.

Can anybody out there shed some light as to why this might be the case?  I know in the documentation for WinExists it does say that even if a window is hidden it will return true, but I'm uncertain how to detect if there is a hidden window with that class identifier.  I've been using the Window Info app that comes with AutoIt to investigate, but I cannot find one.

Any help would be greatly appreciated.

Thanks for your time and help!

Share this post


Link to post
Share on other sites



Send("^!w") ;Sending shortcut key command to "Close All Documents" 
While 1
   If WinExists("[CLASS:#32770]") ;As long as a confirm popup exists     
     Send("!n") ;Send shortcut key command to answer "No"  
     Sleep(1000);After closing each command window wait for the program to create another one if it needs to
   Else
     ExitLoop
WEnd;Exit the loop when the window cannot be found.

I like that you documented each line.


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

Thanks for the reply!  I tried it out after fixing a couple of syntax errors (your example code needed a `Then` and an `EndIf`), but the loop still wouldn't exit, so I went back to documentation and read up a bit on WaitWinActivate.  It turns out that you can have a "timeout".  So this is eventually what I went with that is suiting my needs:

Send("^!w")
While WinWaitActive("[CLASS:#32770]", "", 2)
    Send("!n")
WEnd

Thank you for your time and help, though.  I really appreciate it!

Share this post


Link to post
Share on other sites

If you don't want to "save changes"... Might try ProcessClose() or WinKill()


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
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
Sign in to follow this  
Followers 0