Windows Programming using C++

Discussion in 'C++' started by HK, Sep 30, 2006.

  1. HK

    HK Guest

    I need to wirte a program that will display the degration of a battery
    as it's nature
    of reducing its effective capacity during continous charging and
    discharging cycles. I looked at Microsoft website and I was able to
    locate this API called "CallNtPowerInformation". This will be very
    helpful. However, I have not done any windows programming before. Can
    someone recommend a book on that. Do i need to need to create a Win32
    app for that matter.

    Thanks
     
    HK, Sep 30, 2006
    #1
    1. Advertising

  2. HK

    Moonlit Guest

    "HK" <> wrote in message
    news:...
    >I need to wirte a program that will display the degration of a battery
    > as it's nature
    > of reducing its effective capacity during continous charging and
    > discharging cycles. I looked at Microsoft website and I was able to
    > locate this API called "CallNtPowerInformation". This will be very
    > helpful. However, I have not done any windows programming before. Can
    > someone recommend a book on that.

    Charles Petzold has written some excellent books on windows programming.

    Do i need to need to create a Win32

    > app for that matter.

    Yes, in visual C++ just select a Win32 application (if you do simple stuff)
    or create a dialog based application. The dialog based consist of a single
    dialog and you can add images controls like buttons etc in the dialog editor
    (i.e. the visual part of Visual C++ :) )
    The Win32 app is a simple app with window and client area.

    >
    > Thanks
    >

    Regards, Ron AF Greve

    http://moonlit.xs4all.nl
     
    Moonlit, Sep 30, 2006
    #2
    1. Advertising

  3. HK

    HK Guest

    So I was able to find this WinAPI function:

    NTSTATUS CallNtPowerInformation(
    POWER_INFORMATION_LEVEL InformationLevel,
    PVOID lpInputBuffer,
    ULONG nInputBufferSize,
    PVOID lpOutputBuffer,
    ULONG nOutputBufferSize
    );

    By setting Informationlevel to SystemBatteryState, The lpOutputBuffer
    buffer receives a SYSTEM_BATTERY_STATE structure containing information
    about the current system battery.

    I was to compile the program and link it successfully; however when i
    print the members of the structure I am not getting anything. Here is
    the code:

    #include <windows.h>
    #include <powrprof.h>
    #include <WinDef.h>


    void main()
    {
    NTSTATUS power_information;
    SYSTEM_BATTERY_STATE sys_bat_state;



    power_information = CallNtPowerInformation(SystemBatteryState, NULL, 0,
    &sys_bat_state, sizeof(sys_bat_state));



    printf("BatteryPresent: \n", sys_bat_state.BatteryPresent);
    printf("Charging: \n", sys_bat_state.Charging);
    printf("Discharging: \n", sys_bat_state.Discharging);
    printf("Maxcapacity: \n", sys_bat_state.MaxCapacity);
    printf("RemainingCapacity: \n", sys_bat_state.RemainingCapacity);
    printf("Rate: \n", sys_bat_state.Rate);


    system("PAUSE");

    }

    I did link the libpowrprof.a already.

    Any ideas?

    Thanks


    Moonlit wrote:
    > "HK" <> wrote in message
    > news:...
    > >I need to wirte a program that will display the degration of a battery
    > > as it's nature
    > > of reducing its effective capacity during continous charging and
    > > discharging cycles. I looked at Microsoft website and I was able to
    > > locate this API called "CallNtPowerInformation". This will be very
    > > helpful. However, I have not done any windows programming before. Can
    > > someone recommend a book on that.

    > Charles Petzold has written some excellent books on windows programming.
    >
    > Do i need to need to create a Win32
    >
    > > app for that matter.

    > Yes, in visual C++ just select a Win32 application (if you do simple stuff)
    > or create a dialog based application. The dialog based consist of a single
    > dialog and you can add images controls like buttons etc in the dialog editor
    > (i.e. the visual part of Visual C++ :) )
    > The Win32 app is a simple app with window and client area.
    >
    > >
    > > Thanks
    > >

    > Regards, Ron AF Greve
    >
    > http://moonlit.xs4all.nl
     
    HK, Oct 12, 2006
    #3
  4. HK

    red floyd Guest

    red floyd, Oct 12, 2006
    #4
  5. HK wrote:
    > void main()
    > {
    > NTSTATUS power_information;
    > SYSTEM_BATTERY_STATE sys_bat_state;
    >
    >
    >
    > power_information = CallNtPowerInformation(SystemBatteryState, NULL, 0,
    > &sys_bat_state, sizeof(sys_bat_state));
    >
    >
    >
    > printf("BatteryPresent: \n", sys_bat_state.BatteryPresent);
    > printf("Charging: \n", sys_bat_state.Charging);
    > printf("Discharging: \n", sys_bat_state.Discharging);
    > printf("Maxcapacity: \n", sys_bat_state.MaxCapacity);
    > printf("RemainingCapacity: \n", sys_bat_state.RemainingCapacity);
    > printf("Rate: \n", sys_bat_state.Rate);
    >
    >
    > system("PAUSE");
    >
    > }
    >
    > I did link the libpowrprof.a already.
    >
    > Any ideas?


    Your printf statements are all invalid, containing no formatting
    specification. You need something like the %d in the following:

    printf("BatteryPresent: %d\n", sys_bat_state.BatteryPresent);

    --
    Scott McPhillips [VC++ MVP]
     
    Scott McPhillips [MVP], Oct 13, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vnssoftware

    Windows Programming using Java

    vnssoftware, Nov 22, 2003, in forum: Java
    Replies:
    12
    Views:
    5,929
    vnssoftware
    Dec 26, 2003
  2. Matt
    Replies:
    35
    Views:
    10,675
    George Neuner
    Jul 22, 2004
  3. Jon Turlington
    Replies:
    12
    Views:
    555
    Stefan Schmiedl
    Feb 6, 2007
  4. Midhun K Menon

    Windows Programming using C++

    Midhun K Menon, Aug 21, 2005, in forum: C++
    Replies:
    4
    Views:
    360
    Midhun K Menon
    Aug 21, 2005
  5. Jon Turlington
    Replies:
    5
    Views:
    320
    Alfred
    Feb 6, 2007
Loading...

Share This Page