packages/Windows API Code Pack 1.1/source/WindowsAPICodePack/Core/PowerManagement/MessageManager.cs
/// <summary>
/// This method is called when a Windows message 
/// is sent to this window.
/// The method calls the registered event handlers.
/// </summary>
This method is called when a Windows message
is sent to this window.
The method calls the registered event handlers.
This method is called when a Windows message is sent to this window . The method calls the registered event handlers .
protected override void WndProc(ref Message m)
            {
                if (m.Msg == PowerManagementNativeMethods.PowerBroadcastMessage && 
                    (int)m.WParam == PowerManagementNativeMethods.PowerSettingChangeMessage)
                {
                    PowerManagementNativeMethods.PowerBroadcastSetting ps =
                         (PowerManagementNativeMethods.PowerBroadcastSetting)Marshal.PtrToStructure(
                             m.LParam, typeof(PowerManagementNativeMethods.PowerBroadcastSetting));
                    IntPtr pData = new IntPtr(m.LParam.ToInt64() + Marshal.SizeOf(ps));
                    Guid currentEvent = ps.PowerSetting;
                    if (ps.PowerSetting == EventManager.MonitorPowerStatus &&
                        ps.DataLength == Marshal.SizeOf(typeof(Int32)))
                    {
                        Int32 monitorStatus = (Int32)Marshal.PtrToStructure(pData, typeof(Int32));
                        PowerManager.IsMonitorOn = monitorStatus != 0;
                        EventManager.monitorOnReset.Set();
                    }
                    if (!EventManager.IsMessageCaught(currentEvent))
                    {
                        ExecuteEvents((ArrayList)eventList[currentEvent]);
                    }
                }
                else
                    base.WndProc(ref m);
            }
protected override void WndProc ( ref Message m ) { if ( m . Msg == PowerManagementNativeMethods . PowerBroadcastMessage && ( int ) m . WParam == PowerManagementNativeMethods . PowerSettingChangeMessage ) { PowerManagementNativeMethods . PowerBroadcastSetting ps = ( PowerManagementNativeMethods . PowerBroadcastSetting ) Marshal . PtrToStructure ( m . LParam , typeof ( PowerManagementNativeMethods . PowerBroadcastSetting ) ) ; IntPtr pData = new IntPtr ( m . LParam . ToInt64 ( ) + Marshal . SizeOf ( ps ) ) ; Guid currentEvent = ps . PowerSetting ; if ( ps . PowerSetting == EventManager . MonitorPowerStatus && ps . DataLength == Marshal . SizeOf ( typeof ( Int32 ) ) ) { Int32 monitorStatus = ( Int32 ) Marshal . PtrToStructure ( pData , typeof ( Int32 ) ) ; PowerManager . IsMonitorOn = monitorStatus != 0 ; EventManager . monitorOnReset . Set ( ) ; } if ( ! EventManager . IsMessageCaught ( currentEvent ) ) { ExecuteEvents ( ( ArrayList ) eventList [ currentEvent ] ) ; } } else base . WndProc ( ref m ) ; }
This method is called when a Windows message
is sent to this window.
This method is called when a Windows message is sent to this window .
// Make sure it is a Power Management message. // IsMonitorOn
Message
ref