Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: WinAPI и системное программирование > Определение Wia-устройств (сканеров, камер)


Автор: MadCoder 13.4.2009, 18:01
Здравствуйте!

Подскажите, как опредилить, подключено ли к компьютеру какое-либо устройство ввода видеоизображения (WIA), например сканер или камера. smile 

Автор: Rrader 14.4.2009, 10:32
Посмотри, вдруг поможет smile 
Код

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ActiveX, StdCtrls, ComObj;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  WiaFlag = TOleEnum;
  WiaIntent = TOleEnum;
  WiaItemPropertyId = TOleEnum;
  WiaDeviceInfoPropertyId = TOleEnum;

  ICollection = interface(IDispatch)
    ['{C34C8CE7-B253-4F89-AA25-8A24AD71D0C0}']
    function Get_Item(Index: Integer): IDispatch; safecall;
    function Get_Count: Integer; safecall;
    function Get_Length: LongWord; safecall;
    function Get__NewEnum: IUnknown; safecall;
    property Item[Index: Integer]: IDispatch read Get_Item; default;
    property Count: Integer read Get_Count;
    property Length: LongWord read Get_Length;
    property _NewEnum: IUnknown read Get__NewEnum;
  end;

  IWiaDispatchItem = interface(IDispatch)
    ['{D06D503F-4B71-40F3-94A7-66478F732BC9}']
    function Get_ConnectStatus: WideString; safecall;
    function Get_Time: WideString; safecall;
    function Get_FirmwareVersion: WideString; safecall;
    function GetItemsFromUI(Flags: WiaFlag;
      Intent: WiaIntent): ICollection; safecall;
    procedure Transfer(const Filename: WideString;
      AsyncTransfer: WordBool); safecall;
    function TakePicture: IWiaDispatchItem; safecall;
    function Get_Name: WideString; safecall;
    function Get_FullName: WideString; safecall;
    function Get_ItemType: WideString; safecall;
    function Get_Width: Integer; safecall;
    function Get_Height: Integer; safecall;
    function Get_ThumbWidth: Integer; safecall;
    function Get_ThumbHeight: Integer; safecall;
    function Get_Thumbnail: WideString; safecall;
    function Get_PictureHeight: Integer; safecall;
    function Get_PictureWidth: Integer; safecall;
    function Get_Children: ICollection; safecall;
    function GetPropById(Id: WiaItemPropertyId): OleVariant; safecall;
    property ConnectStatus: WideString read Get_ConnectStatus;
    property Time: WideString read Get_Time;
    property FirmwareVersion: WideString read Get_FirmwareVersion;
    property Name: WideString read Get_Name;
    property FullName: WideString read Get_FullName;
    property ItemType: WideString read Get_ItemType;
    property Width: Integer read Get_Width;
    property Height: Integer read Get_Height;
    property ThumbWidth: Integer read Get_ThumbWidth;
    property ThumbHeight: Integer read Get_ThumbHeight;
    property Thumbnail: WideString read Get_Thumbnail;
    property PictureHeight: Integer read Get_PictureHeight;
    property PictureWidth: Integer read Get_PictureWidth;
    property Children: ICollection read Get_Children;
  end;

  IWiaDeviceInfo = interface(IDispatch)
    ['{5267FF5E-7CAF-4769-865D-17A25968525E}']
    function Create: IWiaDispatchItem; safecall;
    function Get_Id: WideString; safecall;
    function Get_Name: WideString; safecall;
    function Get_type_: WideString; safecall;
    function Get_Port: WideString; safecall;
    function Get_UIClsid: WideString; safecall;
    function Get_Manufacturer: WideString; safecall;
    function GetPropById(Id: WiaDeviceInfoPropertyId): OleVariant; safecall;
    property Id: WideString read Get_Id;
    property Name: WideString read Get_Name;
    property type_: WideString read Get_type_;
    property Port: WideString read Get_Port;
    property UIClsid: WideString read Get_UIClsid;
    property Manufacturer: WideString read Get_Manufacturer;
  end;

  IWia = interface(IDispatch)
    ['{B10BA1BC-3713-4EC0-8EEA-690EBD2CED8A}']
    function Get_Devices: ICollection; safecall;
    function Create(var Device: OleVariant): IWiaDispatchItem; safecall;
    procedure _DebugDialog(fWait: Integer); safecall;
    property Devices: ICollection read Get_Devices;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
const
  CLASS_Wia: TGUID = '{4EC4272E-2E6F-4EEB-91D0-EBC4D58E8DEE}';
  IID_IWia: TGUID = '{B10BA1BC-3713-4EC0-8EEA-690EBD2CED8A}';
  FmtStr = 'Тип устройства: %s' + sLineBreak +
    'Название устройства: %s' + sLineBreak +
    'Производитель: %s' + sLineBreak +
    'Порт: %s';
var
  Wia: IWia;
  Devs: ICollection;
  I: Integer;
  Device: OleVariant;
  S: String;
begin
  if Succeeded(CoInitialize(nil)) then
  try
    Wia := CreateComObject(CLASS_Wia) as IWia;
    Devs := Wia.Devices;
    for I := 0 to Devs.Length - 1 do
      with (Devs.Item[I] as IWiaDeviceInfo) do
      begin
        ShowMessage(Format(FmtStr, [type_, Name, Manufacturer, Port]));
        Device := Devs.Item[I];
        S := Wia.Create(Device).ItemType;
        ShowMessage('Флаги: ' + S);
        Device := Unassigned;
      end;
  finally
    CoUninitialize;
  end;
end;

end.

Автор: MadCoder 14.4.2009, 15:12
Спасибо, вечером попробую smile .

Автор: Bogdan2004 25.8.2010, 11:26
Добрый день!
  Подскажите как добраться до Thumbnail фотографии в фотокамере?

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)