Jump to content

Recommended Posts

Posted

zxcvbnm, Melba23,

WideBoyDixon has a deal for interprocess communication using subclassing. See his sig for example.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

  • Moderators
Posted

kylomas,

scripts with timers set "guiregistermsg(WM_CLOSE)" use "handle" from script issueing WM_CLOSE to exit each script

Thank you for that pointer - it might well be the solution. :x

zxcvbnm,

If we add a handler for WM_CLOSE to the timer pop-up script and use WinClose in another script to end it, the handler can close the timers for us - I have just checked to confirm. :P

Big question: you said earlier

now I have only a vbscript

Does that mean that the script you are using to close the timer is written in VB? If so, even though I have never used VB, I imagine there must be an equivalent command to WinClose in VB - so we need to confirm that it works in the same way. Compile and run this script, then use your VB script to close it and see if the MsgBox appears:

#include <WindowsConstants.au3>

GUICreate("Count Down", 100, 100)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_CLOSE, "WM_CLOSE")

While 1
    Sleep(10)
WEnd

Func WM_CLOSE()
    MsgBox(0, "Success", "The handler has intercepted the 'Close' call from the other script")
    Exit
EndFunc

It certainly appears when I use WinClose in another AutoIt script to close the GUI - let us hope that VB can close GUIs in the same way. :shifty:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

  • Moderators
Posted

zxcvbnm,

Glad we got there in the end. Come back if you run into any more problems. :x

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Posted

If we add a handler for WM_CLOSE to the timer pop-up script and use WinClose in another script to end it, the handler can close the timers for us - I have just checked to confirm. :x

Sorry but I'm new of autoit! It means that I have to add a handler on my script?

  • Moderators
Posted

zxcvbnm,

I have to add a handler on my script?

No, further experiment has shown that you can use an OnAutoItExitRegister function to intercept the closure. I would bet that this function is actually intercepting the same message, but it is easier to code for us. :shifty:

So steps to take now:

- 1. Add an OnAutoItExitRegister function to your timer pop-up script to close the _Timers on exit (very easy):

; At the top of your script add this line
OnAutoItExitRegister("_Kill_Timers")

; And then add this function somewhere in the script
Func _Kill_Timers()
    _Timer_KillAllTimers($Form1)
EndFunc

- 2. Test if you fire the OnExit function when you close the timer pop-up from your VB script - it might well be that you will get a similar response to the WinClose command sent by AutoIt. I would run the test by getting the _Kill_Timers function to fire an additional MsgBox so that you can see if it worked. If you do get the function to fire when your VB script closes the pop-up then you have solved the problem. :x

- 3. If the OnExit function does not fire, then you will have to rewrite your VB script into AutoIt and close the timer pop-up with WinClose. You said: "I wrote the second script in VB for convenience, but I can write in any language!" - so over to you to do it (although I am sure you will get help if you need it)! :nuke:

And then you can have your moveable flashing timer pop-up using _Timer_SetTimer with no worries about not closing the _Timers on exit. :P

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Posted

no good results

I lived on my timer also

[autoiit]

HotKeySet("{ESC}", "On_Exit")

_Timer_KillTimer($Form1, $iTimerProgress)

Func On_Exit()

_Timer_KillTimer($Form1, $iFlash_Timer)

Exit

EndFunc

[/autoit]

to try my vbs and exit with hot wey but msg box doesen't catch the exit

  • Moderators
Posted

zxcvbnm,

Your code as posted does not use OnAutoItExitRegister but HotKeySet. :x

Did you try with an OnAutoItExitRegister function as I showed in the post above? :P

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Posted

I leave also the code posted!

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=tm506.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Timers.au3>

; Set a HotKey to exit
HotKeySet("{ESC}", "On_Exit")

Global $iMin = 1, $iSec = 32, $iFlash = 0, $neg = 0

$Form1 = GUICreate("Count Down", 250, 70, 125, 125, BitOR($WS_DLGFRAME, $WS_POPUP), $WS_EX_TOPMOST)
GUISetBkColor(0x66FF00)

