Jump to content
mike2003

Why WinClose does not work?

Recommended Posts

mike2003

I want to close the script window with another script.

But if I use Opt("GUICloseOnESC", 0) then the command WinClose does not work. WHY???

Simple test

#NoTrayIcon
Opt("GUICloseOnESC", 0)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Scores", 615, 438, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 24, 8, 75, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            WinClose("Scores")
    EndSwitch
WEnd


 

Share this post


Link to post
Share on other sites
Jos

That seems to block the Close message totally, but you still can use GuiDelete($Form1) in stead of a WinClose() to close the window, which should be preferred anyway.

Jos 


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

Share this post


Link to post
Share on other sites
mike2003
Posted (edited)
3 hours ago, Jos said:

you still can use GuiDelete($Form1)

 

3 hours ago, mike2003 said:

with another script.

This is an old bug. Anyway, I found a solution in the Russian forum.
http://autoit-script.ru/index.php?topic=963.0
GUIRegisterMsg($WM_CLOSE, "WM_CLOSE")

#NoTrayIcon
Opt("GUICloseOnESC", 0)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Scores", 615, 438, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 24, 8, 75, 25)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_CLOSE, "WM_CLOSE")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            WinClose("Scores")
    EndSwitch
WEnd

Func WM_CLOSE($hWnd, $nMsg, $lParam, $wParam)
    Exit
EndFunc

 

Edited by mike2003

Share this post


Link to post
Share on other sites
Jos

"With another script " while the WinClose  with its own Title is located in the same script?  confusing  for me. ;)

That solution indeed will work and don't think you need the WinKill() in there. 

Jos


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

Share this post


Link to post
Share on other sites
mike2003
3 hours ago, Jos said:

don't think you need the WinKill() in there. 

Yes, it's left here from previous tests.

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

×