PDA

View Full Version : Events Library


sside
03-03-2007, 04:08 PM
Events library (Events.dll v.1.0.0.0) lets you get notifications for different system events. In order to get notifications for an event you must subscribe to that particular event.

The following events are supported:

DisplaySettingsChanging,
DisplaySettingsChanged,
InstalledFontsChanged,
LowMemory,
PaletteChanged,
PowerModeChanged,
SessionSwitch,
SessionEnding,
SessionEnded,
TimeChanged,
UserPreferenceChanging,
UserPreferenceChanged

I plan to add more events in the future.


Actions:

Events.Subscribe
Events.Unsubscribe
Events.GetEventData
Events.GetEventCount
Events.GetError

Always unsubscribe from the events where you are subscribed when you're done.

Download Events.v.1.0.0.0 (http://ams5.ssideproject.com/downloads/Events.v.1.0.0.0.rar).

Contents:
1.Events.xml // Actions. Drop this to actions folder. C:\Program Files\AutoPlay Media Studio 5.0 Professional\Data\Actions.
2.Events.Blank.Project.apt // Template project. Drop this to template folder. C:\Program Files\AutoPlay Media Studio 5.0 Professional\Templates.
3.Events.Demo.apz // A very basic demo project to see what it does.


.Net 2.0 required.

With Kind Regards
sside

sside
03-04-2007, 02:04 PM
Added:
Events.GetCancelSessionEnding
Events.SetCancelSessionEnding

If you are subscribed to SessionEnding event, it will fire before user logs off or shuts down computer.
Events.GetCancelSessionEnding gets a value (true or false) whether to prevent user from logging off or shutting down the computer or not. Default is false.
Events.SetCancelSessionEnding sets a value (true or false) whether to prevent user from logging off or shutting down the computer or not. If set to true user cannot logoff or shutdown the computer.

Events.SetCancelSessionEnding(true);

This can be handy if you want to save application settings or execute some script before logging off or shutting down.


Example:

Page OnShow (or whatever):


Events.Subscribe(EventType.SessionEnding);
Events.SetCancelSessionEnding(true);
Page.StartTimer(100);



Page OnTimer:


eventData = Events.GetEventData();
if (eventData.EventType == "SessionEnding") then
--Page.StopTimer(); --You can stop timer here.
--Do whatever you want to do. Computer won't logoff or shutdown.
if (eventData.EventInfo == "Logoff") then
--Logoff computer.
elseif (eventData.EventInfo == "SystemShutdown") then
--Shutdown computer.
end
end



You can log off or shutdown the computer by using shutdown.exe (system32 dir). These are command line arguments:


Usage: shutdown [-i | -l | -s | -r | -a] [-f] [-m \\computername] [-t xx] [-c "comment"] [-d up:xx:yy]
No args Display this message (same as -?)
-i Display GUI interface, must be the first option
-l Log off (cannot be used with -m option)
-s Shutdown the computer
-r Shutdown and restart the computer
-a Abort a system shutdown
-m \\computername Remote computer to shutdown/restart/abort
-t xx Set timeout for shutdown to xx seconds
-c "comment" Shutdown comment (maximum of 127 characters)
-f Forces running applications to close without warning
-d [u][p]:xx:yy The reason code for the shutdown
u is the user code
p is a planned shutdown code
xx is the major reason code (positive integer less than 256)
yy is the minor reason code (positive integer less than 65536)


You can use WinCmd.dll to execute commands:
http://indigorose.com/forums/showthread.php?t=17040&highlight=WinCmd.dll

Download:
Events.v.1.0.0.1 (http://ams5.ssideproject.com/downloads/Events.v.1.0.0.1.rar).

Contents:
1.Events.xml // Actions. Drop this to actions folder. C:\Program Files\AutoPlay Media Studio 5.0 Professional\Data\Actions.
2.Events.Blank.Project.apt // Template project. Drop this to template folder. C:\Program Files\AutoPlay Media Studio 5.0 Professional\Templates.
3.Events.Demo.Project.apz // A very basic demo project to see what it does.


Note:
Events.GetEventData() returns an EventData table. EventData.EventType (always) describes which event was fired. EventData.EventInfo (not always, depends on the EventType) has some additional info about the event that was fired. For more info about these values see project globals as the code is well commented.


.Net 2.0 required.

With Kind Regards
sside

sside
03-04-2007, 04:11 PM
Before you logoff or shut down the computer you should do one of two things:

Events.SetCancelSessionEnding(false);

or

Events.Unsubscribe(EventType.SessionEnding);

or computer won't logoff/shutdown.


So this:


Page OnTimer:


eventData = Events.GetEventData();
if (eventData.EventType == "SessionEnding") then
--Page.StopTimer(); --You can stop timer here.
--Do whatever you want to do. Computer won't logoff or shutdown.
if (eventData.EventInfo == "Logoff") then
--Logoff computer.
elseif (eventData.EventInfo == "SystemShutdown") then
--Shutdown computer.
end
end



should be:


Page OnTimer:


eventData = Events.GetEventData();
if (eventData.EventType == "SessionEnding") then
--Page.StopTimer(); --You can stop timer here.
--Events.SetCancelSessionEnding(false); --or
--Events.Unsubscribe(EventType.SessionEnding); --this is better as computer will log off or shutdown anyway.
--Take your time and do whatever you want to do here as computer won't logoff or shutdown.
if (eventData.EventInfo == "Logoff") then
--Logoff computer.
elseif (eventData.EventInfo == "SystemShutdown") then
--Shutdown computer.
end
end




With Kind Regards
sside

SiNisTer
07-12-2007, 07:18 AM
Hello sside,
Hope you wont mind reuploading these 'gems'. The links are dead.
BTW, I really should visit this section of the forum too. Its a gold mine of great dlls by you. Thanks for the unselfish giving.

Thank You.

sside
07-12-2007, 10:36 AM
http://indigorose.com/forums/showthread.php?t=20220&highlight=Events.v.1.0.0.1
http://indigorose.com/forums/showthread.php?t=20221&highlight=Events.v.1.0.0.1

With Kind Regards
sside

SiNisTer
07-13-2007, 08:02 AM
Thanks again for taking time to reupload and share these Dlls...