2.0 gestion de la ram en progress bar [vc++] api win32

Description

Voila la version 2.0 qui sans RACPP n'aurait exister.
Merci beaucoup a lui !
Ce petit utiltaire, va vous permettre de gerer votre utilisation de Memoire Ram.

Merci de ne pas mettre de mauvaise note sans expliquer pourquoi.

Version 2.1 Release Grace a BRUNEWS :)

Source / Exemple :


#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <commctrl.h>
#include "bnIntA.h"
#include "resource.h"

#pragma comment(lib, "comctl32.lib")

HBRUSH fond;
HWND progress, text1, text2, text3, text4, text5, text6, text7, text8;
char szClassName[] = "WindowsApp";

void __stdcall OnTimer()
{
  MEMORYSTATUSEX statex;
  DWORD n;
  char buf[32], *c;
  statex.dwLength = sizeof (statex);
  GlobalMemoryStatusEx(&statex);
  // Obtenir la taille de la mémoire totale en Mo:
  n = (DWORD) ((statex.ullTotalPhys >> 20) + 1);
  c = bnultoa(n, buf);

  • c = 32; *(c+1) = 'M'; *(c+2) = 'o'; *(c+3) = 0;
SetWindowText(text4, buf); // Obtenir la taille de la mémoire disponible en Mo: n = (DWORD) ((statex.ullAvailPhys >> 20) + 1); c = bnultoa(n, buf);
  • c = 32; *(c+1) = 'M'; *(c+2) = 'o'; *(c+3) = 0;
SetWindowText(text8, buf); // Calculer la taille de la mémoire utilisée en Mo: n = (DWORD) ((statex.ullTotalPhys - statex.ullAvailPhys) >> 20); c = bnultoa(n, buf);
  • c = 32; *(c+1) = 'M'; *(c+2) = 'o'; *(c+3) = 0;
SetWindowText(text6, buf); // Obtenir le pourcentage de la mémoire utilisée: n = statex.dwMemoryLoad; c = bnultoa(n, buf);
  • c = 32; *(c+1) = '%'; *(c+2) = 0;
SetWindowText(text1, buf); SendMessage(progress, PBM_SETPOS, (WPARAM) n, 0); if(n < 41) n = RGB(23, 219, 38); else if(n < 81 && n >= 41) n = RGB(255, 127, 0); else if(n >= 81) n = RGB(255, 66, 66); SendMessage(progress, PBM_SETBARCOLOR, 0, (LPARAM) n); } void __stdcall OnCreate(HWND hwnd) { HGDIOBJ font = GetStockObject(DEFAULT_GUI_FONT); progress = CreateWindowEx(CS_DBLCLKS, PROGRESS_CLASS, NULL, WS_CHILD | WS_VISIBLE | PBS_SMOOTH , 30, 115, 200, 50, hwnd, NULL, 0, NULL); text1 = CreateWindowEx(0,"STATIC",0, WS_VISIBLE|WS_CHILD | SS_CENTER , 30,95,200,20,hwnd, 0, 0, NULL); SendMessage(text1, WM_SETFONT, (WPARAM)font, 0); text2 = CreateWindowEx(0,"STATIC","Jean G et RaCPP", WS_VISIBLE|WS_CHILD | SS_CENTER , 30,180,200,20,hwnd, 0, 0, NULL); SendMessage(text2, WM_SETFONT, (WPARAM)font, 0); text3 = CreateWindowEx(0,"STATIC","Mémoire totale\t\t:", WS_VISIBLE|WS_CHILD , 30,10,150,20,hwnd, 0, 0, NULL); SendMessage(text3, WM_SETFONT, (WPARAM)font, 0); text4 = CreateWindowEx(0,"STATIC",0, WS_VISIBLE|WS_CHILD | SS_RIGHT , 180,10,50,20,hwnd, 0, 0, NULL); SendMessage(text4, WM_SETFONT, (WPARAM)font, 0); text5 = CreateWindowEx(0,"STATIC","Mémoire utilisée\t\t:", WS_VISIBLE|WS_CHILD , 30,35,150,20,hwnd, 0, 0, NULL); SendMessage(text5, WM_SETFONT, (WPARAM)font, 0); text6 = CreateWindowEx(0,"STATIC",0, WS_VISIBLE|WS_CHILD | SS_RIGHT , 180,35,50,20,hwnd, 0, 0, NULL); SendMessage(text6, WM_SETFONT, (WPARAM)font, 0); text7 = CreateWindowEx(0,"STATIC","Mémoire disponible\t:", WS_VISIBLE|WS_CHILD , 30,60,150,20,hwnd, 0, 0, NULL); SendMessage(text7, WM_SETFONT, (WPARAM)font, 0); text8 = CreateWindowEx(0,"STATIC",0, WS_VISIBLE|WS_CHILD | SS_RIGHT , 180,60,50,20,hwnd, 0, 0, NULL); SendMessage(text8, WM_SETFONT, (WPARAM)font, 0); SendMessage(progress,PBM_SETRANGE,0,MAKELPARAM(0,100)); SendMessage(progress, PBM_SETBKCOLOR, 0, RGB(236,233,216)); SetTimer(hwnd,1,500,NULL); } LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_CREATE: OnCreate(hwnd); OnTimer(); // AFFICHAGE IMMEDIAT return 0; case WM_CTLCOLORSTATIC: SetTextColor((HDC)wParam,RGB(150,0,75)); SetBkMode((HDC)wParam, TRANSPARENT); return (LRESULT)fond; case WM_CLOSE: KillTimer(hwnd,1); DestroyWindow(hwnd); return 0; case WM_DESTROY: PostQuitMessage (0); return 0; case WM_TIMER: OnTimer(); return 0; default: return DefWindowProc (hwnd, message, wParam, lParam); } return 0; } HWND __stdcall InitInstance(HINSTANCE hinst) { WNDCLASSEX wincl; wincl.hInstance = hinst; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; wincl.style = CS_HREDRAW | CS_VREDRAW; wincl.cbSize = sizeof(WNDCLASSEX); wincl.hIcon = LoadIcon(hinst, (LPCTSTR) IDI_APP); wincl.hIconSm = LoadIcon(hinst, (LPCTSTR) IDI_APP); wincl.hCursor = LoadCursor(NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = fond; if(!RegisterClassEx(&wincl)) return 0; return CreateWindowEx(WS_EX_TOPMOST, szClassName, "Mémoire RAM", WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 270,240, 0, 0, hinst, 0); } #pragma comment(linker, "/entry:myWinMain") __declspec(naked) int __stdcall myWinMain() { __asm { call dword ptr InitCommonControls push 0D8E9ECh ; RGB(236, 233, 216) call dword ptr CreateSolidBrush mov fond, eax push 0 call dword ptr GetModuleHandle push eax call dword ptr InitInstance lea ebp, [esp-28] test eax, eax je short progEXIT mov esp, ebp mov esi, GetMessage push SW_NORMAL push eax mov ebx, TranslateMessage call dword ptr ShowWindow mov edi, DispatchMessage getMSG: push 0 push 0 push 0 push ebp call esi test eax, eax je short progEXIT push ebp call ebx push ebp call edi jmp short getMSG progEXIT: push 0 call dword ptr ExitProcess } } //int WINAPI WinMain(HINSTANCE hinst, HINSTANCE x, LPSTR y, int z) //{ // MSG messages; // HWND hwnd; // InitCommonControls(); // fond = CreateSolidBrush(RGB(236,233,216)); // hwnd = InitInstance(hinst); // if(!hwnd) return 0; // ShowWindow(hwnd, SW_SHOW); // while(GetMessage(&messages, 0, 0, 0)) { // TranslateMessage(&messages); // DispatchMessage(&messages); // } // DeleteObject(fond); // return 0; //}

Conclusion :


sera encore et encore mis a jour prochainement selon vos commantaire !
pour me suggerer quelque amelioration n'oublier pas les Message Prive et mon email : Jean_guis (AT) hotmail.com
Bon coding :)

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.