Mega Code Archive

 
Categories / Delphi / System
 

Resource Meter for Windows 9598ME

Title: Resource Meter for Windows 95/98/ME Question: How do i get the System, User, GDI resources for Windows 95/98/ME? Answer: (******************************************************************************) (* *) (* Unit Name : ResMeter.pas *) (* Unit Version : 1.0.3.7 *) (* Author : Chua Wen Kiat *) (* Website : http://www.geocities.com/chuawenkiat/resmeter *) (* Email : chuawenkiat@hotmail.com *) (* *) (******************************************************************************) unit ResMeter; interface uses Windows, SysUtils; function GetSystemResources: Integer; function GetGDIResources: Integer; function GetUserResources: Integer; function RunningLowOnResources: Boolean; implementation {***************************************************************} var hKernel32Dll: HWND; _QT_Thunk: procedure; cdecl; hUserExe: HWND; _GetFreeSystemResources: function(const nResourceType: Word): Word; stdcall; function _LoadLibrary16(pLibraryName: PChar): HWND; stdcall; external kernel32 index 35; procedure _FreeLibrary16(hInstance: HWND); stdcall; external kernel32 index 36; function _GetProcAddress16(hInstance: HWND; pProcName: PChar): Pointer; stdcall; external kernel32 index 37; function GetFreeSystemResources(const nResourceType: Word): Integer; var arrThunk: array[0..32] of Word; nFreeSystemResources: Word; begin Result := -1; if Win32Platform VER_PLATFORM_WIN32_NT then begin if Assigned(_GetFreeSystemResources) then begin arrThunk[0] := hUserExe; asm push nResourceType mov edx, _GetFreeSystemResources call _QT_Thunk mov nFreeSystemResources, ax end; Result := nFreeSystemResources; end; end; end; function GetSystemResources; begin Result := GetFreeSystemResources(0); end; function GetGDIResources; begin Result := GetFreeSystemResources(1); end; function GetUserResources; begin Result := GetFreeSystemResources(2); end; function RunningLowOnResources; const MINIMUMRESOURCES = 10; var nSystemResources, nGDIResources, nUserResources: Integer; begin Result := False; if Win32Platform VER_PLATFORM_WIN32_NT then begin nSystemResources := GetSystemResources; nGDIResources := GetGDIResources; nUserResources := GetUserResources; Result := ((nSystemResources -1)) or ((nGDIResources -1)) or ((nUserResources -1)); end; end; initialization begin if Win32Platform VER_PLATFORM_WIN32_NT then begin hKernel32Dll := LoadLibrary(kernel32); if hKernel32Dll 0 then begin @_QT_Thunk := GetProcAddress(hKernel32Dll, 'QT_Thunk'); if Assigned(_QT_Thunk) then begin hUserExe := _LoadLibrary16('user.exe'); if hUserExe = 32 then @_GetFreeSystemResources := _GetProcAddress16(hUserExe, 'GetFreeSystemResources'); end; end; end; end; finalization begin if Win32Platform VER_PLATFORM_WIN32_NT then begin if hKernel32Dll 0 then begin if hUserExe = 32 then _FreeLibrary16(hUserExe); FreeLibrary(hKernel32Dll); end; end; end; end.