2010-10-11 5 views
4

Comment puis-je obtenir les propriétés de mon moniteur? Je suis surtout intéressé par le nom du fabricant et le type de modèle. Je ne veux pas non plus l'obtenir du registre. (Certains PC comme mon PC de travail ont un accès restreint à la clé de propriété, donc je préférerais scanner un bus système ou autre chose que le reg.)Delphi7: Obtenir les propriétés du moniteur en pièce jointe

Des idées? Merci SoulBlade

+0

Hi. Cette question est-elle liée au DPI? – Ampere

Répondre

4

essayez d'utiliser la classe Win32_DesktopMonitor WMI. cette classe a toutes les informations que vous cherchez.

vérifiez cet exemple de code.

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.