home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------
- - Windows DISKFREE.C -
- - (c) 1991 toolbox & U.Schmitz -
- ---------------------------------------------------------*/
-
- #include <windows.h>
- #include <dos.h>
- #include <string.h>
- #include <stdlib.h>
-
- #define BLOCK 100
-
- /*------------------------------------------------
- Prototyp der Fensterfunktion
- --------------------------------------------------*/
-
- long FAR PASCAL Fenster (HWND, WORD, WORD, LONG);
- HDC hdc;
- static char szAppName[] = "Diskfree";
- HANDLE hInst;
-
-
- /*------------------------------------------------
- Unterprogramme
- -------------------------------------------------*/
-
- void diskfree()
- {
- struct diskfree_t lwinfo;
-
- unsigned yfrei=0, yganz=0, lw, lw_new, partitions,
- x_start, abstand, i;
-
- long faktor, free_sectors=0, max_sectors=0,
- highest_sectors=0;
-
- char text[30], copyright[50];
-
- i = 0;
- partitions = 0;
- lw = 3; /* 3=C, 4=D usw. */
- lw_new = lw;
-
- while(lw == lw_new)
- {
- partitions++;
- _dos_setdrive(++lw, &i);
- _dos_getdrive(&lw_new);
- }
-
- abstand = 635 - (partitions * BLOCK); /* Fensterbreite */
- x_start = abstand/(partitions + 1); /* anpassen */
- abstand = x_start;
-
- /***** Maximale Plattengröße ermitteln!!!! **************/
-
- for( i=3; i < (partitions+3); i++)
- {
- _dos_getdiskfree(i, &lwinfo);
-
- max_sectors = ((long)lwinfo.total_clusters *
- lwinfo.sectors_per_cluster *
- lwinfo.bytes_per_sector );
-
- if (max_sectors > highest_sectors)
- highest_sectors = max_sectors;
- }
- faktor = highest_sectors/320;
-
- /**********************************************************/
- for( i=3; i < (partitions+3); i++)
- {
- _dos_getdiskfree(i, &lwinfo);
-
- max_sectors = ((long)lwinfo.total_clusters *
- lwinfo.sectors_per_cluster *
- lwinfo.bytes_per_sector );
-
- free_sectors = ((long)lwinfo.avail_clusters *
- lwinfo.sectors_per_cluster *
- lwinfo.bytes_per_sector );
-
- wsprintf(text, " Laufwerk %c: ",
- 'A'+i-1);
-
- TextOut(hdc, x_start-20, 350, text, 27);
- wsprintf(text, " %08ld Bytes frei ", free_sectors);
- TextOut(hdc, x_start-20, 365, text, 21);
-
- yganz = (unsigned)(max_sectors /faktor);
- yfrei = (unsigned)(free_sectors/faktor);
-
- SelectObject(hdc,GetStockObject(WHITE_BRUSH));
- Rectangle (hdc, x_start,350, x_start+BLOCK,
- 350-yganz);
-
- SelectObject(hdc,GetStockObject(GRAY_BRUSH));
- Rectangle (hdc, x_start,350, x_start+BLOCK,
- 350-(yganz-yfrei));
-
- x_start+=(abstand+BLOCK);
- }
- SelectObject(hdc,GetStockObject(GRAY_BRUSH));
- Rectangle (hdc, 15, 415, 620, 445);
-
- SelectObject(hdc,GetStockObject(WHITE_BRUSH));
- Rectangle (hdc, 20, 420, 615, 440);
- wsprintf(copyright,
- "DISKFREE 1.0 (C) 1991 Ulrich Schmitz & toolbox");
- TextOut(hdc, 150, 421, copyright, 48);
- }
-
-
- /*------------------------------------------------
- Hier ist der Eintrittspunkt des Programms
- --------------------------------------------------*/
-
- int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
- LPSTR lpszCmdParam, int nCmdShow)
- {
- HWND hwnd;
- MSG msg;
- WNDCLASS wndclass;
- HANDLE handle;
-
- if (!hPrevInstance)
- {
-
- /*------------------------------------------------
- Hier wird die Fensterklasse definiert
- --------------------------------------------------*/
- wndclass.style = CS_HREDRAW | CS_VREDRAW ;
- wndclass.lpfnWndProc = Fenster;
- wndclass.cbClsExtra = 0;
- wndclass.cbWndExtra = 0;
- wndclass.hInstance = hInstance;
- wndclass.hIcon = LoadIcon(hInstance, szAppName);
- wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
- wndclass.hbrBackground = GetStockObject(LTGRAY_BRUSH);
- wndclass.lpszMenuName = NULL;
- wndclass.lpszClassName = szAppName ;
-
- /*------------------------------------------------
- Hier wird die Fensterklasse registriert
- --------------------------------------------------*/
-
- RegisterClass (&wndclass);
- }
-
- hInst = hInstance;
-
- hwnd = CreateWindow (szAppName,
- "Diskfree",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- NULL,
- NULL,
- hInstance,
- NULL);
-
- /*------------------------------------------------
- Darstellen des Fensters und des Client-Bereichs
- --------------------------------------------------*/
-
- ShowWindow(hwnd, nCmdShow) ;
- UpdateWindow (hwnd);
-
- /*------------------------------------------------
- Warten auf eine Nachricht
- --------------------------------------------------*/
-
- while (GetMessage (&msg, NULL, 0, 0))
- {
- TranslateMessage (&msg);
- DispatchMessage (&msg);
- }
- return msg.wParam;
- }
-
- /*------------------------------------------------
- Definition der Fensterfunktion
- --------------------------------------------------*/
-
- long FAR PASCAL Fenster (HWND hwnd, WORD message,
- WORD wParam, LONG lParam)
- {
- static HICON hIcon;
- PAINTSTRUCT ps;
- RECT rect;
-
- /*------------------------------------------------
- Hier werden eintreffende Nachrichten verarbeitet
- --------------------------------------------------*/
-
- switch(message)
- {
- case WM_CREATE :
- return 0;
-
- case WM_PAINT :
- hIcon = LoadIcon (hInst, szAppName);
- hdc = BeginPaint (hwnd, &ps);
- GetClientRect (hwnd, &rect) ;
-
- /** Eigentliche Zeichen- und Arbeitsroutine ***************/
-
- diskfree();
-
- /**********************************************************/
-
- EndPaint (hwnd, &ps);
- return 0;
-
- case WM_DESTROY :
- PostQuitMessage (0);
- return 0;
- }
-
- return DefWindowProc (hwnd, message, wParam, lParam);
- }
- /*----------------------------------------------------------
- - Ende von DISKFREE.C */