Jump to content

How can I close this script from another script?


timmy2
 Share

Recommended Posts

@timmy2: in your code from post#1 you forgot to add

AutoItSetOption("GUIOnEventMode", 1)

because your code runs in GUIOnEventMode! Just add the line to the top of your code just after the includes.

Best, add both lines:

AutoItSetOption("GUIOnEventMode", 1)
OnAutoItExitRegister("_VisualizerExit")

The disadvantage of the idea in post#12 is that you can also exit the visualization by pressing ESC key.

 

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

_WinAPI_EnumProcessWindows()

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

@timmy2: in your code from post#1 you forgot to add

AutoItSetOption("GUIOnEventMode", 1)

because your code runs in GUIOnEventMode! Just add the line to the top of your code just after the includes.

Best, add both lines:

AutoItSetOption("GUIOnEventMode", 1)
OnAutoItExitRegister("_VisualizerExit")

The disadvantage of the idea in post#12 is that you can also exit the visualization by pressing ESC key.

 

Br,

UEZ

 

Thank you for your continued help, UEZ.  Any references to GuiOnEventMode were left over from testing the FFT visualizer manually. I've removed all references to it.

One thing you did not verify and I'd appreciate it if you would is: should I insert your recommended "If GUIGetMsg() = -3" in the FFT Visualizer While/WEnd loop like this?

While _BASS_ChannelIsActive($hStream)

    If GUIGetMsg() = -3 Then _VisualizerExit()

    _GDIPlus_GraphicsDrawImage($hGfxBuffer, $hBmpBk, 0, 0)

    _BASS_EXT_ChannelGetFFT($hStream, $aFFT, 6)
    If Not @error Then DllCall($ghGDIPDll, "int", "GdipFillPolygonI", "handle", $hGfxBuffer, "handle", $hBrushFFT, "ptr", $aFFT[0], "int", $aFFT[1], "int", "FillModeAlternate")

    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Sleep(30)
WEnd
Link to comment
Share on other sites

What you can do is to start the script from the main script and close it with WinClose() when ever you want.

Prerequisite is that the child process is closeable with WinClose -> GUIGetMsg() = $GUI_EVENT_CLOSE.

Further on child script you have to use OnAutoItExitRegister() to cleanup resouces on exit.

Example:

Main.au3

#include  <WinAPIProc.au3>
#include <Array.au3>

$iPid = Run("Child.exe")
Local $aData = _WinAPI_EnumProcessWindows($iPid, 0)
ConsoleWrite($aData[1][0] & @LF)
Sleep(2000)
WinClose($aData[1][0])
Child.au3

#NoTrayIcon
OnAutoItExitRegister("_Exit")
$hGUI = GUICreate("Test")
GUISetState()

Do
    If GUIGetMsg() = -3 Then _Exit()
Until Not Sleep(1000)

Func _Exit()
    MsgBox(0, "Information", "Exit", 10)
    Exit
EndFunc
Compile Child.au3 and start Main.au3. Both should be in same dir.

 

 

_WinAPI_EnumProcessWindows requires beta version.

 

 

Br,

UEZ

 

 

UEZ, I was curious to test your basic examples of using WinClose. I modified the Main script to use the WinAPIEx UDF because I'm not using the Beta AutoIt.

When I run the Main script there's a long delay between the Main program's WinClose and the Child program actually closing -- at least on my PC.  Also, the MsgBox that indicates the Child program is exiting needs to be clicked twice to close.  Can you explain these behaviors to me, please?

 

"MAIN" script

#Include <WinAPIEx.au3>
#include <Array.au3>

$iPid = Run("Child.exe")
Local $aData = _WinAPI_EnumProcessWindows($iPid, 0)

ConsoleWrite($aData[1][0] & @LF) ; show the handle, but how do I know if it's correct?

sleep(1000)  ;leave Child window alone for 2 seconds before winmove

WinMove($aData[1][0],"", 20,20)  ;visible test to see if handle is valid

Sleep(1000) ;

$result = WinClose($aData[1][0])

ConsoleWrite ("Result of WinClose = " & $result & @LF)


Exit

"CHILD" script

#NoTrayIcon
OnAutoItExitRegister("_Exit")
$hGUI = GUICreate("Child")
GUISetState()

Do
    If GUIGetMsg() = -3 Then
        ToolTip("Trigger received !") ;so I can see when Child.exe is told to close
        sleep (2000)
        _Exit()
    EndIf
Until Not Sleep(1000)

Func _Exit()
    MsgBox(0, "Information", "Exit")
    Exit
EndFunc

I apologize if this is a dumb question.

Edited by timmy2
Link to comment
Share on other sites

The reason why it has to closed twice is that the _Exit() function is called twice. One within the If Then check and the second caused by OnAutoItExitRegister().

In this case you can disable OnAutoItExitRegister().

Regading the delay I cannot say anything.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

The reason why it has to closed twice is that the _Exit() function is called twice. One within the If Then check and the second caused by OnAutoItExitRegister().

In this case you can disable OnAutoItExitRegister().

Regading the delay I cannot say anything.

Br,

UEZ

 

Ah, then perhaps I'm back at the beginning: Would OnAutoItExitRegister() be effective if the Main program had gotten the PID when Running Child.exe and then issued a ProcessClose(Child's PID)?

The delay caught my attention because it made me wonder if your suggested approach (WinClose in combination with GUIGetMsg) is a reliable air-tight solution (not to dis it, but all things must be tested, especially by toddlers and noobs).

Link to comment
Share on other sites

ProcessClose() is the hard way to close the script and OnAutoItExitRegister will not work in this.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

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