$Label = GUICtrlCreateLabel(StringFormat("%02d:%02d", $iMin, $iSec), 24, 02, 200, 70, -1, $GUI_WS_EX_PARENTDRAG)
;$Label = GUICtrlCreateLabel("", 24, 02, 200, 70, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 40, 800, 0, "verdana")
; At the top of your script add this line
OnAutoItExitRegister("_Kill_Timers")

GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "On_Exit")

;AutoItSetOption ( "TrayIconHide" ,1 )

; Start a timer for the countdown
$iTimerProgress = _Timer_SetTimer($Form1, 5, "_CountDown") ; Call once a sec
; Set a placeholder for the Flash timer
$iFlash_Timer = 9999

; Loop until you get to the correct value
Do
    Sleep(10)
Until $iMin = (-59) And $iSec = 59

; Kill the Progress Timer
_Timer_KillTimer($Form1, $iTimerProgress)

; Keep the scipt alive
While 1
    Sleep(10)
WEnd


; And then add this function somewhere in the script
Func _Kill_Timers()
    _Timer_KillAllTimers($Form1)
EndFunc


; When you exit, kill the Flash timer
Func On_Exit()
    _Timer_KillTimer($Form1, $iFlash_Timer)
    Exit
EndFunc
.
.
  • Moderators
Posted

zxcvbnm,

If the the OnAutoItExitRegister method does not work for you then let us try the handler route: :x

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=tm506.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Timers.au3>

Global $iMin = 1, $iSec = 32, $iFlash = 0, $neg = 0

$Form1 = GUICreate("Count Down", 250, 70, 125, 125, BitOR($WS_DLGFRAME, $WS_POPUP), $WS_EX_TOPMOST)
GUISetBkColor(0x66FF00)

$Label = GUICtrlCreateLabel(StringFormat("%02d:%02d", $iMin, $iSec), 24, 02, 200, 70, -1, $GUI_WS_EX_PARENTDRAG)
;$Label = GUICtrlCreateLabel("", 24, 02, 200, 70, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 40, 800, 0, "verdana")

GUISetState(@SW_SHOW)

; Set up the intercept of the WM_CLOSE message
GUIRegisterMsg($WM_CLOSE, "WM_CLOSE")

;AutoItSetOption ( "TrayIconHide" ,1 )

; Start a timer for the countdown
$iTimerProgress = _Timer_SetTimer($Form1, 5, "_CountDown") ; Call once a sec
; Set a placeholder for the Flash timer
$iFlash_Timer = 9999

; Loop until you get to the correct value
Do
    Sleep(10)
Until $iMin = (-59) And $iSec = 59

; Kill the Progress Timer
_Timer_KillTimer($Form1, $iTimerProgress)

; Keep the scipt alive
While 1
    Sleep(10)
WEnd

; this runs when the message is intercepted
Func WM_CLOSE()
    _Timer_KillTimer($Form1, $iFlash_Timer)
    MsgBox(0, "Success", "The handler has intercepted the 'Close' call from the other script")
    Exit
EndFunc

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

  • Moderators
Posted

zxcvbnm,

First just to prove it will work for you in AutoIt, compile and run the script I gave you above and then run this simple script from SciTE:

WinClose("Count Down")

You should see the MsgBox appear - I certainly do. :x

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Posted

Yessss!!!

Sorry...now just two question...what about repentine shut down of pc before closing whit second script?

the first script is launched from a program, each time the program returns this error: DD Host failed to execute (The DDC server cannot be launched)

Any idea?

  • Moderators
Posted

zxcvbnm,

repentine shut down

I have no idea what you mean by "repentine"! :x If you perhaps mean the whole machine closing down unexpectedly, then there is no problem. :P

error: DD Host failed to execute (The DDC server cannot be launched)

No idea, I am afraid. I would start a new topic. :shifty:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Posted

I have no idea what you mean by "repentine"! :) If you perhaps mean the whole machine closing down unexpectedly, then there is no problem. ;)

Yes it is!

  • 3 weeks later...
Posted

The timer application and the closer are called by a server running in remotely.

The timer application starts, but the closer fails to intercept the window, it works only when run locally on computer (launch with double click!).

Can I create an executable that controls the execution of the in timer task manager so I shut down and also simultaneously closes the timer (_Timer_KillAllTimers)?

