Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   Uso del CPU en 9x (https://www.clubdelphi.com/foros/showthread.php?t=80832)

cHackAll 12-08-2007 01:47:22

Uso del CPU en 9x
 
Código Delphi [-]
uses Windows;
begin
 _lwrite(_lcreat('cpu.res', 0), PChar(#0#0#0#0#32#0#0#0#$FF#$FF#0#0#$FF#$FF#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#40#1#0#0#32#0#0#0#$F  F#$FF#3#0#$FF#$FF#1#0#0#0#0#0#16+
                                      #16#10#64#0#0#0#0#0#0#0#0#40#0#0#0#16#0#0#0#32#0#0#0#1#0#4#0#0#0#0#0#$C0#0#0#0#0#0#0#0#0#0#0#0#0#0#0  #0#0#0#0#0#0#0#0#0#0#0#$80+
 {  Ésta "línea" de código crea el  } #0#0#$80#0#0#0#$80#$80#0#$80#0#0#0#$80#0#$80#0#$80#$80#0#0#$80#$80#$80#0#$C0#$C0#$C0#0#0#0#$FF#0#0#$  FF#0#0#0#$FF#$FF#0#$FF#0#0+
 { recurso necesario para compilar  } #0#$FF#0#$FF#0#$FF#$FF#0#0#$FF#$FF#$FF#0#2#34#34#34#34#34#34#32#0#32#32#32#32#32#32#32#2#34#34#34#34  #34#34#32#0#32#32#32#32#32+
 { el medidor de uso del CPU. Para  } #32#32#2#34#34#34#34#34#34#32#0#32#32#32#32#32#32#32#2#34#34#34#34#34#34#32#0#32#32#32#32#32#32#32#2  #34#34#34#34#34#34#32#0#32+
 { ambos casos, se debe copiar su   } #32#32#32#32#32#32#2#34#34#34#34#34#34#32#0#32#32#32#32#32#32#32#2#34#34#34#34#34#34#32#0#32#32#32#3  2#32#32#32#2#34#34#34#34#34+
 { "contenido" en un archivo nuevo  } #34#32#0#32#32#32#32#32#32#32#$80#1#0#0#$80#1#0#0#$80#1#0#0#$80#1#0#0#$80#1#0#0#$80#1#0#0#$80#1#0#0#  $80#1#0#0#$80#1#0#0#$80#1#0+
 { con extensión ".dpr"             } #0#$80#1#0#0#$80#1#0#0#$80#1#0#0#$80#1#0#0#$80#1#0#0#$80#1#0#0#20#0#0#0#32#0#0#0#$FF#$FF#14#0#$FF#$F  F#$64#0#0#0#0#0#16#16#10#64+
                                      #0#0#0#0#0#0#0#0#0#0#1#0#1#0#16#16#16#0#1#0#4#0#40#1#0#0#1#0), $19C);
end.

cpu, es un pequeño programita que nació para imitar lo que más me llamaba la atención del "Administrador de tareas" del Güindos eQuispe en 9x. El mayor logro en el mismo fue poder utilizar 16 iconos diferentes sin la necesidad de "incrustar" 16 iconos en la aplicación. El método de verificación de versión del S.O. también fue una innovación en la época en que ignoraba que Microsoft ya no daba soporte a estos DinosauriOS.

Código Delphi [-]
uses Windows, ShellAPI, Types; {$r cpu.res} {$warnings off} // 050216

function RegisterServiceProcess(Address: Pointer): Cardinal;
asm
 mov   ecx, eax
 jecxz @IsNT
 push  01h
 call  GetCurrentProcessID
 push  eax
 call  ecx
@IsNT:
end;

var
 Dummy, Canvas: Cardinal;
 Saved: Cardinal = $00000010;
 IconInfo: TIconInfo;
 Icons: array[0..15] of HICON;
 TrayIcon: TNotifyIconData = (cbSize: SizeOf(TNotifyIconData); uFlags: NIF_ICON);
 hKey: Windows.HKEY;

function GetCPUUsage: Cardinal;
var Size: Cardinal;
begin
 Size := SizeOf(Result);
 RegQueryValueEx(hKey, 'KERNEL\CPUUsage', nil, nil, @Result, @Size);
end;

procedure RegOpenKey(const lpSubKey: PChar);
begin
 RegCloseKey(hKey);
 RegOpenKeyEx(HKEY_DYN_DATA, lpSubKey, 0, KEY_READ, hKey);
 GetCPUUsage;
end;

begin
 CreateMutex(nil, True, 'cpu');
 if (GetLastError = ERROR_ALREADY_EXISTS) or (RegisterServiceProcess(GetProcAddress(GetModuleHandle('kernel32.dll'), 'RegisterServiceProcess')) = 0) then Exit;

 Dummy := GetDC(0);
 Canvas := CreateCompatibleDC(Dummy);
 ReleaseDC(0, Dummy);

 Icons[0] := LoadIcon(hInstance, MAKEINTRESOURCE(100));
 GetIconInfo(Icons[0], IconInfo);
 SelectObject(Canvas, IconInfo.hbmColor);
 Dummy := CreateSolidBrush(RGB(0, 255, 0));
 repeat Dec(Saved);
  FillRect(Canvas, Rect(2, (Saved * 2) + 1, 30, 32), Dummy);
  Icons[16 - Saved] := CreateIconIndirect(IconInfo);
 until Saved = 0;

 TrayIcon.hIcon := Icons[0];
 TrayIcon.Wnd := FindWindow('Shell_TrayWnd', nil);
 Shell_NotifyIcon(NIM_ADD, @TrayIcon);

 RegOpenKey('PerfStats\StartStat');
 RegOpenKey('PerfStats\StatData');
 repeat Sleep(250);
  Dummy := GetCPUUsage div 6;
  if Saved <> Dummy then
   begin
    Saved := Dummy;
    TrayIcon.hIcon := Icons[Dummy];
    Shell_NotifyIcon(NIM_MODIFY, @TrayIcon);
   end;
 until FindWindow('Shell_TrayWnd', nil) = 0;
 RegOpenKey('PerfStats\StopStat');
 RegCloseKey(hKey);
end.


La franja horaria es GMT +2. Ahora son las 10:40:06.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi