Jump to content

Close GUI Window


shogun
 Share

Recommended Posts

Hi,

The following code works, but I have searched and searched and experimented and experimented and I just can't figure out how to make the GUI window close after ccleaner finishes.

#notrayicon
#include <GUIConstants.au3>
Run("c:\program files\ccleaner\ccleaner.exe /auto")
$Form = GUICreate("Cleaning...", 300, 100, 700, 475)
GUICtrlCreateAvi("shell32.dll", 164, 10, 10, -1, -1, BitOr($ACS_TRANSPARENT, $ACS_AUTOPLAY))
GUISetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd

Any hints?

Thanks in advance!

 

P.S.  I have only briefly looked into this, but would also like for the window to self center on the screen rather than specify location due to different resolutions on my computers.

Link to comment
Share on other sites

Why are you using a DLL for the filename in the AVI window? Also, why do you need a GUI just to run CCleaner, what is the GUI for?

Your GUI isn't ever going to close until  you close it because you don't check to see if CCleaner is running or not, use ProcessExists to see if it's still running, and when it's not, close your GUI, or just exit the While loop when it does.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Why are you using a DLL for the filename in the AVI window?

That DLL provides an animation that I find acceptable for my purpose.

Also, why do you need a GUI just to run CCleaner, what is the GUI for?

Because when CCleaner is run from the command line with the /auto switch, there is no GUI and I want a window to be visible while it is working.  There is an animated icon in the tray while it is working, but with my taskbar on autohide it is out of sight.

 

Edit:  changed the last two lines:

While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd

to this:

ProcessWaitClose ("ccleaner.exe")
exit

and it works.

Still have to figure out how to make the window center automatically.

Edit 2:  Got the window to center.  Would like to get it to stay on top - WinSetOnTop nor $WS_EX_TOPMOST seem to be working.

Edited by shogun
Link to comment
Share on other sites

#notrayicon
#include <GUIConstants.au3>
#include <WinAPI.au3>

$width = _WinAPI_GetSystemMetrics(0)
$height = _WinAPI_GetSystemMetrics(1)
$widthi = 300
$heighti = 100
Run("c:\program files\ccleaner\ccleaner.exe /auto")
$Form = GUICreate("Cleaning...", $widthi, $heighti, ($width / 2 ) - ($widthi / 2), ($height / 2 ) - ($heighti / 2),$DS_MODALFRAME,$WS_EX_TOPMOST) ; width height left top
GUICtrlCreateAvi("shell32.dll", 164, 10, 10, -1, -1, BitOr($ACS_TRANSPARENT, $ACS_AUTOPLAY))
GUISetState()
ProcessWaitClose ("ccleaner.exe")
exit

Link to comment
Share on other sites

you can always do it on this way then you don't need ProcessWaitClose

#notrayicon
#include <GUIConstants.au3>
#include <WinAPI.au3>

$width = _WinAPI_GetSystemMetrics(0)
$height = _WinAPI_GetSystemMetrics(1)
$widthi = 300
$heighti = 100
$Form = GUICreate("Cleaning...", $widthi, $heighti, ($width / 2 ) - ($widthi / 2), ($height / 2 ) - ($heighti / 2),$DS_MODALFRAME,$WS_EX_TOPMOST) ; width height left top
GUICtrlCreateAvi("shell32.dll", 164, 10, 10, -1, -1, BitOr($ACS_TRANSPARENT, $ACS_AUTOPLAY))
GUISetState()
RunWait("c:\program files\ccleaner\ccleaner.exe /auto")
exit
Link to comment
Share on other sites

Thanks guys - though cleaner than what I had came up with, they work the same as mine.

As I stated in my second edit above, WinSetOnTop nor $WS_EX_TOPMOST neither one are working.  The window starts in focus, then goes out of focus while CCleaner is running, then comes back into focus for a moment before closing.

I would like for it to stay in focus throughout but am happy I got this far with it :)

 

Link to comment
Share on other sites

Got everything as I want now :)  Used some of all examples and stuff I found in other posts. 

I never could get WinSetOnTop nor $WS_EX_TOPMOST to work, so used a MouseClick trick to keep the GUI window on top and in focus (mouse moves to center of screen, clicks then returns to original position) - may be crude but it works!

Thanks again.

Here is the final code in case anyone wanders along trying to do the same thing:

#notrayicon
#include <GUIConstants.au3>
#include <WinAPI.au3>
$width = _WinAPI_GetSystemMetrics(0)
$height = _WinAPI_GetSystemMetrics(1)
$widthi = 300
$heighti = 125
Run("c:\program files\ccleaner\ccleaner.exe /auto")
$pos=MouseGetPos() 
MouseClick("left", @DesktopWidth / 2, @DesktopHeight / 2,1,0)
MouseMove($pos[0],$pos[1],0)
$Form = GUICreate("Cleaning...", $widthi, $heighti, -1,-1,$DS_MODALFRAME,$WS_EX_TOPMOST)
GUICtrlCreateAvi("shell32.dll", 164, 10, 10, -1, -1, BitOr($ACS_TRANSPARENT, $ACS_AUTOPLAY))
GUISetState()
ProcessWaitClose ("ccleaner.exe")
exit
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...