473,592 Members | 2,921 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Drawing. Icon and hIcon (ptr to an ICONIMAGE structure)

I have an interesting quandary.

I have developed a program in VB.Net to extract an icon resource from an
exe/dll or from an ico file and enumerate its formats (16x16,256
color;32x32,tru e color;etc.). It reads out the structures all the way down
to the ICONIMAGE structures. I have this represented as an array of bytes
read from the resource. I am using the unmanaged function
CreateIconFromR esourceEx to generate an hIcon pointer. I take this icon
pointer and pass it into the FromHandle method of a System.Drawing. Icon.

Everything works beautifully with one exception. When the icon format is
monochrome, the height from the System.Drawing. Icon is doubled. I understand
that the biHeight from the BITMAPINFOHEADE R structure is doubled to account
for both the XOR (color) and AND (transparent) masks, but I am passing the
correct desired height (biHeight / 2) into CreateIconFromR esourceEx.

Is there something wrong with the pointer I'm getting back, or is there
something wrong with System.Drawing. Icon that it doesn't understand
monochrome icons?

[VB.Net Pseudocode]
Public Structure ICONIMAGE
Public pBits() As Byte 'All the bytes that make up the structure from
the resource.
Public Function GetHeader As BITMAPINFOHEADE R
....
End Function
End Structure
....
Dim img as ICONIMAGE
....

Dim bmi As BITMAPINFOHEADE R = img.GetHeader()
Dim width As Integer = bmi.biWidth
Dim height As Integer = bmi.biHeight \ 2
Dim flags As Integer = 0
If IsMonoChrome() Then
flags = flags Or LR_MONOCHROME
End If

Dim hIcon As IntPtr
hIcon = CreateIconFromR esourceEx(img.l pBits, ico.idEntries(i ).dwBytesInRes,
True, &H30000, width, height, flags)

Dim icon As System.Drawing. Icon
icon = icon.FromHandle (hIcon)

Debug.WriteLine (i, "i")
Debug.WriteLine (icon.Size, "Size")
Debug.WriteLine ("")

....
Jul 21 '05 #1
7 7456
> I have an interesting quandary.

I have developed a program in VB.Net to extract an icon resource from an
exe/dll or from an ico file and enumerate its formats (16x16,256
color;32x32,tru e color;etc.). It reads out the structures all the way down
to the ICONIMAGE structures. I have this represented as an array of bytes
read from the resource. I am using the unmanaged function
CreateIconFromR esourceEx to generate an hIcon pointer. I take this icon
pointer and pass it into the FromHandle method of a System.Drawing. Icon.

Everything works beautifully with one exception. When the icon format is
monochrome, the height from the System.Drawing. Icon is doubled. I understand
that the biHeight from the BITMAPINFOHEADE R structure is doubled to account
for both the XOR (color) and AND (transparent) masks, but I am passing the
correct desired height (biHeight / 2) into CreateIconFromR esourceEx.

Is there something wrong with the pointer I'm getting back, or is there
something wrong with System.Drawing. Icon that it doesn't understand
monochrome icons?


As has been mentioned before, VB.NET queries should really go to a more appropriate group such as those listed here:
Http://EDais.mvps.org/DotNet/
In answer to your question though, monochrome icons are stored using a single 1-Bit Bitmap rather then two as with other
bit-depths. I don't recall offhand which way round the images are within this Bitmap but this should be a simple test
in your code - If you can't work it out then let me know and I'll have a look at some of my old code to extract them.
The height of that particular ICONDIRENTRY will be doubled and as such should be halved to get the real size of the icon
and the data dealt with accordingly.
Hope this helps,

Mike
- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Jul 21 '05 #2
Right, I remember reading that somewhere. So now my question is
How do I split up my byte array (ICONIMAGE) to accommodate that?

Do I have to create another ICONIMAGE structure because of that when it's
monochrome? If so, how do I split up the AND mask into its constituent XOR
and AND masks?

"Mike D Sutton" <ED***@mvps.org > wrote in message
news:OF******** ******@TK2MSFTN GP10.phx.gbl...
I have an interesting quandary.

I have developed a program in VB.Net to extract an icon resource from an
exe/dll or from an ico file and enumerate its formats (16x16,256
color;32x32,tru e color;etc.). It reads out the structures all the way down to the ICONIMAGE structures. I have this represented as an array of bytes read from the resource. I am using the unmanaged function
CreateIconFromR esourceEx to generate an hIcon pointer. I take this icon
pointer and pass it into the FromHandle method of a System.Drawing. Icon.

