System info

Get printer drivers directory

Posted in System info

Use GetPrinterDriverDirectory function for solving of this problem. Don't forget include WinSpoon to uses chapter.

uses WinSpool;
... 
procedure TForm1.Button1Click(Sender: TObject);
var
  NewDevMode: TDeviceModeA;
  MyDir: PChar;
  Int: Integer;
begin
  GetMem(MyDir, 500);
  GetPrinterDriverDirectory(nil, nil, 1, MyDir, 200, Int);
  Label1.Caption:=StrPas(MyDir);
  FreeMem(MyDir);
end;

Get power status

Posted in System info

-Use GetSystemPowerStatus function and SYSTEM_POWER_STATUS structure.

procedure TForm1.Button1Click(Sender: TObject);
var
  PowerStatus: TSystemPowerStatus;
begin
  GetSystemPowerStatus(PowerStatus);
  if PowerStatus.ACLineStatus=1 then
    Label1.Caption:='AC power online'
  else Label1.Caption:='AC power offline';
end;

Get paper source

Posted in System info

Use DevMode structure to detect paper source.

uses Printers;
...
procedure TForm1.Button2Click(Sender: TObject);
var
  Device: array[0..cchDevicename-1] of Char;
  Driver: array[0..(MAX_PATH)-1] of Char;
  Port: array[0..32] of Char;
  hDMode: THandle;
  pDMode: PDevMode;
begin
  Printer.GetPrinter(Device, Driver, Port, hDMode);
  if (hDMode<>0) then
  begin
    pDMode:=GlobalLock(hDMode);
    if pDMode<>nil then
    begin
      if (pDMode^.dmDefaultSource=7) then
        Label1.Caption:='Paper source - auto';
      if (pDMode^.dmDefaultSource=4) then
        Label1.Caption:='Paper source - manual';
    end;
  end;
end;

Get number of system colors

Posted in System info

Use GetDisplayColors function for this problem. This function returns number of bits on point of screen. For example, 16-65535, 8-256, 4-16.

function GetDisplayColors: integer;
var 
  tHDC: hdc;
begin
  tHDC:=GetDC(0);
  Result:=GetDeviceCaps(tHDC, 12)*GetDeviceCaps(tHDC, 14);
  ReleaseDC(0, tHDC);
end;

Get module filename of current process

Posted in System info

The GetModuleFileName function retrieves the full path and filename for the executable file containing the specified module.

procedure TForm1.Button1Click(Sender: TObject);
var
  FileName: array[0..128] of Char;
begin
  GetModuleFileName(hInstance, FileName, 128);
  Label1.Caption := FileName;
end;