Jump to content

Onexitfunc Problem


Recommended Posts

  • Moderators

Why does this work correctly:

Test()

Func Test($a=0)
    
    If $a == 0 Then MsgBox(0, "", "This does work!")
    
EndFunc

But this does not:

Opt("OnExitFunc", "Test")

Sleep(2000)

Func Test($a=0)
    
    If $a == 0 Then MsgBox(0, "", "This doesn't work!")
    
EndFunc
Link to comment
Share on other sites

  • Developers

I understand that, but if the parameter is set within the function should it not work?

If no parameters are processed then $a isn't initialised and thus will error out...

You can test this by added a Global $a = 0 statement. You will see that the error disapears.

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

  • Moderators

If no parameters are processed then $a isn't initialised and thus will error out...

You can test this by added a Global $a = 0 statement. You will see that the error disapears.

This somewhat limits your abilities when using the on exit function.
Link to comment
Share on other sites

  • Moderators

This somewhat limits your abilities when using the on exit function.

I just send it to another function... and set my parameters that way.

Edit:

If I remember correctly, Call() used to be this way also but since has changed...

Anyway, this is what I meant before the edit:

Opt('OnExitFunc', 'SetParams')

Func SetParams()
    If 1 + 1 = 2 Then Test(2)
EndFunc

Func Test($a = 0)
    MsgBox(0, '', $a)
EndFunc
Edited by SmOke_N

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.

Link to comment
Share on other sites

as i understand this

OnExitFunc Sets the name of the function called when AutoIt exits (default is OnAutoItExit).

it makes sure that this function is ran when autoit exits

here is a good example of its use... by greenmachine

#include <GUIConstants.au3>

$MagWidth = InputBox ("Magnify Area", "What should the WIDTH of the magnified area be?")
$MagHeight = InputBox ("Magnify Area", "What should the HEIGHT of the magnified area be?")
$MagZoom = InputBox ("Magnify Area", "What should the ZOOM of the magnified area be?", 2)

Global $SRCCOPY = 0x00CC0020
Global $dll[3], $DeskHDC, $GUIHDC

$dll[1] = DllOpen ( "user32.dll")
$dll[2] = DllOpen ( "gdi32.dll")

Global $GUI = GUICreate ("Zoom x2 Au3", $MagWidth * $MagZoom, $MagHeight * $MagZoom, _
    MouseGetPos (0), MouseGetPos (1), $WS_POPUP+$WS_BORDER, $WS_EX_TOPMOST)

GUISetState(@SW_SHOW)

Global $LastPos[2] = [0,0]

While 1
    MAG()
    $MousePos = MouseGetPos()
    If ($LastPos[0] <> $MousePos[0] Or $LastPos[1] <> $MousePos[1]) Then
        WinMove("Zoom x2 Au3", "", $MousePos[0] + $MagWidth/2 + 5, $MousePos[1])
        $LastPos[0] = $MousePos[0]
        $LastPos[1] = $MousePos[1]
    EndIf
    
    Sleep(10)
WEnd

Func MAG()
    $DeskHDC = DLLCall("user32.dll","int","GetDC","hwnd",0)
    $GUIHDC = DLLCall("user32.dll","int","GetDC","hwnd",$GUI)
    If Not @error Then
        DLLCall("gdi32.dll", "int", "StretchBlt", "int", $GUIHDC[0], "int", _
            0, "int", 0, "int", $MagWidth * $MagZoom, "int", $MagHeight * $MagZoom, "int", $DeskHDC[0], "int", _
            MouseGetPos (0) - $MagWidth/2, "int", MouseGetPos (1) - $MagHeight/2, "int", $MagWidth ,"int", $MagHeight, _
            "long", $SRCCOPY)
        DLLCall("user32.dll","int","ReleaseDC","int",$DeskHDC[0],"hwnd",0)
        DLLCall("user32.dll","int","ReleaseDC","int",$GUIHDC[0],"hwnd",$GUI)
    EndIf
EndFunc

Func OnAutoItExit()
    DllClose ( $dll[1] )
    DllClose ( $dll[2] )
EndFunc

8)

NEWHeader1.png

Link to comment
Share on other sites

You could do this:

Exit(1)

Func OnAutoItExit ( )

Msgbox(0,"The Exit Codes was:",@ExitCode)

EndFunc

Is that more like what you were looking for?

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

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