473,500 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get Class ImageList

Hi,
How can I get the System class ImageList from C# application, I want to
receive this image list used in device manager ?
I find a C API :

WINSETUPAPI BOOL WINAPI
SetupDiGetClassImageList(
OUT PSP_CLASSIMAGELIST_DATA ClassImageListData);

How I can call this API from C# ?

Thanks
Joe
Sep 3 '06 #1
6 5263

"[Joe]" <Jo*@discussions.microsoft.comwrote in message
news:15**********************************@microsof t.com...
| Hi,
| How can I get the System class ImageList from C# application, I want to
| receive this image list used in device manager ?
| I find a C API :
|
| WINSETUPAPI BOOL WINAPI
| SetupDiGetClassImageList(
| OUT PSP_CLASSIMAGELIST_DATA ClassImageListData);
|
| How I can call this API from C# ?
|
| Thanks
| Joe

Not sure why you ever wanna use this from C# but here it goes:

[DllImport("setupapi.dll")]
static extern int SetupDiGetClassImageList(out PSP_CLASSIMAGE_DATA
ClassImageList);

public struct PSP_CLASSIMAGE_DATA {
public uint cbSize; // size of this struct
public IntPtr ImageList; // Handle
public uint Reserved;
}

don't forget to destroy the list when done (see
SetupDiDestroyClassImageList).

Willy.
Sep 3 '06 #2
Hello Willy,
Thanks this was very helpful , I still don't know how to convert this
handle to System.Windows.Forms.ImageList ?? , I watch in the Marshal class
but didn't figure how to do that. I will be so happy if you can help me also
in this issue .

Regards,
Joe

"Willy Denoyette [MVP]" wrote:
>
"[Joe]" <Jo*@discussions.microsoft.comwrote in message
news:15**********************************@microsof t.com...
| Hi,
| How can I get the System class ImageList from C# application, I want to
| receive this image list used in device manager ?
| I find a C API :
|
| WINSETUPAPI BOOL WINAPI
| SetupDiGetClassImageList(
| OUT PSP_CLASSIMAGELIST_DATA ClassImageListData);
|
| How I can call this API from C# ?
|
| Thanks
| Joe

Not sure why you ever wanna use this from C# but here it goes:

[DllImport("setupapi.dll")]
static extern int SetupDiGetClassImageList(out PSP_CLASSIMAGE_DATA
ClassImageList);

public struct PSP_CLASSIMAGE_DATA {
public uint cbSize; // size of this struct
public IntPtr ImageList; // Handle
public uint Reserved;
}

don't forget to destroy the list when done (see
SetupDiDestroyClassImageList).

Willy.
Sep 4 '06 #3

"[Joe]" <Jo*@discussions.microsoft.comwrote in message
news:9E**********************************@microsof t.com...
| Hello Willy,
| Thanks this was very helpful , I still don't know how to convert
this
| handle to System.Windows.Forms.ImageList ?? , I watch in the Marshal class
| but didn't figure how to do that. I will be so happy if you can help me
also
| in this issue .
|

That's what I was affraid of, Forms.ImageList is a class while the
setupapi.dll API returns a Handle, there is no way to convert this to an
ImageList nor to contruct an ImageList from a Handle. The setup library is
not meant for general consumption, it is meant to be used to build your own
device setup applications (using C++) using your own image lists. If you are
trying to implement device installers using C# you will have a hard time as
you'll have to use all API's in the set. If you are only trying to use the
images in the setupapi.dll ,you only have to call SetupDiDrawMiniIcon using
this import definition:

[DllImport("setupapi.dll")]
static extern int SetupDiDrawMiniIcon(IntPtr hDC, Rectangle rec, int index,
uint flags);
but honestly I don't see why you ever wanna do this.

Willy.


Sep 4 '06 #4
what I'm tring to display my devices in treeview and set the image depending
on the Class type .

"Willy Denoyette [MVP]" wrote:
>
"[Joe]" <Jo*@discussions.microsoft.comwrote in message
news:9E**********************************@microsof t.com...
| Hello Willy,
| Thanks this was very helpful , I still don't know how to convert
this
| handle to System.Windows.Forms.ImageList ?? , I watch in the Marshal class
| but didn't figure how to do that. I will be so happy if you can help me
also
| in this issue .
|

That's what I was affraid of, Forms.ImageList is a class while the
setupapi.dll API returns a Handle, there is no way to convert this to an
ImageList nor to contruct an ImageList from a Handle. The setup library is
not meant for general consumption, it is meant to be used to build your own
device setup applications (using C++) using your own image lists. If you are
trying to implement device installers using C# you will have a hard time as
you'll have to use all API's in the set. If you are only trying to use the
images in the setupapi.dll ,you only have to call SetupDiDrawMiniIcon using
this import definition:

[DllImport("setupapi.dll")]
static extern int SetupDiDrawMiniIcon(IntPtr hDC, Rectangle rec, int index,
uint flags);
but honestly I don't see why you ever wanna do this.

