home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / shtdwn01.zip / Source / shutdown.c < prev    next >
C/C++ Source or Header  |  1994-01-30  |  2KB  |  95 lines

  1. /**
  2.  **  PM Shutdown v0.1
  3.  **
  4.  **  (c) 1994 by Carsten Wimmer
  5.  **
  6.  **/
  7.  
  8. #define INCL_WINDIALOGS
  9. #define INCL_WINFRAMEMGR
  10. #define INCL_WINWORKPLACE
  11. #define INCL_WINWINDOWMGR
  12. #define INCL_WINTIMER
  13. #include <os2.h>
  14. #include <stdlib.h>
  15. #include "shutdown.h"
  16.  
  17. #define APPNAME "PM Shutdown"
  18. #define VERSION "v0.1"
  19.  
  20. MRESULT EXPENTRY shutdownProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  21.  
  22. HWND hwndDlg;
  23. HAB hab;
  24. HMQ hmq;
  25. ULONG TimerID, Seconds=1, TimeToGo;
  26.  
  27. void main(int argc, char *argv[])
  28. {
  29.   if( argc != 2 )
  30.     return;
  31.  
  32.   TimeToGo = atol(argv[1]);
  33.  
  34.   if( !(hab = WinInitialize( 0 )) )
  35.     return;
  36.  
  37.   if( !(hmq = WinCreateMsgQueue(hab, 0)) )
  38.     return;
  39.  
  40.   hwndDlg = WinLoadDlg(HWND_DESKTOP, HWND_DESKTOP, shutdownProc, 0, ID_DIALOG, 0);
  41.  
  42.   WinProcessDlg(hwndDlg);
  43.  
  44.   WinDestroyWindow(hwndDlg);
  45.   WinDestroyMsgQueue(hmq);
  46.   WinTerminate(hab);
  47.  
  48.   return;
  49. }
  50.  
  51. MRESULT EXPENTRY shutdownProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  52. {
  53.   char str[255];
  54.  
  55.   switch(msg)
  56.   {
  57.    case WM_INITDLG:
  58.      sprintf(str, "%s %s (Timer: %ld out of %ld)", APPNAME, VERSION, Seconds, TimeToGo);
  59.      WinSetWindowText(WinWindowFromID(hwnd, FID_TITLEBAR), (PSZ) str);
  60.      TimerID = WinStartTimer(hab, hwnd, 50, 1000UL);
  61.      break;
  62.    case WM_COMMAND:
  63.      switch( SHORT1FROMMP(mp1) )
  64.      {
  65.        case ID_BUTTON_OK:
  66.          WinPostMsg(hwnd, WM_CLOSE, 0, 0);
  67.          WinShutdownSystem(WinQueryAnchorBlock(HWND_DESKTOP), hmq);
  68.          break;
  69.        case ID_BUTTON_CANCEL:
  70.          WinPostMsg(hwnd, WM_CLOSE, 0, 0);
  71.          break;
  72.        default:
  73.          break;
  74.      }
  75.      break;
  76.    case WM_TIMER:
  77.      Seconds++;
  78.      sprintf(str, "%s %s (Timer: %ld out of %ld)", APPNAME, VERSION, Seconds, TimeToGo);
  79.      WinSetWindowText(WinWindowFromID(hwnd, FID_TITLEBAR), (PSZ) str);
  80.      if( Seconds == TimeToGo ) {
  81.        WinStopTimer(hab, hwnd, TimerID);
  82.        WinPostMsg(hwnd, WM_COMMAND, MPFROMSHORT(ID_BUTTON_OK), 0);
  83.      }
  84.      break;
  85.    case WM_CLOSE:
  86.      WinDismissDlg(hwnd, TRUE);
  87.      break;
  88.    default:
  89.      return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  90.   }
  91.  
  92.   return (MRESULT)0;
  93. }
  94.  
  95.