#include <windows.h>
#include <stdio.h>
#include <string.h>
#define IDTimer 1
#define laps_temps 1000
LONG FAR PASCAL WndProc(HWND,WORD,WORD,LONG);
int PASCAL WinMain(HANDLE hInstance,HANDLE hPrevInstance,
LPSTR lpszCmdLine,int nCmdShow)
{
static char szAppName[]="MEMLIBRE";
HWND hWnd;
MSG msg;
WNDCLASS wndclass;
if (!hPrevInstance) {
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=NULL;
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=szAppName;
RegisterClass(&wndclass);
}
hWnd=CreateWindow(szAppName,"MEMLIBRE",WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,0,CW_USEDEFAULT,0,NULL,NULL,
hInstance,NULL);
if (!SetTimer(hWnd,IDTimer,laps_temps,NULL)) {
MessageBox(hWnd,"Plus de timer disponible","Horloge",MB_ICONEXCLAMATION|MB_OK);
return FALSE;
}
MessageBox(hWnd,"ICONE : Memoire Disponible","Memoire",MB_ICONEXCLAMATION|MB_OK);
ShowWindow(hWnd,SW_SHOWMINNOACTIVE);
UpdateWindow(hWnd);
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (msg.wParam);
}
/***************************************************************************/
LONG FAR PASCAL WndProc(HWND hWnd,WORD Message,WORD wParam,LONG lParam)
{
HDC hDC;
PAINTSTRUCT ps;
static RECT taille_fenetre;
static char car[20],cardif[20];
static float memlib,v_memlib=0.0,diff=0.0;
switch (Message) {
case WM_CREATE:
GetClientRect(hWnd,&taille_fenetre);
strcpy(car,"");
strcpy(cardif,"");
break;
case WM_TIMER:
memlib=GetFreeSpace(0);
memlib/=1024;
memlib/=1024;
sprintf(car,"%.3f%",memlib);
if (!(memlib==v_memlib)) {
diff=memlib-v_memlib;
sprintf(cardif,"%+.2f",diff);
InvalidateRect(hWnd,NULL,TRUE);
v_memlib=memlib;
}
break;
case WM_PAINT:
hDC=BeginPaint(hWnd,&ps);
Rectangle(hDC,0,0,32,32);
TextOut(hDC,0,0,car,strlen(car));
TextOut(hDC,0,16,cardif,strlen(cardif));
EndPaint(hWnd,&ps);
break;
case WM_QUERYOPEN:
return 0;
case WM_DESTROY:
KillTimer(hWnd,IDTimer);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,Message,wParam,lParam);
}
return NULL;
}