Sign in to follow this  
Followers 0
DenDuze

Winclose (or WinKill) not working

8 posts in this topic

Hello,

I'm a new user of AutoIt and I have the following problem:

- have a au3-script that does some processing (getting some values and check a few items

- when everything is OK I call a function (that exist in a included au3-script)

- that function creates a GUI, that GUI works with then 'Opt("GUIOnEventMode", 1)'

- In that included-file there are only functions that process the user-events

- Now is my problem that when they click OK (or they close the GUI) I want to return processing my original script (all the lines after the GUI-create) so I want to close this GUI window but I'm probably doing something wrong.

Simplified I have the following

Master Script:

#include <file2.au3>

<multiple checks>

if <all checks are ok> then func-CreateWindow()

msgbox(......)

file2.au3

Opt("MustDeclareVars", 1)

func func-CreateWindow()

....

$Screen = GUICreate("Generate", 400, 150)

GUISetOnEvent($GUI_EVENT_CLOSE, "Func-CloseThisWindow")

EnvSet("BSCREEN",$Screen)

...

while 1

Sleep(1000) ; Idle

WEnd

EndFunc

func func-CloseThisWindow()

local $Screen

$screen = EnvGet("BSCREEN")

winclose($Screen)

EndFunc

Now when I click the window-close button the GUI-screen stays vissible and I don't get the MsgBox that is coded just after the func-CreateWindow (in my masterscript)

I've tried multiple variations to do this but always the same result.

The only thing that works is to use a Exit-statement but then my main program also stops and that's not the wanted behaviour

What I'm I doing wrong?

Note: I will change the whole setup (first create my window - then I will do my tests and if something is not Ok I will stop the program (with exit because that works ok). But I still like to know what's my problem with my first method.

Thanks

Didier

Share this post


Link to post
Share on other sites



DenDuze,

Welcome to the AutoIt forum. :graduated:

A novel way of coding, if I may say so. :D

Your problem arises because you have no way of escaping from the While...WEnd loop in file2.au3. In keeping with the coding style you are using, I would suggest something along these lines (look for the <<<<<<<<<<<<<<<<<<<< lines:

Func CreateWindow()

    $Screen = GUICreate("Generate", 400, 150)
    EnvSet("BSCREEN",$Screen)
    EnvSet("GUIEXIT", 0) ; Create an envvar to keep us in the loop <<<<<<<<<<<<<<<<<<<<
    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseThisWindow")
    GUISetState()

    While EnvGet("GUIEXIT") = 0 ; Check the envvar <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        Sleep(1000) ; Idle
    WEnd

EndFunc   ;==>CreateWindow

Func CloseThisWindow()

    $Screen = EnvGet("BSCREEN")
    GUIDelete($Screen) ; Better to use this as you created it <<<<<<<<<<<<<<<<<<<<<<<<<
    EnvSet("GUIEXIT", 1) ; Set the envvar to exit the loop <<<<<<<<<<<<<<<<<<<<<<<<<<<<


EndFunc   ;==>CloseThisWindow

I get back to the calling script with no problems now. :(

Note that the function names you were using are invalid - from the Help file: :D

"Function names must start with either a letter or an underscore, and the remainder of the name can contain any combination of letters and numbers and underscores"

M23

P.S. When you post code please use Code tags. Put [autoit ] before and [/autoit ] after your posted code (but omit the trailing space - it is only there so the tags display here). Or press the blue button just under the BOLD toolbar button. :D


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

@Melba23: thanks for your answer

Whats so novel on this code?

For the function-names:

In our company we have some naming-conventions and I'm only applying these rules also in this script (so it is the same as all out other coding)

I will keep in mind the info about the autoit-tags

Regards

Share this post


Link to post
Share on other sites

DenDuze,

I used the word "novel" because I would have expected the code you have put into an #include file to be a simple function within the main script. There is nothing wrong with doing it your way - it is just that I have not seen it before. :P

Why do you do it this way? Is it to reduce the size of the main script when editing? :x

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

You would really love the way Project Express is written then. It would drive you over the edge I'm afraid.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

George,

I think I am already over it - or at least it feels like that sometimes! :x

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I think I am already over it

M23

I concur

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

At least when wanting to kill Ecel 2007, "WinKill" works only if followed by "ProcessClose"

1 person likes this

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