MAXScript Tools and Interaction with 3ds Max > DotNet In MAXScript > DotNet Examples >

# Registering Windows SystemEvents Callbacks Using DotNet

The following example demonstrates how to register a MAXScript event handler which will react when Windows System settings are being changed.

CODE:
     --First we need the SystemEvents DotNet Class:
    c = dotNetClass "Microsoft.Win32.SystemEvents"
    dotNetClass:Microsoft.Win32.SystemEvents
    --Then we get a list of all available events:
    showevents c
    [static] DisplaySettingsChanged <System.Object>sender <System.EventArgs>e = ( ... )
    [static] DisplaySettingsChanging <System.Object>sender <System.EventArgs>e = ( ... )
    [static] EventsThreadShutdown <System.Object>sender <System.EventArgs>e = ( ... )
    [static] InstalledFontsChanged <System.Object>sender <System.EventArgs>e = ( ... )
    [static] LowMemory <System.Object>sender <System.EventArgs>e = ( ... )
    [static] PaletteChanged <System.Object>sender <System.EventArgs>e = ( ... )
    [static] PowerModeChanged <System.Object>sender <Microsoft.Win32.PowerModeChangedEventArgs>e = ( ... )
    [static] SessionEnded <System.Object>sender <Microsoft.Win32.SessionEndedEventArgs>e = ( ... )
    [static] SessionEnding <System.Object>sender <Microsoft.Win32.SessionEndingEventArgs>e = ( ... )
    [static] SessionSwitch <System.Object>sender <Microsoft.Win32.SessionSwitchEventArgs>e = ( ... )
    [static] TimeChanged <System.Object>sender <System.EventArgs>e = ( ... )
    [static] TimerElapsed <System.Object>sender <Microsoft.Win32.TimerElapsedEventArgs>e = ( ... )
    [static] UserPreferenceChanged <System.Object>sender <Microsoft.Win32.UserPreferenceChangedEventArgs>e = ( ... )
    [static] UserPreferenceChanging <System.Object>sender <Microsoft.Win32.UserPreferenceChangingEventArgs>e = ( ... )
    true
    --We define a global function to be called by the event handler:
    fn TimeChanged a1 a2 = format "TimeChanged callback: % : %\n" a1 a2
    TimeChanged()
    --Finally we add the Event Handler for the event "TimeChanged":
    dotnet.addeventhandler c "TimeChanged" TimeChanged
    OK

Now if you would open the Date and Time properties of MS Windows, change the seconds only (to avoid problems with your 3ds Max license, don't change the date too much!) and apply the changes, the MAXScript function we registered will be called and will print in the Listener:

    TimeChanged callback: dotNetObject:Microsoft.Win32.SystemEvents : dotNetObject:System.EventArgs

As you can see from the events list, one could register event handlers to be notified when display settings are being changed, the palette or fonts are changing and so on.

#### See Also

- DotNet In MAXScript