Пример #1
0
        // Handles the device discovery event
        public void DeviceFound(object sender, IntPtr pDev)
        {
            // Marshal interface to the current thread
            IUPnPDevice device = (IUPnPDevice)Marshal.GetObjectForIUnknown(pDev);

            Debug.WriteLine("Found device: " + device.FriendlyName);

            // Check if the device already in the list
            // Devices are compared by UniqueDeviceName
            foreach (ListViewItem item in lvDevices.Items)
            {
                if ((item.Tag as IUPnPDevice).UniqueDeviceName == device.UniqueDeviceName)
                {
                    Debug.WriteLine("Already known");
                    return;
                }
            }

            // Get device icon
            // For simplicity we always ask for a 64x64 icon
            string url;

            Debug.WriteLine("Getting icon");
            int   ret     = device.IconURL("image/png", 64, 64, 16, out url);
            Image imgIcon = new Bitmap(64, 64);

            if (ret == 0 && url != null)
            {
                imgIcon = GetIcon(url);
            }
            Debug.WriteLine("Adding");
            il.Images.Add(imgIcon);
            ListViewItem newItem = new ListViewItem(device.FriendlyName);

            newItem.Tag        = device;
            newItem.ImageIndex = il.Images.Count - 1;
            lvDevices.Items.Add(newItem);
            _evtDeviceFound.Set();
        }
Пример #2
0
 /// <summary>
 /// Gets the URL for an icon for this device.
 /// </summary>
 /// <param name="encodingFormat">The MIME type of the encoding format that is requested for the icon.</param>
 /// <param name="sizeX">Specifies the width of the icon, in pixels. Standard values are 16, 32, or 48.</param>
 /// <param name="sizeY">Specifies the height of the icon, in pixels. Standard values are 16, 32, or 48 pixels.</param>
 /// <param name="bitDepth">Specifies the bit depth of the icon. Standard values are 8, 16, or 24.</param>
 /// <returns>A string representing the URL for the icon.</returns>
 /// <remarks>
 /// An application can specify any values for lSizeX, lSizeY, and lBitDepth. However, there is no
 /// guarantee that an icon exists with those specifications. If a matching icon does not exist,
 /// the URL for the icon that most closely matches the size and bit depth specified is returned.
 /// </remarks>
 public string GetIconURL(string encodingFormat, int sizeX, int sizeY, int bitDepth)
 {
     return(COMDevice.IconURL(encodingFormat, sizeX, sizeY, bitDepth));
 }