[vc++] api win32 : gestion de la ram en progress bar v 1.1

Description

Le code a pour but de vous montrer grace a une progress bar, l'utilisation de votre Ram !
C'est la Version 1.0, car la version avec Texte nessecite une conversion DWLONG -> LPCSTR !
Zone verte : Entre 0 et 41 %
Orange Entre 41 et 81
ROUGE + 81

voila plz, ne mettez pas de mauvaise sans expliquer pourquoi dans les commentaires

Source / Exemple :


#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <commctrl.h>
#pragma comment(lib,"comctl32.lib")

HWND hmain;
HWND hprg;
HWND csur;
HWND soit;
HWND pcent;
HWND libre;

char szappname[] = "Rameur";

void __stdcall OnTimerRam()
{
  MEMORYSTATUSEX mstt;
  DWORD mem;
  long color;
  mstt.dwLength = sizeof(MEMORYSTATUSEX);
  GlobalMemoryStatusEx(&mstt);
  mem = mstt.dwMemoryLoad;
  if(mem < 41) color = RGB(23, 219, 38);
  else if(mem > 81) color = RGB(255, 66, 66);
  else color = RGB(255, 127, 0);
  SendMessage(hprg, PBM_SETBARCOLOR, 0, color);
  SendMessage(hprg, PBM_SETPOS, (WPARAM) mem, 0);
  	char buf[12];
	char buf1[12];
    ultoa(mem, buf, 10);
	ultoa(mstt.ullAvailPhys,buf1,10);
    SetWindowText(csur,buf); 
	SetWindowText(soit,"% soit ");
	SetWindowText(pcent,buf1);
	SetWindowText(libre,"Oc Libre");
}

LRESULT CALLBACK AppWndProc(HWND hwnd, UINT mssg, WPARAM wParam, LPARAM lParam)
{
  switch(mssg) {
    case WM_TIMER:
      OnTimerRam();
      return 0;
    case WM_CREATE:
      hprg = CreateWindowEx(CS_DBLCLKS, PROGRESS_CLASS, NULL, WS_CHILD | WS_VISIBLE | PBS_SMOOTH, 30, 20, 218, 30, hwnd, 0, 0, 0);
      csur = CreateWindowEx(0,"STATIC",NULL,WS_CHILD | WS_VISIBLE,30,60,200,30,hwnd,0,0,0);
	  soit = CreateWindowEx(0,"STATIC",NULL,WS_CHILD | WS_VISIBLE,50,60,200,90,hwnd,0,0,0);
	  pcent =CreateWindowEx(0,"STATIC",NULL,WS_CHILD | WS_VISIBLE,95,60,300,90,hwnd,0,0,0);
	  libre =CreateWindowEx(0,"STATIC",NULL,WS_CHILD | WS_VISIBLE,175,60,300,90,hwnd,0,0,0);
	  SetTimer(hwnd,1,500,NULL);
      SendMessage(hprg, PBM_SETRANGE, 0, MAKELPARAM(0,100));
      return 0;
    case WM_DESTROY:
      KillTimer(hwnd, 1);
      PostQuitMessage(0);
      return 0;
  }
  return DefWindowProc(hwnd, mssg, wParam, lParam);
}

DWORD __stdcall InitInstance(HINSTANCE hinst)
{
  WNDCLASSEX     wndcls;
  INITCOMMONCONTROLSEX iccex;
  iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  iccex.dwICC = ICC_PROGRESS_CLASS;
  if(!InitCommonControlsEx(&iccex)) return 0;
  memset(&wndcls, 0, sizeof(WNDCLASSEX));
  wndcls.cbSize = sizeof(WNDCLASSEX);
  wndcls.lpfnWndProc   = AppWndProc;
  wndcls.style         = CS_HREDRAW | CS_VREDRAW;
  wndcls.hInstance     = hinst;
  wndcls.lpszClassName = szappname;
  wndcls.hbrBackground = CreateSolidBrush(RGB(236,233,216));
  wndcls.hCursor       = LoadCursor(0, IDC_ARROW);
  if(!RegisterClassEx(&wndcls)) return 0;
  hmain = CreateWindowEx(WS_EX_TOPMOST, szappname, szappname, WS_OVERLAPPED | WS_VISIBLE | WS_SYSMENU | WS_MINIMIZEBOX,
                        CW_USEDEFAULT, CW_USEDEFAULT, 280, 125, 0, 0, hinst, 0);
  return (hmain != 0);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE x, PSTR y, int z)
{
  MSG msg;
  if(!InitInstance(hInstance)) return 0;
  ShowWindow(hmain, SW_NORMAL);
  while(GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  return 0;
}

Conclusion :


Merci a Brunews qui ma expliquer comment recuperer les notions de memoires RAM
Version 1.1 :) Je pense bientot integrer un system de defragmentation de RAM :) voila merci :)

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.