home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 December
/
simtel1292_SIMTEL_1292_Walnut_Creek.iso
/
msdos
/
mswindws
/
freedi.arc
/
FREEDISK.C
< prev
next >
Wrap
C/C++ Source or Header
|
1987-12-30
|
6KB
|
149 lines
/* FreeDisk.C -- WinApp to display free disk space on default drive */
/* Adapted from "FreeMem.C" (Charles Petzold) by Harold Long. */
/* Originally printed in Microsoft Systems Journal. */
/* Assembly & runtime environment: */
/* MAKE 4.02 */
/* MSC 4.00 */
/* LINK4 5.00.12 */
/* MAP 4.00 */
/* MS-DOS 3.10 */
/* Windows 1.03.04 */
/* Libraries required: */
/* SLIBW.LIB */
/* EM.LIB */
/* SLIBFP.LIB */
/* SLIBC.LIB */
/* LIBH.LIB */
#include <windows.h> /* all Windows functions */
#include <stdlib.h> /* itoa */
#include <string.h> /* strcat & strlen */
#include <dos.h> /* DOS registers */
long FAR PASCAL WndProc (HWND, unsigned, WORD, LONG);
/* WinMain - Main loop for all Windows applications */
int PASCAL WinMain ( hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
HANDLE hInstance;
LPSTR lpszCmdLine;
int nCmdShow;
{
static char szAppName [] = "FreeDisk";
WNDCLASS WndClass;
HWND hWnd;
MSG msg;
/* allow multiple instances */
/* define Window class */
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hIcon = NULL;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = (LPSTR) szAppName;
WndClass.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH );
WndClass.hInstance = hInstance;
WndClass.style = CS_VREDRAW | CS_HREDRAW;
WndClass.lpfnWndProc = WndProc;
/* register this new class with WINDOWS */
if (!RegisterClass((LPWNDCLASS)&WndClass))
return FALSE; /* Initialization failed */
/* create window */
hWnd = CreateWindow((LPSTR) szAppName,
(LPSTR) szAppName,
WS_TILEDWINDOW,
0, 0, 0, 0,
(HWND) NULL,
(HMENU) NULL,
(HANDLE) hInstance,
(LPSTR) NULL);
/* set up timer (1 update/sec) */
if (!SetTimer (hWnd, 1, 1000, NULL) )
return FALSE;
/* show window (start in ICONIC state) */
ShowWindow( hWnd, SHOW_ICONWINDOW );
UpdateWindow( hWnd );
/* main program loop */
while (GetMessage ((LPMSG) &msg, NULL, 0, 0)) {
TranslateMessage((LPMSG) &msg );
DispatchMessage((LPMSG) &msg );
} /* end while GetMessage */
/* exit back to Windows */
return (int) msg.wParam;
} /* end WinMain */
/* WndProc - Window procedure for main window */
long FAR PASCAL WndProc (hWnd, message, wParam, lParam)
HWND hWnd;
unsigned message;
WORD wParam;
LONG lParam;
{
static int lastdisk, byterept; /* DOS register values */
static char intno, doscall; /* Interrrupt constants */
static long bytecount; /* 32 bit precision */
char buffer[20];
PAINTSTRUCT ps;
RECT rect;
union REGS inregs; /* DOS.H registers */
union REGS outregs;
/* switch on message type sent to window by Windows dispatcher */
switch(message) {
case WM_TIMER:
doscall = 0x36; /* get free disk (36H) */
intno = 0x21; /* system function call */
inregs.h.ah = doscall; /* set up AH register */
inregs.h.dl = 0; /* "default" drive */
int86(intno,&inregs,&outregs); /* interrupt DOS */
bytecount = outregs.x.bx; /* available clusters */
bytecount = bytecount * outregs.x.ax; /* avail sectors */
bytecount = bytecount * outregs.x.cx; /* bytes/sector */
bytecount = (bytecount / 1000); /* avail K bytes */
if (bytecount != lastdisk)
InvalidateRect( hWnd, NULL, TRUE );
lastdisk = (int) bytecount;
break;
case WM_PAINT:
BeginPaint( hWnd, (LPPAINTSTRUCT) &ps );
GetClientRect( hWnd, (LPRECT) &rect );
if (bytecount > 9999) /* more than 10 Mbyte ? */
{
byterept = (int) (bytecount /1000); /* yes, reset scale */
DrawText( ps.hdc, (LPSTR) buffer,
strlen (strcat (itoa (byterept, buffer, 10), " Mbyt")),
(LPRECT) &rect, DT_WORDBREAK);
}
else
{
byterept = (int) bytecount;
DrawText( ps.hdc, (LPSTR) buffer,
strlen (strcat (itoa (byterept, buffer, 10), " Kbyt")),
(LPRECT) &rect, DT_WORDBREAK);
}
EndPaint( hWnd, (LPPAINTSTRUCT) &ps );
break;
case WM_DESTROY:
KillTimer (hWnd, 1);
PostQuitMessage( 0 );
break;
default:
return DefWindowProc( hWnd, message, wParam, lParam);
} /* end switch */
return (long) 0;
} /* end WndProc */