Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic Suspend and resume using VC

Status
Not open for further replies.

Shakila

Programmer
Jun 14, 2000
1
US
<br>Hi, <br>The requirement is with respect to suspension and automatic resumption of the system.<br><br>For this WinAPI functions like<br><br>SetSystemPowerState()<br>GetSystemPowerStatus()<br>SYSTEM_POWER_STATUS<br><br>have been used.<br><br>EXTRACT FROM THE CODING:<br><br>LRESULT CALLBACK WndProc(HWND hWnd , UINT message ,WPARAM wParam ,LPARAM lParam)<br>{<br> static HCURSOR hCursor;<br> static int nXpos=0,nYpos=0;<br> <br> switch(message)<br> {<br><br> case WM_CREATE:<br> hCursor = LoadCursor(NULL,IDC_ARROW);<br> break;<br> <br> case WM_COMMAND:<br> switch(LOWORD(wParam))<br> {<br> <br> case ID_EXIT:<br><br> DestroyWindow(hWnd);<br> break;<br><br> case ID_QUERYSTATUS:<br> {<br> SetSystemPowerState(TRUE,FALSE);<br> wParam=PBT_APMRESUMESUSPEND;<br> }<br> break;<br> }<br> break;<br><br> case WM_POWERBROADCAST:<br><br> if(wParam == PBT_APMQUERYSUSPEND)<br> {<br> char szBuffer[100],szBuffer1[100];<br> HDC hdc = GetDC(hWnd);<br> <br> SYSTEM_POWER_STATUS ps;<br> GetSystemPowerStatus(&ps);<br> wsprintf(szBuffer,&quot;AcLineStatus=%d,BatteryFlag=%d,BatteryFullLifeTime=%ld&quot;,<br> ps.ACLineStatus ,ps.BatteryFlag ,ps.BatteryFullLifeTime );<br> wsprintf(szBuffer1,&quot;BatteryLifePercent=%d,BatteryLifetime=%ld,Reserved1=%d&quot;,<br> ps.BatteryLifePercent ,ps.BatteryLifeTime ,ps.Reserved1 );<br> <br> TextOut(hdc,0,0,szBuffer,lstrlen(szBuffer));<br> TextOut(hdc,50,50,szBuffer1,lstrlen(szBuffer1));<br><br> if(ps.ACLineStatus )<br> {<br> <br> int Reply = MessageBox(hWnd,&quot;Do you want to suspend(Y/N)?&quot;,&quot;Suspension state&quot;,MB_YESNO);<br> <br> if(Reply == IDYES)<br> return TRUE;<br> else<br> return FALSE;<br> <br> }<br> }<br> return (DefWindowProc(hWnd,message,wParam,lParam));<br><br> case WM_DESTROY:<br><br> PostQuitMessage(0);<br> break;<br> <br> default:<br> return DefWindowProc(hWnd,message,wParam,lParam);<br>}<br> return(0L);<br>}<br><br>/////////////////////////////////////////////////////////////////////////////////////////////////<br><br>The problems encountered are:<br><br>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)<br> What could be the reason for this?<br><br>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.<br><br><br>Could anyone suggest a solution for this problem?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top