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 >
Wrap
Text File
|
1993-03-01
|
3KB
|
108 lines
/****************************************************************************
Module name: MemStat.C
*****************************************************************************/
#include <windows.h>
#include <windowsx.h>
#include <string.h> // for strrev
#include "MemStat.H"
// This function accepts a number and converts it to a string
// inserting commas where appropriate.
LPSTR WINAPI BigNumToString (LONG lNum, LPSTR szBuf) {
WORD wNumDigits = 0, wNumChars = 0;
do {
// Put the last digit of the string in the character buffer.
szBuf[wNumChars++] = lNum % 10 + '0';
// Increment the number of digits that we put in the string.
wNumDigits++;
// For every three digits put in the string, add a comma ",".
if (wNumDigits % 3 == 0)
szBuf[wNumChars++] = ',';
// Divide the number by 10 and repeat the process.
lNum /= 10;
// Continue adding digits to the string until the number is zero.
} while (lNum != 0);
// If the last character added to the string was a comma, truncate it.
if (szBuf[wNumChars - 1] == ',')
szBuf[wNumChars - 1] = 0;
// Make sure that the string is zero-terminated.
szBuf[wNumChars] = 0;
// We added all of the chaaracters to the string in reverse order.
// We must reverse the contents of the string.
strrev(szBuf);
// Returns the address of the string. This is the same value that was
// passed to us initially. Returning it here makes it easier for the
// calling function to use the string.
return(szBuf);
}
BOOL Dlg_OnInitDialog (HWND hwnd, HWND hwndFocus, LPARAM lParam) {
char szBuf[50];
MEMORYSTATUS ms;
// Initialize the length of the structure before calling GlobalMemoryStatus.
ms.dwLength = sizeof(ms);
GlobalMemoryStatus(&ms);
// File the static controls in the listbox with the appropraite number.
SetDlgItemText(hwnd, ID_MEMLOAD,
BigNumToString(ms.dwMemoryLoad, szBuf));
SetDlgItemText(hwnd, ID_TOTALPHYS,
BigNumToString(ms.dwTotalPhys, szBuf));
SetDlgItemText(hwnd, ID_AVAILPHYS,
BigNumToString(ms.dwAvailPhys, szBuf));
SetDlgItemText(hwnd, ID_TOTALPAGEFILE,
BigNumToString(ms.dwTotalPageFile, szBuf));
SetDlgItemText(hwnd, ID_AVAILPAGEFILE,
BigNumToString(ms.dwAvailPageFile, szBuf));
SetDlgItemText(hwnd, ID_TOTALVIRTUAL,
BigNumToString(ms.dwTotalVirtual, szBuf));
SetDlgItemText(hwnd, ID_AVAILVIRTUAL,
BigNumToString(ms.dwAvailVirtual, szBuf));
return(TRUE);
}
void Dlg_OnCommand (HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) {
switch (id) {
case IDCANCEL: EndDialog(hwnd, id); break;
}
}
BOOL CALLBACK DlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
BOOL fProcessed = TRUE;
switch (uMsg) {
HANDLE_MSG(hDlg, WM_INITDIALOG, Dlg_OnInitDialog);
HANDLE_MSG(hDlg, WM_COMMAND, Dlg_OnCommand);
default: fProcessed = FALSE; break;
}
return(fProcessed);
}
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow) {
DialogBox(hInstance, MAKEINTRESOURCE(DLG_MEMSTAT), NULL, DlgProc);
return(0);
}