News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

CreateIconFromResource

Started by ic2, January 06, 2008, 06:19:44 AM

Previous topic - Next topic

ic2

I found this thread to help get me started with trying to use  CreateIconFromResource ...

http://www.masm32.com/board/index.php?PHPSESSID=da3ab12218404af62e8a0bf457793
919&topic=1275.0

Donkey indicated that when using masm the icon file should be in hex so i used the Bintodb tool from the masm32 Example10 in the HLLDEMO folder to dump the hex from an icon and I added the quotes and terminator and named the file TestIco.iaa

In the attachment below when using the dialog click button one.  It suppose to show the icon in button three but it don't work.

Could someone show me what i'm doing wrong.  I think my problem is in the TestIco.iaa or im not using it properly.

Also, are there other ways to put icon data in the data section.  I'm trying to eliminate the resource section in my program.  If so, could you place some examples here.

Thanks in advance

[attachment deleted by admin]

Vortex

 :8)

Here is an example with CreateIconFromResource

[attachment deleted by admin]

ic2

Could I get copy of your res2bin with some instruction on how to use it.

Thank you very much.

Hope I can return those favors some day   :bg

Vortex

Hi ic2,

You are welcome.

Res2bin is replaced by Res2obj, another tool with more capabilities. It can create .bin files and .obj files.

http://vortex.masmcode.com/files/Res2objV1.zip

ic2

It works for the client window, but I couldn't get it to draw the Icon in the TITLE BAR.  That's what I been trying to do so I wouldn't have to use any resources.  Would you a look at the changes I made.  These were my first few attempts.

Why is that so difficult.  Can it be done?  Seems like windows don't want to share your own given handle in your own process even if you create another handle.


[attachment deleted by admin]

ic2

I just got an idea.  I notice that your icon include was smaller in size in comparison to my's.

Res2objV1 stripped the unneeded icon information that makes it works for our programs but not Windows Window (The Title Bar).  Bintodb keeps the whole file so maybe I'll try that... I may be talking myself up on a solution.. Can't wait to try it.

If that don't work, I got another idea... how would I include the entire icon.bin binary file.  I bet that will work.  Than I Load Icon from there. Windows shouldn't bark about that, should it.

Is there a tool that can do that or how would I do it with just the present icon.bin (binary) file.

Vortex

Hi ic2,

Did you check the bmbutton example? It demonstrates how to use an icon like a button.

\masm32\examples\exampl02\bmbutton

Vortex

Hi ic2,

It's probably the resource compiler stripping the icon header info :

ICONDIRENTRY STRUCT

  bWidth        BYTE    ? ; Width, in pixels, of the image
  bHeight       BYTE    ? ; Height, in pixels, of the image
  bColorCount   BYTE    ? ; Number of colors in image (0 if >=8bpp)
  bReserved     BYTE    ? ; Reserved ( must be 0)
  wPlanes       WORD    ? ; Color Planes
  wBitCount     WORD    ? ; Bits per pixel
  dwBytesInRes  DWORD   ? ; How many bytes in this resource?
  dwImageOffset DWORD   ? ; Where in the file is this image?

ICONDIRENTRY ENDS

ICONDIR STRUCT

