What is an event? In my opinion, the event is like an alarm clock on our mobile phone. When the alarm clock rings, we have to do some specific things. In this case, an event is like an alarm. When a special event occurs while the program is running, the event itself is a message, if you write a script to process events, you need a special process or function to accept and process events. This special process or function is constantly monitored when the program is running to check whether the system has received the corresponding event. Once the event is received, the script responds to the event.
So where did the event come from? Do we need to write events in the script? Under normal circumstances, an event is triggered by a special State in which a program is running. We do not need to write events, but only need to write functions to process events. For example, if we use vbs to create an IE instance, when the IE window is closed, an event called onquit will be triggered.
Does the script naturally accept and process the event? We cannot. When creating an object, we will use the Createobject command of wsh, for example:
Set objie = wscript. Createobject ("internetexplorer. Application", "event _")
Have you noticed? What is the role of an additional parameter? It is called the event receiving end. When the object connected by the script contains an event, if the event called by the object is onbegin, wsh will call an event_onbegin event processing program in the script. Of course, the event receiver is not fixed. if the object is defined as myobj _, the event handler will be myobj_onbegin.
Familiar? In the personalized QQ lecture, the window_onsize (CX, CY) function has appeared. It is actually an event processing program.
Let's take a complete example to see the event handling process:
Set objie = wscript. Createobject ("internetexplorer. Application", "Event _")
Objie. Visible = true
Msgbox "Close the browser window to see the effect! ", Vbsystemmodal
Wscript. Sleep 6000
Msgbox "Disabled now"
Sub event_onquit ()
Msgbox "are you sure you want to close the browser? ", Vbsystemmodal
End sub
This script opens an IE window and asks you to close the IE window. When you close the window, the Event Response Program is automatically called.