none
How to write new setting to current active power plan and take effect?

    Question

  • Hi

    Currently I am working on a new laptop power management program on vista. Write new setting value to active power plan is OK. But it doesn't take effect until user change to another power plan and then change back. Is there anyone has some ideas about this problem?  Thanks.

    Following is my code. I wrote it in C++ :

    GUID *pPwrGUID;
    GUID subGUID = GUID_VIDEO_SUBGROUP;
    GUID BriGUID = GUID_VIDEO_BRIGHTNESS;

    PowerGetActiveScheme(NULL, &pPwrGUID);

    // ...Get new LCD brightness level by user input and save it to dwLevel;

    if (PowerSource())
    { // AC Power
    PowerWriteACValueIndex(NULL, pPwrGUID, &subGUID, &BriGUID, dwLevel);
    }
    else
    { // DC Power
    PowerWriteDCValueIndex(NULL, pPwrGUID, &subGUID, &BriGUID, dwLevel);
    }

    PowerSetActiveScheme(NULL, pPwrGUID); // It seems not working.



    Monday, May 28, 2007 3:24 AM

Answers

  • Hi ZhChin,

     

    Your code looks fine to me.

     

    You should check and see if the laptop you are testing on supports brightness control in power policy natively.  You should look and make sure that in Windows mobility center, there is a brightness tile, which allows you to change the display brightness in real-time.

     

    If there is not a brightness tile in mobility center, then brightness control on the system is implemented in some proprietary method, which may not work well with your code. 

     

    If there is a brightness tile in mobility center, then your code should work fine as is.  You might try setting the value for both AC and DC power sources at the same time--just in case there is some issue with your PowerSource() routine.

     

    Hope that helps,

    --Pat

    Tuesday, June 05, 2007 8:11 PM

All replies

  • Hi ZhChin,

     

    Your code looks fine to me.

     

    You should check and see if the laptop you are testing on supports brightness control in power policy natively.  You should look and make sure that in Windows mobility center, there is a brightness tile, which allows you to change the display brightness in real-time.

     

    If there is not a brightness tile in mobility center, then brightness control on the system is implemented in some proprietary method, which may not work well with your code. 

     

    If there is a brightness tile in mobility center, then your code should work fine as is.  You might try setting the value for both AC and DC power sources at the same time--just in case there is some issue with your PowerSource() routine.

     

    Hope that helps,

    --Pat

    Tuesday, June 05, 2007 8:11 PM
  • This thread helped me really. Thanks a lot first.

    I have a question. How can I get the name of the active power plan and set the name for the new power scheme, i.e., if I have "Balanced" as my current plan, how can I get the string "Balanced". And if I am duplicating the current active scheme and creating a new plan based on this, how can I set it to some name like "New plan". Seems like friendly name working, but this doesn't show up in Control Panel/Power Options. When I duplicated the "Balanced" power scheme and created my own "newPlan", it still shows up as "Balanced" in the control panel, though the API, PowerReadFriendlyName returns "newPlan".

    Please guide me.

    Thanks a lot!
    sanav

    PS:
    1)Sorry for posting it in the same thread. I didn't find any related thread and this thread seemed to me to be the proper one to post this query.
    2) Pat, I have gone through a lot of your PPTs and they are really good. Special thanks for that.
    Thanks.
    Thursday, July 26, 2007 1:04 PM