Hi,
you can use the next C# code using the APIs of your OS.
Yo'll have to change it to VB.NET.
I'm sorry, some comments are in Spanish.
const uint DRIVE_UNKNOWN = 0;
const uint DRIVE_NO_ROOT_DIR = 1;
const uint DRIVE_REMOVABLE = 2;
const uint DRIVE_FIXED = 3;
const uint DRIVE_REMOTE = 4;
const uint DRIVE_CDROM = 5;
const uint DRIVE_RAMDISK = 6;
Icon Ico0 = new Icon("Indet.ico");
Icon Ico1 = new Icon("NoDisp.ico");
Icon Ico2 = new Icon("Disquete.ico");
Icon Ico3 = new Icon("Hard.ico");
Icon Ico4 = new Icon("Red.ico");
Icon Ico5 = new Icon("CDR.ico");
Icon Ico6 = new Icon("Ram.ico");
private string Unidad;
[DllImport("Kernel32.dll")] public static extern uint GetDriveType(string
lpRootPathName);
private void cboDrives_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{
e.DrawBackground();
e.DrawFocusRectangle();
if(e.Index < 0) return;
Rectangle rect = new Rectangle( 3, e.Bounds.Top +3 , e.Bounds.Height,
e.Bounds.Height -3);
Rectangle rectInt = new Rectangle( 1, e.Bounds.Top + 1, e.Bounds.Width-1,
e.Bounds.Height - 1);
e.Graphics.DrawRectangle(Pens.White, rectInt);
Font f = new Font("Verdana",8);
string textoItem = cboDrives.Items[e.Index].ToString();
Unidad = textoItem.Substring(0,textoItem.Length-1);
switch (GetDriveType(textoItem))
{
case DRIVE_UNKNOWN:
e.Graphics.DrawIcon(Ico0,rect);
textoItem =Unidad + " - Unidad desconocida";
break;
case DRIVE_NO_ROOT_DIR:
e.Graphics.DrawIcon(Ico1,rect);
textoItem =Unidad + " - Unidad no disponible";
break;
case DRIVE_REMOVABLE:
e.Graphics.DrawIcon(Ico2,rect);
textoItem =Unidad + " - (Disquete)";
break;
case DRIVE_FIXED:
e.Graphics.DrawIcon(Ico3,rect);
textoItem = Unidad + " - (Disco Duro)";
break;
case DRIVE_REMOTE:
e.Graphics.DrawIcon(Ico4,rect);
textoItem = Unidad + " - (Unidad de Red)";
break;
case DRIVE_CDROM:
e.Graphics.DrawIcon(Ico5,rect);
textoItem = Unidad + " - (CD-ROM)";
break;
case DRIVE_RAMDISK:
e.Graphics.DrawIcon(Ico6,rect);
textoItem = Unidad + " - (Disco RAM)";
break;
}
this.Text = e.State.ToString();
if((e.State & DrawItemState.Selected) != 0)
{
e.Graphics.DrawRectangle(Pens.DarkCyan,rectInt);
e.Graphics.DrawString(textoItem, f , Brushes.White,
e.Bounds.Height + 5, ((e.Bounds.Height - f.Height) / 2) + e.Bounds.Top);
return;
}
else
{
e.Graphics.DrawString(textoItem, f , Brushes.Black, e.Bounds.Height + 5,
((e.Bounds.Height - f.Height) / 2) + e.Bounds.Top);
}
}
I hope that helps.
Kind regards,
Jorge Serrano Pérez
MVP VB.NET
notregister said:
how do u get the devicenames if i have several usb device connected to an usb
hub?
will it be any different if i several printer connected to an ethernet
router? if there are, how can i get the device names?