idReserved      WORD            ?  ; Reserved (must be 0)
idType          WORD            ?  ; Resource Type (1 for icons)
idCount         WORD            ?  ; How many images?
idEntries       ICONDIRENTRY    <> ; An entry for each image (idCount of 'em)

ICONDIR ENDS


Here is another method to eliminate resources. Convert the icon to a MS COFF object module and read the icon header information to display the image :

       .IF uMsg==WM_CREATE
       
            mov     edx,OFFSET Icon
            mov     eax,ICONDIR.idEntries.dwImageOffset[edx]
            add     eax,edx
            invoke  CreateIconFromResource,eax,ICONDIR.idEntries.dwBytesInRes[edx],\
                    TRUE,030000h
            mov     hIcon,eax

[attachment deleted by admin]

ic2

And to talk about how skin a cat or the 50 ways to leave your lover.  What a Change ....  Do you realize you just turned a million tools into four line of Build-in code with a few structs that any PE must use anyway in order to exist.

WoW wee Vortex :U :U

I been at it for over 36 hours and was ready to fall dead asleep... Now I like a jack rabbit.  I know I will not be sleeping for another 8 hours minimum.

It's not showing in the title bar yet but your ideas seem more than interesting than that right now.  Something good going to happen just to compliment your inscribe Someplace Somewhere.

I'm off to explore your code and to read your word over and over again.  Nothing new to you but a head bumper for many of us. :)

Out with the old in with the New


Vortex

Hi ic2,

Everything will go fine for you, have a rest. I am sure you will find the solution. It's easier to think with a fresh mind after resting.

ic2

It's amazing what a little sleep can do.  In my dream thought I realized I did this icon to dialog thing before.  I just woke up and two hours ago,  Searched my machine with key word ICON and found this in a flash.

QuoteIf your looking just to change the Icon, the easiest way is the WM_SETICON message, this way you don't have to modify the icon for all windows of the class. ResNum is your resource identifier

invoke LoadIcon,hInst,ResNum
mov hIcon,eax
invoke SendMessage,hDlg,WM_SETICON,ICON_SMALL,hIcon

Donkey

Strange,
I start out with Donkey code in the first example above and end with Donkey code from the year 2002 ... the solution to a problem provided by Donkey

I always hear  "it a big world out there"  but no one said anything about a STABLE

Vortex

Hi ic2,

Edgar ( Donkey ) is an expert of GUI applications, he has many nice examples. You can have a look in his examples about handling icons.

ic2


Thanks Vortex.  I'll be checking into that in a few minutes.

However, for now I have one more question so I don't continue to mess up the purpose of the original thread question which has been throughly answered.  Vortex I never knew how to even use Res2obj.exe and bin2coff.exe until now.   I didn't realize it needed a BATCH file.  I just start writing a few not to long ago for my test needs so it's really new to me.  I use to delete them if I saw them in example program because it was ugly to me.

Anyway, I manage in under a week to make a near exact copy of my masm32 program to a fasm program.  Once I get them 100% identical as far as my code by then I will find OLLYDBG and IDA useful and work on learning them.  I plan to run all kind of tests on both files to compare result just to see what the real difference is and find out if they really matter.

I'm only had one problem.  Fasm have a problem reading in the bin2coff(Icon.inc) binary file.   There is no problem with Res2obj (Icon.inc) hex file.


How would I write this in fasm syntax:

extern      Icon db

and how would I write a simple BATCH file to run poLink with basic Fasm example since bin2coff.exe require poLink .

For now, I'm afraid of those people over there, I read where what seem like some new guy got fuss out for not knowing scientific mathematics before he posted his question (non related to math).  Must have ran the poor guy off because I could not find anymore thread with his name.

I just read the fasm help files for now and with an answer to these final few fasm question I be just fine because I learn enough about masm here to do anything I need since being inside fasm and I am really shock that I was able to do it so darn fast.


Thanks for All Vortex

Now that I know how to use all these new tools I'm having a B A L L

Vortex

Hi ic2,

Fasm provides the FILE statement to embed binary files into your executable, you don't need of bin2coff to generate an object module. You can create directly the final executable with Fasm :

Icon FILE 'Smiley.ico'
[attachment deleted by admin]

ic2

QuoteThanks Vortex.  I'll be checking into that in a few minutes.

I should have told you that I have been to Donkey Web Site many time but I don't recall seeing that particular project.

Quote( Donkey ) is an expert of GUI applications

I thought the name donkey was only his handle ...

So that's why I just recently fail the COMPASS test for reading.

Anyway, Thanks for the info about fasm and CreateXXXXFromResource.  I see it all now.