The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: brixton on June 08, 2005, 09:26:14 PM

Title: Question about icons
Post by: brixton on June 08, 2005, 09:26:14 PM
If I wanted my program to have a custom icon instead of the standard executable window one, how would I go about it?

Thankyou in advance!  :cheekygreen:
Title: Re: Question about icons
Post by: dsouza123 on June 08, 2005, 10:37:53 PM
Create the icon using an appropriate tool/program such as image editor,
it can be accessed in Quick Editor in the Tools menu.

Look at the example GENERIC.ASM
along with it's resource file source code RSRC.RC
and the icon MAINICON.ICO that is one of the examples that comes with MASM32.

Title: Re: Question about icons
Post by: brixton on June 09, 2005, 11:23:06 PM
If it has no GUI, do I need any ASM code?
Title: Re: Question about icons
Post by: Clueless on June 10, 2005, 01:50:06 AM
brixton,
I think that if you have no GUI you can just create the program from the asm file with no icon.  One you have the exe you can click its properties and then add any icon you want.

Gene
Title: Re: Question about icons
Post by: Mark Jones on June 10, 2005, 01:55:08 AM
Console apps can have icons just like GUI apps, dsouza123's comments above still apply.
Title: Re: Question about icons
Post by: Clueless on June 10, 2005, 02:05:13 AM
Mark,
I realize this, also, but I somehow get the idea he wants to avoid the use of a resource file.  My method allows this to happen.

Gene
Title: Re: Question about icons
Post by: Mark Jones on June 10, 2005, 02:18:10 AM
Interesting. I never knew that an .exe's icon could be changed by digging into its properties. Guess we learn something new every day...
Title: Re: Question about icons
Post by: hutch-- on June 10, 2005, 02:18:05 AM
The trick is to work out how a normal resource script is written and how to compile the resource into an executable file. There is no difference between console and GUI apps here. Most console aps don't use resources as they are text mode displays.

Once you have the need for image data like bitmaps and icons, you write the script, compile it and link it into the application. Within the application there are system API calls that load and access this resource data.
Title: Re: Question about icons
Post by: Jeff on June 10, 2005, 02:25:27 AM
Quote from: Clueless on June 10, 2005, 01:50:06 AM
brixton,
I think that if you have no GUI you can just create the program from the asm file with no icon. One you have the exe you can click its properties and then add any icon you want.

Gene

unfortunately its not that easy.  that only applies to shortcuts, not executables.
Title: Re: Question about icons
Post by: brixton on June 10, 2005, 06:07:40 AM
You can only change the icon with the PIF file (shortcut) to a DOS executable  :U

I have a 32-bit console app.  How do I link with the resource file?   Will QE do this for me?  And do I need any ASM in my app?

Thanks  :P
Title: Re: Question about icons
Post by: Mark Jones on June 10, 2005, 06:37:40 AM
Brixton, to make your 32-bit console app have an icon, make a new file called rsrc.rc and in that file include the line:


100 icon discardable "MyIcon.ico"


Then run these two commands to produce an .obj file:

\masm32\bin\rc /v rsrc.rc
\masm32\bin\cvtres /machine:ix86 rsrc.res

Then when you recompile the regular .exe, the rsrc.obj will be included automatically and your icon will appear in the executable. Experiment with the MASM32 examples for more info. :)
Title: Re: Question about icons
Post by: brixton on June 10, 2005, 10:53:35 AM
Mark Jones,

Quote from: Mark Jones on June 10, 2005, 06:37:40 AM
Brixton, to make your 32-bit console app have an icon, make a new file called rsrc.rc and in that file include the line:


100 icon discardable "MyIcon.ico"


Then run these two commands to produce an .obj file:

\masm32\bin\rc /v rsrc.rc
\masm32\bin\cvtres /machine:ix86 rsrc.res

Then when you recompile the regular .exe, the rsrc.obj will be included automatically and your icon will appear in the executable. Experiment with the MASM32 examples for more info. :)
Thankyou for the info!  Could you explain what the /v switch does, and what cvtres does? 

Sorry for the basic questions  :'(
Title: Re: Question about icons
Post by: hutch-- on June 10, 2005, 11:40:01 AM
The /v switch is "verbose" so that you can see if the resources built correctly.

CVTRES converts a compiled resource file with a RES extension to an object module so it can be linked into the EXE file as its resource section.
Title: Re: Question about icons
Post by: brixton on June 10, 2005, 12:11:25 PM
Thankyou very much all, I understand now  :bg :dance:
Title: Re: Question about icons
Post by: Clueless on June 10, 2005, 12:14:43 PM
Jeff,
Yes, I was referring to the shortcut.  Somehow, if you drop the exe onto the desktop, the OS makes it all work and adding an icon is very easy.  I do it all the time.  It is, IMO, the preferred method for a console app that does not have a need for any other resources.  As far as embedding an icon directly into an exe without a resource script, I would just convert the icon to db strings and put it in the data section.