Willy.


Sep 4 '06 #5

"[Joe]" <Jo*@discussions.microsoft.comwrote in message
news:F5**********************************@microsof t.com...
| what I'm tring to display my devices in treeview and set the image
depending
| on the Class type .
|
|
Well as I said, you need to call some more API's.
First you'll have to call:
SetupDiClassGuidsFromName
to get the list of Guid's corresponding to the device class,
using the right Guid in the list you'll have to call:
SetupDiLoadClassIcon
the returned HICON can then be used to construct an Icon instance which can
be used in your treeview.
To get you started here is a code snip that shows you how to get at the
device icon using the classGuid....

static extern int SetupDiLoadClassIcon(ref Guid classGuid, out IntPtr hIcon,
out int index);[DllImport("setupapi.dll")]
....

IntPtr hIcon;
int ix;
// Here the "DiskDrive" deviceClass GUID
//4D36E967-E325-11CE-BFC1-08002BE10318
Guid guid = new Guid("{0x4D36E967, 0xE325, 0x11CE,{0xbf, 0xc1, 0x08, 0x00,
0x2b, 0xe1, 0x03, 0x18}}");
if(SetupDiLoadClassIcon(ref guid, out hIcon, out ix) != 0)
{
// Ok, Icon found
// Create graphics object for alteration.
// Create a new icon from the handle.
Icon devIcon = Icon.FromHandle(hIcon);
...

}

Willy.



Sep 4 '06 #6
Thanks a lot .

"Willy Denoyette [MVP]" wrote:
>
"[Joe]" <Jo*@discussions.microsoft.comwrote in message
news:F5**********************************@microsof t.com...
| what I'm tring to display my devices in treeview and set the image
depending
| on the Class type .
|
|
Well as I said, you need to call some more API's.
First you'll have to call:
SetupDiClassGuidsFromName
to get the list of Guid's corresponding to the device class,
using the right Guid in the list you'll have to call:
SetupDiLoadClassIcon
the returned HICON can then be used to construct an Icon instance which can
be used in your treeview.
To get you started here is a code snip that shows you how to get at the
device icon using the classGuid....

static extern int SetupDiLoadClassIcon(ref Guid classGuid, out IntPtr hIcon,
out int index);[DllImport("setupapi.dll")]
....

IntPtr hIcon;
int ix;
// Here the "DiskDrive" deviceClass GUID
//4D36E967-E325-11CE-BFC1-08002BE10318
Guid guid = new Guid("{0x4D36E967, 0xE325, 0x11CE,{0xbf, 0xc1, 0x08, 0x00,
0x2b, 0xe1, 0x03, 0x18}}");
if(SetupDiLoadClassIcon(ref guid, out hIcon, out ix) != 0)
{
// Ok, Icon found
// Create graphics object for alteration.
// Create a new icon from the handle.
Icon devIcon = Icon.FromHandle(hIcon);
...

}

Willy.



Sep 5 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3146
by: A. Solomon | last post by:
Hi, I have a ImageList containing 4 bitmaps attached to a UserControl which acts as a Open/Close panel. This panel, upon click, switches the image in a PictureBox control to indicate the...
2
2292
by: Bob C. | last post by:
Hi All, I am using the ImageList/ListView Components to display around 100 images in C#.NET. The issue i have is, some times i may need to display the thumbnail of size more then 256x256 in...
2
8498
by: Sanjeeva Reddy | last post by:
hai Anti Keskinen, i have used the following code MyListView->LargeImageList->ImageSize = gcnew System::Drawing::Size(100, 100); // Sets large image size to 100, 100 here i am getting error...
7
2075
by: Andrew Christiansen | last post by:
Hey everyone. I have Visual Basic .NET 2003 and am trying to show images on a treeview control. I have the imagelist on the form filled with images, and have the ImageList property of the...
4
4300
by: David | last post by:
I have a problem that just cropped up with using an ImageList in my project I am using VB .NET 200 Problem: I have existing Form with 2 Image List controls. ImageList16 (for 16x16 Images) and...
4
2180
by: Just Me | last post by:
If I add an image to an imagelist using imageList.Images.Add... And use it with a tree node tn.ImageIndex = imageList.Images.Count-1 This is the actual code:...
0
2820
by: Andre Viens | last post by:
Hello, I am using the following variation of code from <http://support.microsoft.com/default.aspx?scid=kb;EN-US;319340> to add icons to an imagelist for use in a listview: Private Structure...
3
1489
by: Ryan Liu | last post by:
Hi, If I extend a user control, do I need to so something for its resource file, like ImageList used in parent class? I ask this question because I often get inconsistent problem with images...
2
3534
by: =?Utf-8?B?S2VuTg==?= | last post by:
We're using a System.Windows.Forms.ImageList to store a bunch of Images that I've loaded, and rendering each image in the ImageList during a draw loop. The process was running unusually slow and...
0
7217
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7248
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6924
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7409
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4941
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4619
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3117
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
688
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
322
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.