Delphi7:获取附加的监视器属性 [英] Delphi7: Get attached monitor properties

查看:208
本文介绍了Delphi7:获取附加的监视器属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取显示器的属性?我对制造商名称和型号类型最感兴趣.我也不想从注册表中获取它. (某些PC像我的工作PC一样,限制了对属性密钥的访问,因此我宁愿扫描系统总线或除reg外的其他东西.)

How do I get my monitor's properties? I'm mostly interested in the manufacturer name and model type. I also don't want to get it from the registry. (Some PC's like my work PC has restricted access to the property key so I'd rather want to scan a system bus or something other than the reg.)

有什么想法吗? 谢谢SoulBlade

Any ideas? Thanks SoulBlade

推荐答案

尝试使用

try using the Win32_DesktopMonitor WMI Class. this class have all the information wich you are looking.

检查此示例代码.

program GetWMI_MonitorInfo;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  ActiveX,
  ComObj,
  Variants;

function VarStrNull(VarStr:OleVariant):string;//dummy function to handle null variants
begin
  Result:='';
  if not VarIsNull(VarStr) then
  Result:=VarToStr(VarStr);
end;


procedure  GetMonitorInfo;
var
  objWMIService : OLEVariant;
  colItems      : OLEVariant;
  colItem       : OLEVariant;
  oEnum         : IEnumvariant;
  iValue        : LongWord;

  function GetWMIObject(const objectName: String): IDispatch;
  var
    chEaten: Integer;
    BindCtx: IBindCtx;
    Moniker: IMoniker;
  begin
    OleCheck(CreateBindCtx(0, bindCtx));
    OleCheck(MkParseDisplayName(BindCtx, StringToOleStr(objectName), chEaten, Moniker));
    OleCheck(Moniker.BindToObject(BindCtx, nil, IDispatch, Result));
  end;

begin
  objWMIService := GetWMIObject('winmgmts:\\localhost\root\CIMV2');
  colItems      := objWMIService.ExecQuery('SELECT * FROM Win32_DesktopMonitor','WQL',0);
  oEnum         := IUnknown(colItems._NewEnum) as IEnumVariant;
  if oEnum.Next(1, colItem, iValue) = 0 then
  begin
    Writeln('Caption      '+VarStrNull(colItem.Caption));
    Writeln('Description  '+VarStrNull(colItem.Description));
    Writeln('Device ID    '+VarStrNull(colItem.DeviceID));
    Writeln('Manufacturer '+VarStrNull(colItem.MonitorManufacturer));//Manufacter
    Writeln('Type         '+VarStrNull(colItem.MonitorType));//Model
  end;

end;


begin
 try
    CoInitialize(nil);
    try
      GetMonitorInfo;
      Readln;
    finally
    CoUninitialize;
    end;
 except
    on E:Exception do
    Begin
        Writeln(E.Classname, ': ', E.Message);
        Readln;
    End;
  end;
end.

这篇关于Delphi7:获取附加的监视器属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