Leadtools.Wia Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
GetRootItem Method
See Also  Example
Leadtools.Wia Namespace > WiaSession Class : GetRootItem Method



item
Handle to the item which represents the item for which you wish to retrieve its root item. You can retrieve this parameter by either calling the WiaSession.GetRootItem method to get the device’s root item itself or by enumerating the child items of the device through a call to EnumChildItems method.
item
Handle to the item which represents the item for which you wish to retrieve its root item. You can retrieve this parameter by either calling the WiaSession.GetRootItem method to get the device’s root item itself or by enumerating the child items of the device through a call to EnumChildItems method.
Gets the equivalent string for the passed property ID.

Syntax

Visual Basic (Declaration) 
Public Sub GetRootItem( _
   ByVal item As Object _
) 
Visual Basic (Usage)Copy Code
Dim instance As WiaSession
Dim item As Object
 
instance.GetRootItem(item)
C# 
public void GetRootItem( 
   object item
)
C++/CLI 
public:
void GetRootItem( 
   Object^ item
) 

Parameters

item
Handle to the item which represents the item for which you wish to retrieve its root item. You can retrieve this parameter by either calling the WiaSession.GetRootItem method to get the device’s root item itself or by enumerating the child items of the device through a call to EnumChildItems method.

Example

Visual BasicCopy Code
Dim wiaSession As WiaSession
Public Sub GetRootItemExample(ByVal parent As IWin32Window)
   If (Not WiaSession.IsAvailable(WiaVersion.Version1)) Then
      MessageBox.Show("WIA version 1.0 not installed.")
      Return
   End If

   wiaSession = New WiaSession()
   wiaSession.Startup(WiaVersion.Version1)

   Dim res As DialogResult = wiaSession.SelectDeviceDlg(parent, WiaDeviceType.Default, WiaSelectSourceFlags.NoDefault)
   If res <> DialogResult.OK Then
      MessageBox.Show("Error selecting WIA device.")
      wiaSession.Shutdown()
      Return
   End If

   wiaSession.GetRootItem(Nothing)
   If Not wiaSession.RootItem Is Nothing Then
      AddHandler wiaSession.EnumItemsEvent, AddressOf session_EnumItemsEvent

      wiaSession.EnumChildItems(wiaSession.RootItem)

      RemoveHandler wiaSession.EnumItemsEvent, AddressOf session_EnumItemsEvent
   End If

   wiaSession.Shutdown()
End Sub

Private Sub session_EnumItemsEvent(ByVal sender As Object, ByVal e As WiaEnumItemsEventArgs)
   If Not e.Item Is Nothing Then
      Dim properties As WiaProperties = WiaProperties.Empty
      Dim dataTransfer As WiaDataTransferProperties = WiaDataTransferProperties.Empty
      Dim imageEffects As WiaImageEffectsProperties = WiaImageEffectsProperties.Empty

      wiaSession.GetProperties(e.Item)
      properties = wiaSession.Properties

      properties.MaximumNumberOfPages = 0 ' scan all pages in feeder
      dataTransfer.ImageDataType = WiaImageDataType.Grayscale
      imageEffects.Brightness = 250

      properties.DataTransfer = dataTransfer
      properties.ImageEffects = imageEffects
      wiaSession.Properties = properties

      AddHandler wiaSession.SetPropertiesEvent, AddressOf session_SetPropertiesEvent

      wiaSession.SetProperties(e.Item)

      RemoveHandler wiaSession.SetPropertiesEvent, AddressOf session_SetPropertiesEvent

      wiaSession.FreeItem(e.Item)
   End If
End Sub

Private Sub session_SetPropertiesEvent(ByVal sender As Object, ByVal e As WiaSetPropertiesEventArgs)
   If e.Error <= 0 Then
      Console.WriteLine("Failed to set the below property:" & Constants.vbLf + Constants.vbTab & "Property Id: {0}" & Constants.vbLf + Constants.vbTab & "Property Value: {1}" & Constants.vbLf + Constants.vbTab & "Error: {2}" & Constants.vbLf + Constants.vbLf, e.PropertyId.ToString(), Convert.ToInt32(e.Value).ToString(), e.Error.ToString())
   End If
End Sub
C#Copy Code
WiaSession wiaSession; 
public void GetRootItemExample(IWin32Window parent) 

   if (!WiaSession.IsAvailable(WiaVersion.Version1)) 
   { 
      MessageBox.Show("WIA version 1.0 not installed."); 
      return; 
   } 
 
   wiaSession = new WiaSession(); 
   wiaSession.Startup(WiaVersion.Version1); 
 
   DialogResult res = wiaSession.SelectDeviceDlg(parent, WiaDeviceType.Default, WiaSelectSourceFlags.NoDefault); 
   if (res != DialogResult.OK) 
   { 
      MessageBox.Show("Error selecting WIA device."); 
      wiaSession.Shutdown(); 
      return; 
   } 
 
   wiaSession.GetRootItem(null); 
   if (wiaSession.RootItem != null) 
   { 
      wiaSession.EnumItemsEvent += new EventHandler<WiaEnumItemsEventArgs>(wiaSession_EnumItemsEvent); 
 
      wiaSession.EnumChildItems(wiaSession.RootItem); 
 
      wiaSession.EnumItemsEvent -= new EventHandler<WiaEnumItemsEventArgs>(wiaSession_EnumItemsEvent); 
   } 
 
   wiaSession.Shutdown(); 

 
void wiaSession_EnumItemsEvent(object sender, WiaEnumItemsEventArgs e) 

   if(e.Item != null) 
   { 
      WiaProperties properties = WiaProperties.Empty; 
      WiaDataTransferProperties dataTransfer = WiaDataTransferProperties.Empty; 
      WiaImageEffectsProperties imageEffects = WiaImageEffectsProperties.Empty; 
 
      wiaSession.GetProperties(e.Item); 
      properties = wiaSession.Properties; 
 
      properties.MaximumNumberOfPages = 0;   // scan all pages in feeder 
      dataTransfer.ImageDataType = WiaImageDataType.Grayscale; 
      imageEffects.Brightness = 250; 
 
      properties.DataTransfer = dataTransfer; 
      properties.ImageEffects = imageEffects; 
      wiaSession.Properties = properties; 
 
      wiaSession.SetPropertiesEvent += new EventHandler<WiaSetPropertiesEventArgs>(wiaSession_SetPropertiesEvent); 
 
      wiaSession.SetProperties(e.Item); 
 
      wiaSession.SetPropertiesEvent -= new EventHandler<WiaSetPropertiesEventArgs>(wiaSession_SetPropertiesEvent); 
 
      wiaSession.FreeItem(e.Item); 
   } 

 
void wiaSession_SetPropertiesEvent(object sender, WiaSetPropertiesEventArgs e) 

   if(e.Error <= 0) 
   { 
      Console.WriteLine("Failed to set the below property:\n\tProperty Id: {0}\n\tProperty Value: {1}\n\tError: {2}\n\n", e.PropertyId.ToString(), Convert.ToInt32(e.Value).ToString(), e.Error.ToString()); 
   } 
}

Remarks

Gets the root item for the item passed through the item parameter. If item parameters is null then the retrieved item will be the devices root item (which represents the device itself). This is the first function you need to call to get a handle to the devices root item. Then pass that handle to the EnumChildItems method to enumerate all of the devices child items. Then call this function again for any child item of the enumerated items to retrieve its root item if needed.

After calling this method the RootItem property will be updated with the root item for the item you passed through the item parameter and then you can use this property as the root item handle.

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows 2000, Windows XP, Windows Vista, Windows Server 2003 family, Windows Server 2008 family

See Also