home *** CD-ROM | disk | FTP | other *** search
- /* FreeEMM.c
- * Windows Application that displays free expanded memory
- * Requires MS C5.0 (for _dos_open ), will run with Windows 1.x and 2.x
- * Note: Compiled and tested with C5.0 and Windows 2.01
- *
- * PUBLIC DOMAIN
- * MAY BE DISTRIBUTED IN AN UNMODIFED FORM WITHOUT OBLIGATION TO AUTHOR
- *
- * Written By: David A. Hoatson, Spectrum Productions 1987
- * Spinoff of idea by: Charles Petzold
- */
-
- #define NOMINMAX /* for screwed up windows.h file */
- #include <windows.h>
- #include <stdlib.h>
- #include <string.h>
- #include <fcntl.h>
- #include <dos.h>
- #include <stdio.h>
-
- #define EMMINT 0x67
- #define EMMGETPAGES 0x42
- #define EMMGETVERSION 0x46
-
- char verbuf[6];
-
- emm_get_version( version )
- unsigned char *version;
- {
- union REGS regs;
-
- regs.h.ah = EMMGETVERSION;
- int86( EMMINT, ®s, ®s );
- *version = regs.h.al;
-
- return( TRUE );
- }
-
- emm_get_num_pages( num_pages, unalloc_pages )
- int *num_pages, *unalloc_pages;
- {
- union REGS regs;
-
- regs.h.ah = EMMGETPAGES;
- int86( EMMINT, ®s, ®s );
- *num_pages = regs.x.dx;
- *unalloc_pages = regs.x.bx;
-
- return( TRUE );
- }
-
- /* Procedures which make up the window class. */
- long FAR PASCAL WndProc( hWnd, message, wParam, lParam )
- HWND hWnd;
- unsigned message;
- WORD wParam;
- LONG lParam;
- {
- static int mem, lastmem, maxmem;
- char buffer[20];
- PAINTSTRUCT ps;
- RECT rect;
- int num_pages, unalloc_pages;
-
- switch (message) {
- case WM_TIMER:
- emm_get_num_pages( &num_pages, &unalloc_pages );
- maxmem = num_pages * 16;
- mem = unalloc_pages * 16;
- if (mem != lastmem)
- InvalidateRect( hWnd, NULL, TRUE );
- lastmem = mem;
- break;
-
- case WM_PAINT:
- BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );
-
- /* Maximum Expanded memory in system */
- strcat( itoa( maxmem, buffer, 10 ), "K" );
-
- /* Decided to hard code X and Y coords to fit in icon */
- TextOut( ps.hdc, 0, 0, buffer, strlen( buffer ) );
-
- /* Available Expanded memory in system */
- strcat( itoa( mem, buffer, 10 ), "K" );
- TextOut( ps.hdc, 0, 12, buffer, strlen( buffer ) );
-
- /* Version number of EMM driver */
- TextOut( ps.hdc, 0, 24, verbuf, strlen( verbuf ) );
- EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
- break;
-
- case WM_QUERYOPEN:
- break;
-
- case WM_DESTROY:
- KillTimer( hWnd, 1 );
- PostQuitMessage( 0 );
- break;
-
- default:
- return DefWindowProc( hWnd, message, wParam, lParam );
- break;
- }
- return(0L);
- }
-
- int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
- HANDLE hInstance, hPrevInstance;
- LPSTR lpszCmdLine;
- int cmdShow;
- {
- static char szAppName[] = "FreeEMM";
- WNDCLASS WndClass;
- MSG msg;
- HWND hWnd;
- int fh;
- struct EMMVERSION {
- unsigned char low : 4;
- unsigned char high: 4;
- } emmversion;
-
- if (hPrevInstance)
- return FALSE;
-
- /* Register Class for Main Windows */
- WndClass.hCursor = LoadCursor( NULL, IDC_ARROW );
- WndClass.hIcon = NULL;
- WndClass.cbClsExtra = 0;
- WndClass.cbWndExtra = 0;
- WndClass.lpszMenuName = szAppName;
- WndClass.lpszClassName = szAppName;
- WndClass.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
- WndClass.hInstance = hInstance;
- WndClass.style = CS_HREDRAW | CS_VREDRAW;
- WndClass.lpfnWndProc = WndProc;
-
- if (!RegisterClass( (LPWNDCLASS)&WndClass ) )
- return(FALSE);
-
- if ( _dos_open( "EMMXXXX0", O_RDONLY, &fh ) != 0 ) {
- MessageBox( hWnd, szAppName, "Expanded Memory Manager Not Found",
- MB_OK | MB_ICONEXCLAMATION );
- exit( 1 );
- }
-
- emm_get_version( &emmversion );
- sprintf( verbuf, "V%d.%d", emmversion.high, emmversion.low );
-
- hWnd = CreateWindow(szAppName, szAppName, WS_TILEDWINDOW,
- 0, 0, 0, 0, NULL, NULL, hInstance, NULL );
-
- if (!SetTimer( hWnd, 1, 1000, NULL ))
- return FALSE;
-
- ShowWindow( hWnd, SW_SHOWMINIMIZED );
- UpdateWindow( hWnd );
-
- /* Polling messages from event queue */
- while (GetMessage( &msg, NULL, 0, 0 )) {
- TranslateMessage( &msg );
- DispatchMessage( &msg );
- }
-
- return (int)msg.wParam;
- }