Loading a bitmap from a .net resource as a HBITMAP

J

j.edwards

I currently have some custom controls in a vb.net class library that use
native Win32 GDI calls instead of the GDI+ stuff as I found that way too
slow. The only way I know to get a HBITMAP required for win32 calls is to
use SHLoadImageFile() from aygshell - and that's been working well. However,
I now want to have the various images the controls need (such as a down
arrow) stored as resources within the class library rather than being
messily scatted about in the file system.

The loading of resources is working fine - I can have a bitmap as "Embedded
Resource" and load it's data into a stream, array of bytes, or whatever
else. But how can I convert the bitmap file data into an actual bitmap with
a HBITMAP handle? It looks like CreateDIBitmap is what I need but it's not
available in the pocket pc windows.
 
A

Alex Feinman [MVP]

I think the easiest way would be reading the bitmap data stream from
resource, copying it into a temporary file and then using SHLoadImageFile.
Once the bitmap is loaded you can delete the file
 
J

j.edwards

Thanks anyway.
I think I'll just write it to a temp file as suggested - dodgy, but should
work ok until/if ever a better way turns up.
 
A

Alex Feinman [MVP]

I did not say there isn't a better way - just that this was the easiest way
to go. You can create a bitmap from a memory stream in unmanaged code or
using P/Invoke, but it takes some work. In fact, I'm not sure that using a
temp file is such a bad idea - most applications use temporary files -
nothing dodgy about it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top