home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / MEM.ZIP / MEM.C < prev    next >
C/C++ Source or Header  |  1989-03-03  |  3KB  |  114 lines

  1. #define INCL_PM
  2. #define INCL_DOSMEMMGR
  3. #include <os2.h>
  4. #include <stdio.h>
  5. #include <math.h>
  6. #include <string.h>
  7. #include "mem.h"
  8.  
  9. HAB    hAB;
  10. HMQ    hmqMem;
  11. HWND    hwndMem;
  12. HWND    hwndMemFrame;
  13. CHAR    szMessage[80];
  14. ULONG avail;
  15.  
  16. SHORT cdecl main( )
  17. {
  18.     QMSG qmsg;
  19.  
  20.     hAB = WinInitialize(NULL);
  21.  
  22.     hmqMem = WinCreateMsgQueue(hAB, 0);
  23.     if(!MemInitApp())
  24.     return(1);
  25.  
  26.     while( WinGetMsg( hAB, (PQMSG)&qmsg, (HWND)NULL, 0, 0 ) )
  27.     {
  28.     WinDispatchMsg( hAB, (PQMSG)&qmsg );
  29.     }
  30.  
  31.     WinDestroyWindow( hwndMemFrame );
  32.     WinDestroyMsgQueue( hmqMem );
  33.     WinTerminate( hAB );
  34. }
  35.  
  36. MRESULT EXPENTRY MemWndProc( hWnd, msg, mp1, mp2 )
  37. HWND   hWnd;
  38. USHORT msg;
  39. MPARAM mp1;
  40. MPARAM mp2;
  41. {
  42.     HPS    hPS;
  43.     static SHORT timer_delay = IDM_1;
  44.     RECTL   rect;
  45.     LONG    clrFore;
  46.     LONG    clrBack;
  47.     USHORT  rgfCmd;
  48.  
  49.   switch (msg)
  50.     {
  51.     case WM_CREATE:
  52.          WinStartTimer(hAB,hWnd,ID_TIMER,timer_delay * 1000);
  53.          CheckMenuItem(hWnd,timer_delay,TRUE);
  54.         break;
  55.     case WM_COMMAND:
  56.          switch(LOUSHORT(mp1))
  57.          {
  58.           case IDM_60:
  59.           case IDM_30:
  60.           case IDM_10:
  61.           case IDM_1:
  62.                CheckMenuItem(hWnd,timer_delay,FALSE);
  63.                timer_delay = LOUSHORT(mp1);
  64.                CheckMenuItem(hWnd,timer_delay,TRUE);
  65.                WinPostMsg( hWnd, WM_TIMER, 0L, 0L );
  66.                WinStartTimer(hAB,hWnd,ID_TIMER,timer_delay * 1000);
  67.                break;
  68.           case IDM_EXITMEM:
  69.                WinPostMsg( hWnd, WM_QUIT, 0L, 0L );
  70.                break;
  71.           case IDM_RESUME:
  72.                break;
  73.          }
  74.          break;
  75.    case WM_CLOSE:
  76.     WinPostMsg( hWnd, WM_QUIT, 0L, 0L );
  77.     break;
  78.  
  79.     case WM_TIMER:
  80.      WinInvalidateRegion(hWnd,NULL, TRUE);
  81.     break;
  82.     case WM_PAINT:
  83.     hPS = WinBeginPaint( hWnd, (HPS)NULL, (PWRECT)NULL );
  84.     WinQueryWindowRect( hWnd, (PRECTL)&rect );
  85.     clrFore = CLR_BLACK;
  86.     clrBack = CLR_BACKGROUND;
  87.     rgfCmd = DT_CENTER | DT_VCENTER | DT_TEXTATTRS | 
  88. DT_ERASERECT;
  89.     DosMemAvail(&avail);
  90.     sprintf(szMessage,"Free memory : %.f bytes",(double)avail);
  91.     WinDrawText(hPS, 0xFFFF, szMessage, &rect, clrFore, clrBack, rgfCmd);
  92.     WinEndPaint( hPS );
  93.     break;
  94.  
  95.     case WM_ERASEBACKGROUND:
  96.     return( TRUE );
  97.     break;
  98.  
  99.     default:
  100.     return( WinDefWindowProc( hWnd, msg, mp1, mp2 ) );
  101.     break;
  102.     }
  103.     return(0L);
  104. }
  105.  
  106. VOID CheckMenuItem(HWND hwnd, SHORT iMenuItem, BOOL bCheck)
  107. {
  108.    HWND hwndParent = WinQueryWindow(hwnd,QW_PARENT,FALSE);
  109.    HWND hwndMenu = WinWindowFromID(hwndParent,FID_MENU);
  110.    
  111. WinSendMsg(hwndMenu,MM_SETITEMATTR,(MPARAM)MAKEULONG(iMenuItem,TRUE), 
  112.   (MPARAM)MAKEULONG(MIA_CHECKED,bCheck ? MIA_CHECKED : 0));
  113. }
  114.