About cvtres, why bother, I never do.  The linker is quite capable of handling .res files and if it is done this way you can then name the .rc file with the same name as the .asm file, this is something that I prefer for some reason.  But I realize that everyone has there own way of doing things and I applaud Hutch for including all the files necessary for people to do things the way they prefer.  Way to go, Hutch!  :thumbu

Gene


Paul
Title: Re: Question about icons
Post by: hutch-- on June 10, 2005, 12:23:52 PM
Paul,

Its actually done for a reason, while its simpler to use the RES file with the linker, it hides the technique used by the linker which is to call CVTRES to convert the RES to OBJ so it was a design decision so that programmer would know how it all worked. A lot of HLL people don't care but the assembler gang like to know how everything works.
Title: Re: Question about icons
Post by: Clueless on June 10, 2005, 01:13:49 PM
Hutch,
You are certainly right about that!  We snoop into all knowledge areas!  It is a part of who and what we are and why we choose assembly (I dislike the word 'compiler' for obvious reasons).

Paul (or Gene, whatever)  :bg
Title: Re: Question about icons
Post by: Robert Collins on June 10, 2005, 01:38:00 PM
Quote from: Mark Jones on June 10, 2005, 02:18:10 AM
Interesting. I never knew that an .exe's icon could be changed by digging into its properties. Guess we learn something new every day...

I don't think you can change the exe's icon via the properties. This only changes the desktop icon of the shortcut and not the icon on the title bar of an application.
Title: Re: Question about icons
Post by: dsouza123 on June 10, 2005, 03:20:23 PM
There is a usefull freeware program called reshacker that allows you to modify your executable
to view/change/add/delete various resource items.
Title: Re: Question about icons
Post by: donkey on June 11, 2005, 03:57:14 AM
The icon for an executable is the first icon found in the resource section, there is no way to assign another as it is not your program that is choosing or displaying the icon, it is the shell. Shell32 will only use the first icon of the executable. In order to change the icon you have to either update the resources with a new icon (using UpdateResource if you want to do it at runtime) or using a resource editor (like ResHacker that was mentioned previously). If you use UpdateResource, it only works in NT/2K/XP/2K3 the 9x versions will require MSLU (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mslu/winprog/microsoft_layer_for_unicode_on_windows_95_98_me_systems.asp) in order to use it though it will not generate any errors in 9x it will not do anything either.
Title: Re: Question about icons
Post by: Vortex on June 11, 2005, 07:43:38 AM
Yaroslav's resource linker is able to update resources. Run the batch file Update.bat and watch how the icon of the executable Win.exe is changed.  :)


[attachment deleted by admin]
Title: Re: Question about icons
Post by: Vortex on June 11, 2005, 11:13:00 PM
Here is another example with the UpdateResource function

[attachment deleted by admin]
Title: Re: Question about icons
Post by: donkey on June 11, 2005, 11:22:20 PM
Well, updating a resource with UpdateResource is fairly simple, I don't really see the need to use external programs or batch files for it. Here is a snippet from an old project that I worked on that inserted binary data into the resources of an executable. It is part of the engine for an install maker, nothing nefarious...

invoke BeginUpdateResource,OFFSET OutFile,FALSE
mov [hUpdate],eax

; Write the compressed file to the resource section
invoke UpdateResource,[hUpdate],RT_RCDATA,[ResNumber],NULL,[pCompHeap],[ComprSize]

add D[ResNumber],1
; Write the file data to the resource section
invoke UpdateResource,[hUpdate],RT_RCDATA,[ResNumber],NULL,[pDataStruct],SIZEOF ResourceHeader

invoke EndUpdateResource,[hUpdate],FALSE


The sequence is essentially the same for any resource type, for icons simply enumerate the icon resources, get the resource number of the first one and replace it.
Title: Re: Question about icons
Post by: Vortex on June 12, 2005, 08:21:15 AM
I am really curious Donkey, had you the time to check for what purposes could be used the resource linker rl.com?
I don't claim that using that tool is a big event but if you could check it...
Title: Re: Question about icons
Post by: brixton on June 12, 2005, 09:20:34 AM
Thankyou for all the replies, I have got it working, it's as easy as a click in QE  :dance:

Now I just need to create a decent icon  :lol .  Also, it adds a few K onto the filesize, but I suppose that's to be expected as it is storing the icon.