(Type your message here)
--------------------------------
From: anijith m
Instead of using SystemEvents.PowerModeChanged delegate override WndProc.This is working fine for me
const int BROADCAST_QUERY_DENY = 0x424D5144; // Return this value to deny a query.
const int WM_POWERBROADCAST = 0x0218;
const int PBT_APMQUERYSUSPEND=0x0000;
protected override void WndProc(ref Message message)
{
base.WndProc(ref message);
if (message.Msg == WM_POWERBROADCAST )
{
switch(message.WParam.ToInt32())
{
case PBT_APMQUERYSUSPEND:
if( message.LParam.ToInt32() == 0x1)
{
DialogResult res = MessageBox.Show("Go to Standby ?","Standby",MessageBoxButtons.YesNo,MessageBoxIco n.Question );
if( res == DialogResult.No)
{
IntPtr deny = new IntPtr(BROADCAST_QUERY_DENY);
message.Result = deny;
}
else
message.Result = (IntPtr)1;
}
else
{
IntPtr deny = new IntPtr(BROADCAST_QUERY_DENY);
message.Result = deny;
}
break;
}
}
}
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>hbl3x343BUa/qSsdlgvpfQ==</Id>