For those who may need to block Power and Sleep buttons from their programs :
The solution wiht low level keyboard hook does not work on XP SP2. instead this works :
Inside the window procedure, where you switch on message you need to handle the WM_POWERBROADCAST and return BROADCAST_QUERY_DENY to prevent system to be shut down on locked.
Code:
{
switch (message)
{
case WM_POWERBROADCAST:
{
int ret =1;
if ( wParam == PBT_APMQUERYSUSPEND || wParam == PBT_APMQUERYSTANDBY )
return BROADCAST_QUERY_DENY;
else
return TRUE;
}break;
............
}