Everything works beautifully with one exception. When the icon format is
monochrome, the height from the System.Drawing. Icon is doubled. I understand that the biHeight from the BITMAPINFOHEADE R structure is doubled to account for both the XOR (color) and AND (transparent) masks, but I am passing the correct desired height (biHeight / 2) into CreateIconFromR esourceEx.

Is there something wrong with the pointer I'm getting back, or is there
something wrong with System.Drawing. Icon that it doesn't understand
monochrome icons?
As has been mentioned before, VB.NET queries should really go to a more

appropriate group such as those listed here: Http://EDais.mvps.org/DotNet/
In answer to your question though, monochrome icons are stored using a single 1-Bit Bitmap rather then two as with other bit-depths. I don't recall offhand which way round the images are within this Bitmap but this should be a simple test in your code - If you can't work it out then let me know and I'll have a look at some of my old code to extract them. The height of that particular ICONDIRENTRY will be doubled and as such should be halved to get the real size of the icon and the data dealt with accordingly.
Hope this helps,

Mike
- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/

Jul 21 '05 #3
> Right, I remember reading that somewhere. So now my question is
How do I split up my byte array (ICONIMAGE) to accommodate that?

Do I have to create another ICONIMAGE structure because of that when it's
monochrome? If so, how do I split up the AND mask into its constituent XOR
and AND masks?


Does CreateIconFromR esourceEx() not handle them as they are?
If not then you'll have to create the hIcon yourself using CreateIconIndir ect() as I mentioned in a prior post of
yours - Just create a monochrome Bitmap from the data, then use this as the Mask member of the ICONINFO structure you
pass to the function.
Hope this helps,

Mike
- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Jul 21 '05 #4
CreateIconFromR esourceEx gives me an hIcon, but for the monochrome guys, it
gives me double the height. I tried passing in the correct height into
CreateIconFromR esourceEx, but it still gave me double the height. Then I
tried passing half the height to CreateIconFromR esourceEx on known
monochrome icons. The height came out right, but the scanning didn't.

Perhaps you could provide a code sample of dealing with monochrome icons.

"Mike D Sutton" <ED***@mvps.org > wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Right, I remember reading that somewhere. So now my question is
How do I split up my byte array (ICONIMAGE) to accommodate that?

Do I have to create another ICONIMAGE structure because of that when it's monochrome? If so, how do I split up the AND mask into its constituent XOR and AND masks?
Does CreateIconFromR esourceEx() not handle them as they are?
If not then you'll have to create the hIcon yourself using

CreateIconIndir ect() as I mentioned in a prior post of yours - Just create a monochrome Bitmap from the data, then use this as the Mask member of the ICONINFO structure you pass to the function.
Hope this helps,

Mike
- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/

Jul 21 '05 #5
> CreateIconFromR esourceEx gives me an hIcon, but for the monochrome guys, it
gives me double the height. I tried passing in the correct height into
CreateIconFromR esourceEx, but it still gave me double the height. Then I
tried passing half the height to CreateIconFromR esourceEx on known
monochrome icons. The height came out right, but the scanning didn't.

Perhaps you could provide a code sample of dealing with monochrome icons.


Not for VB.NET unfortunately, for that you'd need to post to another group I'm afraid, and I don't know of any examples
offhand written in VB either. The call you need to look at though is as mentioned before, CreateIconIndir ect() - Simply
create a single monochrome Bitmap (either DDB or DIB) and populate it with the data array from the ICONIMAGE structure
then send this as the mask bitmap to the afore mentioned API call, it will return an hIcon perfectly compatible with
those you're currently using.
Hope this helps,

Mike
- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Jul 21 '05 #6
I'll take C# if you got it. I'll even live with C++.
This wasn't specifically a VB question, but one of GDI/GDI+ (unmanaged vs.
managed). I just happened to write it in VB.Net
Any code sample will be appreciated.

"Mike D Sutton" <ED***@mvps.org > wrote in message
news:Om******** ******@TK2MSFTN GP10.phx.gbl...
CreateIconFromR esourceEx gives me an hIcon, but for the monochrome guys, it gives me double the height. I tried passing in the correct height into
CreateIconFromR esourceEx, but it still gave me double the height. Then I
tried passing half the height to CreateIconFromR esourceEx on known
monochrome icons. The height came out right, but the scanning didn't.

