Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
487 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (1)


Resource Meter for Windows 95/98/MEComponent available for this articleFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi all versions
Category:
System
Skill Level:
Scoring:
Last Update:
10/05/2001
Search Keys:
delphi delphi3000 article borland vcl code-snippet resmeter system-resource resource-meter system user gdi
Times Scored:
3
Visits:
3087
Uploader: Wen Kiat Chua
Company:
Reference: http://www.geocities.com/chuawenkiat
Component Download: http://www.geocities.com/chuawenkiat/resmeter/resmeter.pas.txt
 
Question/Problem/Abstract:
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 <= MINIMUMRESOURCES) and (nSystemResources > -1)) or ((nGDIResources <= MINIMUMRESOURCES) and (nGDIResources > -1)) or ((nUserResources <= MINIMUMRESOURCES) and (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.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
How about Windows 2000?
    Hugo Ribeiro (Dec 25 2001 2:36PM)

How can find when Windows 2000 is running low on "GDI objects"?
I have an application that creates and adds LOTS of icons to a list view. After creating something over 9000 GDI Objects (as seen in task manager) it crashes. How can I prevent this?
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
E. Irigoyen
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)