home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / m / msjmar93.zip / MEMMAN.ZIP / MEMSTAT.ZIP / MEMSTAT.C < prev    next >
Text File  |  1993-03-01  |  3KB  |  108 lines

  1. /****************************************************************************
  2. Module name: MemStat.C
  3. *****************************************************************************/
  4.  
  5. #include <windows.h>
  6. #include <windowsx.h>
  7. #include <string.h>   // for strrev
  8. #include "MemStat.H"
  9.  
  10. // This function accepts a number and converts it to a string
  11. // inserting commas where appropriate.
  12. LPSTR WINAPI BigNumToString (LONG lNum, LPSTR szBuf) {
  13.    WORD wNumDigits = 0, wNumChars = 0;
  14.  
  15.    do {
  16.       // Put the last digit of the string in the character buffer.
  17.       szBuf[wNumChars++] = lNum % 10 + '0';
  18.  
  19.       // Increment the number of digits that we put in the string.
  20.       wNumDigits++;
  21.  
  22.       // For every three digits put in the string, add a comma ",".
  23.       if (wNumDigits % 3 == 0)
  24.          szBuf[wNumChars++] = ',';
  25.  
  26.       // Divide the number by 10 and repeat the process.
  27.       lNum /= 10;
  28.  
  29.       // Continue adding digits to the string until the number is zero.
  30.    } while (lNum != 0);
  31.  
  32.    // If the last character added to the string was a comma, truncate it.
  33.    if (szBuf[wNumChars - 1] == ',')
  34.       szBuf[wNumChars - 1] = 0;
  35.  
  36.    // Make sure that the string is zero-terminated.
  37.    szBuf[wNumChars] = 0;
  38.  
  39.    // We added all of the chaaracters to the string in reverse order.
  40.    // We must reverse the contents of the string.
  41.    strrev(szBuf);
  42.  
  43.    // Returns the address of the string.  This is the same value that was
  44.    // passed to us initially.  Returning it here makes it easier for the
  45.    // calling function to use the string.
  46.    return(szBuf);
  47. }
  48.  
  49.  
  50. BOOL Dlg_OnInitDialog (HWND hwnd, HWND hwndFocus, LPARAM lParam) {
  51.    char szBuf[50];
  52.    MEMORYSTATUS ms;
  53.  
  54.    // Initialize the length of the structure before calling GlobalMemoryStatus.
  55.    ms.dwLength = sizeof(ms);
  56.    GlobalMemoryStatus(&ms);
  57.  
  58.    // File the static controls in the listbox with the appropraite number.
  59.    SetDlgItemText(hwnd, ID_MEMLOAD,
  60.       BigNumToString(ms.dwMemoryLoad, szBuf));
  61.  
  62.    SetDlgItemText(hwnd, ID_TOTALPHYS,
  63.       BigNumToString(ms.dwTotalPhys, szBuf));
  64.  
  65.    SetDlgItemText(hwnd, ID_AVAILPHYS,
  66.       BigNumToString(ms.dwAvailPhys, szBuf));
  67.  
  68.    SetDlgItemText(hwnd, ID_TOTALPAGEFILE,
  69.       BigNumToString(ms.dwTotalPageFile, szBuf));
  70.  
  71.    SetDlgItemText(hwnd, ID_AVAILPAGEFILE,
  72.       BigNumToString(ms.dwAvailPageFile, szBuf));
  73.  
  74.    SetDlgItemText(hwnd, ID_TOTALVIRTUAL,
  75.       BigNumToString(ms.dwTotalVirtual, szBuf));
  76.  
  77.    SetDlgItemText(hwnd, ID_AVAILVIRTUAL,
  78.       BigNumToString(ms.dwAvailVirtual, szBuf));
  79.  
  80.    return(TRUE);
  81. }
  82.  
  83. void Dlg_OnCommand (HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) {
  84.    switch (id) {
  85.       case IDCANCEL: EndDialog(hwnd, id); break;
  86.    }
  87. }
  88.  
  89.  
  90. BOOL CALLBACK DlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  91.    BOOL fProcessed = TRUE;
  92.    switch (uMsg) {
  93.       HANDLE_MSG(hDlg, WM_INITDIALOG, Dlg_OnInitDialog);
  94.       HANDLE_MSG(hDlg, WM_COMMAND, Dlg_OnCommand);
  95.  
  96.       default: fProcessed = FALSE; break;
  97.    }
  98.    return(fProcessed);
  99. }
  100.  
  101.  
  102. int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  103.    LPSTR lpszCmdLine, int nCmdShow) {
  104.  
  105.    DialogBox(hInstance, MAKEINTRESOURCE(DLG_MEMSTAT), NULL, DlgProc);
  106.    return(0);
  107. }
  108.