Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > Visual C++
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 13th, 2006, 07:53 AM
Registered User
 
Join Date: Mar 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trouble writing small app... ???API usage???

Hello, all.

I am brand new to C++. I am trying to write a quick app to shut off a Pocket PC(WM 2003) once the battery reaches 15% . I believe I have all of the code that i need (which I found in various places), but I am not quite grasping exactly how to use the API code, which I have pasted below.

Can some explain how to code: "SWITCH OFF POCKET PC IF BATTERY PERCENT <15%"

:::CODE TO SWITCH OFF POCKET PC:::
Code:
// Switch off a Pocket PC
//
#include "stdafx.h"
 
int WINAPI WinMain(  HINSTANCE hInstance,
                                  HINSTANCE hPrevInstance,
                                  LPTSTR    lpCmdLine,
                                  int       nCmdShow)
{
 
       // Send keypresses that mean power off
       keybd_event(VK_OFF,0,KEYEVENTF_SILENT,0);
       keybd_event(VK_OFF,0,(KEYEVENTF_KEYUP|KEYEVENTF_SILENT),0);
 
       return 0;
}
------------

:::API CODE THAT RETURNS BATTERY PERCENT (SO I AM TOLD BY HELP FILE):::

API REFERNCE:

SYSTEM_POWER_STATUS_EX

This structure contains information about the power status of the system.
Code:
typedef struct _SYSTEM_POWER_STATUS_EX {

BYTE ACLineStatus;

BYTE BatteryFlag;

BYTE BatteryLifePercent;

BYTE Reserved1;

DWORD BatteryLifeTime;

DWORD BatteryFullLifeTime;

BYTE Reserved2;

BYTE BackupBatteryFlag;

BYTE BackupBatteryLifePercent;

BYTE Reserved3;

DWORD BackupBatteryLifeTime;

DWORD BackupBatteryFullLifeTime;

} SYSTEM_POWER_STATUS_EX, *PSYSTEM_POWER_STATUS_EX, *LPSYSTEM_POWER_STATUS_EX;

ADDITIONAL CODE I MAY NEED???:
This function retrieves the power status of the system. The status indicates whether the system is running on AC or DC power, whether or not the batteries are currently charging, and the remaining life of main and backup batteries.A remote application interface (RAPI) version of this function exists, and it is called CeGetSystemPowerStatusEx.

Code:
BOOL GetSystemPowerStatusEx(

PSYSTEM_POWER_STATUS_EX pstatus,

BOOL fUpdate );


Parameters
pstatus[out] Pointer to the SYSTEM_POWER_STATUS_EX structure receiving the power status information.

fUpdate
[in] If this Boolean is set to TRUE, GetSystemPowerStatusEx gets the latest information from the device driver, otherwise it retrieves cached information that may be out-of-date by several seconds.
Thank you in advance







Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing a VB/Access app for Vista as Standard User lescox Pro VB 6 2 March 9th, 2008 05:39 PM
Trouble writing to an Access Database JAdkins Classic ASP Basics 5 June 27th, 2007 03:05 PM
Trouble writing database MDrumm Classic ASP Databases 5 August 4th, 2005 03:27 PM
App.xxx ONLY via API - Help ! Peppiniello Pro VB 6 1 December 23rd, 2004 04:38 PM
Need help in writing a C program using win32 API rameshbabumv C++ Programming 0 March 10th, 2004 05:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.