×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Automatic Suspend and resume using VC

Automatic Suspend and resume using VC

Automatic Suspend and resume using VC

(OP)

Hi,
The requirement is with respect to suspension and automatic resumption of the system.

For this WinAPI functions like

SetSystemPowerState()
GetSystemPowerStatus()
SYSTEM_POWER_STATUS

have been used.

EXTRACT FROM THE CODING:

LRESULT CALLBACK WndProc(HWND hWnd , UINT message ,WPARAM wParam ,LPARAM lParam)
{
static HCURSOR hCursor;
static int nXpos=0,nYpos=0;

switch(message)
{

case WM_CREATE:
hCursor = LoadCursor(NULL,IDC_ARROW);
break;

case WM_COMMAND:
switch(LOWORD(wParam))
{

case ID_EXIT:

DestroyWindow(hWnd);
break;

case ID_QUERYSTATUS:
{
SetSystemPowerState(TRUE,FALSE);
wParam=PBT_APMRESUMESUSPEND;
}
break;
}
break;

case WM_POWERBROADCAST:

if(wParam == PBT_APMQUERYSUSPEND)
{
char szBuffer[100],szBuffer1[100];
HDC hdc = GetDC(hWnd);

SYSTEM_POWER_STATUS ps;
GetSystemPowerStatus(&ps);
wsprintf(szBuffer,"AcLineStatus=%d,BatteryFlag=%d,BatteryFullLifeTime=%ld",
ps.ACLineStatus ,ps.BatteryFlag ,ps.BatteryFullLifeTime );
wsprintf(szBuffer1,"BatteryLifePercent=%d,BatteryLifetime=%ld,Reserved1=%d",
ps.BatteryLifePercent ,ps.BatteryLifeTime ,ps.Reserved1 );

TextOut(hdc,0,0,szBuffer,lstrlen(szBuffer));
TextOut(hdc,50,50,szBuffer1,lstrlen(szBuffer1));

if(ps.ACLineStatus )
{

int Reply = MessageBox(hWnd,"Do you want to suspend(Y/N)?","Suspension state",MB_YESNO);

if(Reply == IDYES)
return TRUE;
else
return FALSE;

}
}
return (DefWindowProc(hWnd,message,wParam,lParam));

case WM_DESTROY:

PostQuitMessage(0);
break;

default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
return(0L);
}

/////////////////////////////////////////////////////////////////////////////////////////////////

The problems encountered are:

1. Suspension and automatic resumption occurs, but not at all times, in the sense after suspension the systems waits in the suspended state until the key is pressed manually by the user to bring it to the resumption state.(Win 95)
What could be the reason for this?

2. The same program when run on laptop gets into suspension state and automatic resumption is not taking place at all when compared with Win 95(point No:1) as told above.


Could anyone suggest a solution for this problem?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close