Thanks

Posted

now I'm using an autoit app to close my "timer app"

this is the code

RegWrite("HKEY_CURRENT_USER", "Count", "REG_SZ","3")

in this way i'm sure to close all timer i'm using,

this is the code of "timer app":

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=tm506.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Timers.au3> 
Global $iMin = 1, $iSec = 32, $iFlash = 0, $neg = 0
Global Const $DW = @DesktopWidth
Global Const $DH = @DesktopHeight
$Form1 = GUICreate("Count Down", 250, 70, $DW-280, 125, BitOR($WS_DLGFRAME, $WS_POPUP), $WS_EX_TOPMOST)
GUISetBkColor(0x66FF00)$Label = GUICtrlCreateLabel(StringFormat("%02d:%02d", $iMin, $iSec), 24, 02, 200, 70, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 40, 800, 0, "verdana")GUISetState(@SW_SHOW)$test = RegWrite("HKEY_CURRENT_USER", "Count", "REG_SZ","2")
;AutoItSetOption ( "TrayIconHide" ,1 ); Start a timer for the countdown
$iTimerProgress = _Timer_SetTimer($Form1, 5, "_CountDown") ; Call once a sec
; Set a placeholder for the Flash timer
$iFlash_Timer = 9999 ; Loop until you get to the correct value
Do
    Sleep(10)
    $test = RegRead("HKEY_CURRENT_USER","Count")
    if $test <> 2 then
_Timer_KillAllTimers($Form1)
Exit
    endif
Until $iMin = (-59) And $iSec = 59; Kill the Progress Timer
_Timer_KillTimer($Form1, $iTimerProgress); Keep the scipt alive
While 1
Sleep(10)
    $test = RegRead("HKEY_CURRENT_USER","Count")
    if $test <> 2 then
_Timer_KillTimer($Form1, $iFlash_Timer)
Exit
    endif
Wend 
Func _CountDown($a, $b, $c, $d) ; You must have 4 parameters here, even though they do nothing!
    ; We call it once a sec, so just reduce by 1 sec each time
    If $iMin > 0 Then
        $iSec -= 1
        If $iSec < 0 Then
            $iSec = 59
            $iMin -= 1
        EndIf
        GUICtrlSetData($Label, StringFormat("%02d:%02d", $iMin, $iSec))
    ElseIf $iMin = 0 And $neg = 0 Then
        $iSec -= 1
        If $iSec = 0 Then
            $neg = 1
        EndIf
        GUICtrlSetData($Label, StringFormat("%02d:%02d", $iMin, $iSec))
    ElseIf $iMin = 0 And $neg = 1 Then
        $iSec += 1
        GUICtrlSetData($Label, StringFormat("-" & "%02d:%02d", $iMin, $iSec))
        If $iSec > 59 Then
            $iSec = 0
            $iMin -= 1
            GUICtrlSetData($Label, StringFormat("%03d:%02d", $iMin, $iSec))
        EndIf
    ElseIf $iMin < 0 And $neg = 1 Then
        $iSec += 1
        If $iSec > 59 Then
            $iSec = 0
            $iMin -= 1
        EndIf
        GUICtrlSetData($Label, StringFormat("%03d:%02d", $iMin, $iSec))
    EndIf
    If $iMin = 2 And $iSec = 30 Then
        GUISetBkColor(0xFFFF00)
    EndIf
    If $iMin = 0 And $iSec = 30 Then
        GUISetBkColor(0xFF0000)
    EndIf
    If $iMin = 0 And $iSec = 0 Then
        $iFlash_Timer = _Timer_SetTimer($Form1, 50, "_Flash") ; Start a second timer to flash
    EndIfEndFunc   ;==>_CountDown
Func _Flash($a, $b, $c, $d) ; You must have 4 parameters here, even though they do nothing!
    $iFlash = Not $iFlash
    If $iFlash Then
        GUICtrlSetColor($Label, 0xFF0000)
        Return
    EndIf
    GUICtrlSetColor($Label, 0x000000)
EndFunc   ;==>_Flash

I don't know about closing app by task manager, can I stop all timer?

thanks

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
×
×
  • Create New...