Perhaps you could provide a code sample of dealing with monochrome
icons.
Not for VB.NET unfortunately, for that you'd need to post to another group I'm afraid, and I don't know of any examples offhand written in VB either. The call you need to look at though is as mentioned before, CreateIconIndir ect() - Simply create a single monochrome Bitmap (either DDB or DIB) and populate it with the data array from the ICONIMAGE structure then send this as the mask bitmap to the afore mentioned API call, it will return an hIcon perfectly compatible with those you're currently using.
Hope this helps,

Mike
- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/

Jul 21 '05 #7
> I'll take C# if you got it. I'll even live with C++.
This wasn't specifically a VB question, but one of GDI/GDI+ (unmanaged vs.
managed). I just happened to write it in VB.Net
Any code sample will be appreciated.


I've given you all the information you need (it's not a complex task!), have a hack at implementing it yourself and I'm
sure Google can fill in any gaps you have associated with any of the API's.
Hope this helps,

Mike
- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Jul 21 '05 #8

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

Similar topics

6
10031
by: yxq | last post by:
Thank Armin Zingler, the codes below work well! But i want to put the icon into Picturebox1 instead of the Form1, how to do? the code ************************** If retval <> 0 Then Dim g As Graphics Dim ico As Icon Dim hIcon As IntPtr ' handle to the icon once it is extracted hIcon = ExtractIcon(VB6.GetHInstance, iconfile, iconindex)
5
3029
by: BJ | last post by:
I am trying to add my application to the system tray. I am not using the built in control becuase of the limitation that you can not use the balloon tool tip feature. I have done this succesfully in vb6 but when I try it in vb.net I get the system tray to work but there is no icon in the system tray. I know it is working because I can get the balloon tip to appear and where the icon is supposed to be there just isn't an icon. just a blank...
4
1482
by: Urs Vogel | last post by:
Hi I have an image list with icons and would like to change the form icon depending on an operating mode, but I couldn't figure out how to re-assign an image from the image list to the form.icon property. Thanks fo a hint. Urs
7
259
by: WALDO | last post by:
I have an interesting quandary. I have developed a program in VB.Net to extract an icon resource from an exe/dll or from an ico file and enumerate its formats (16x16,256 color;32x32,true color;etc.). It reads out the structures all the way down to the ICONIMAGE structures. I have this represented as an array of bytes read from the resource. I am using the unmanaged function CreateIconFromResourceEx to generate an hIcon pointer. I take...
4
5313
by: Neo | last post by:
I am developing a GUI for a destop application in Visual C++ .Net 2005, I am trying to create toolbar exactlly same as windows explorer which will have default windows icons, which are in windows folder shell32.dll. please let me know, how to get and use icons from shell32.dll?
0
1656
by: Nickneem | last post by:
I' m trying to disable all right mouse clicks by using the vbAccelerator Windows Hooks Library The small (systray / console) app. must catch all (right) mouseclicks before they are received by the users application (for instance IE). I' m not getting passed the stage where I write to the console catching clicks on my applications form.. I really doubt if this one's possible at all (especially for an API noob like me)..
1
2606
by: GHUM | last post by:
I have found a "make a icon in traybar" skript, and it loads its Icon from a file hinst = win32gui.GetModuleHandle(None) iconPathName= "c:/myapp/myapp.ico" icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE hicon = win32gui.LoadImage(hinst, str(iconPathName), win32con.IMAGE_ICON, 0, 0, icon_flags) that works great.
0
1004
by: =?Utf-8?B?SnVzdCBjbG9zZSB5b3VyIGV5ZXMgYW5kIHNlZQ== | last post by:
Hello all, I have SDI Application had made using MFC Application wizard, and I could able to change the icon of the application executable file through add adding a resource icon and replace it with the old one that came with the wizard, But I couldn't able to change the main window icon to be the same I tried that code inside “PreCreateWindow” but it fails HICON hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));...
2
8731
by: Nathan Sokalski | last post by:
I am attempting to create icons for controls I have created using VB.NET by using the System.Drawing.ToolboxBitmap attribute. I have managed to do this in C# by specifying the path to the *.ico file, but I have been unable to get any of the overloads to work in VB.NET. I would like to store the *.ico files in a *.resx file so that users do not need anything other than the *.dll, but at the moment I am just trying to get any of the overloads...
0
7871
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8366
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7995
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6642
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5735
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5400
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2379
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1467
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1202
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.