my development system is a notebook, powered by 32-bit Vista Home Premium OS.
i am trying to programmatically change the sleep button's behavior. I am pretty sure to use WriteGlobalPwrPolicy for this; but i am experiencing some difficulties.
First, let me start with variables:
GLOBAL_POWER_POLICY powPol;
// i want to save button's initial behavior. so, these two variables needed.
POWER_ACTION acSleep,
dcSleep;
Now, to the action.
...
if(!ReadGlobalPwrPolicy(&powPol))
return -1;
// save initial behavior
acSleep = powPol.user.SleepButtonAc.Action;
dcSleep = powPol.user.SleepButtonDc.Action;
// assign new behaviors: do nothing
powPol.user.SleepButtonAc.Action = PowerActionNone;
powPol.user.SleepButtonDc.Action = PowerActionNone;
// modifications are complete. Now it is time to write back
bool bRet = WriteGlobalPwrPolicy(&powPol);
DWORD dwErr = GetLastError();
...
Watch window shows : bRet = true and dwErr = 0.
When I execute this code, I do not see the behavior of the button is changed. Neither by practice nor from Power Options window.
Maybe I should provide some values for Flags and EventCode members; but i cannot make anything out of it.
Currently i am stuck on it and desperately in need of help.