Hi everyone -
I've been trying to figure out how to add an icon to a window. I have created an .ico file (icondemo.ico). I have a .rc file containing a define for the (#define IDI_ICON 101 and a statement declaring the icon as IDI_ICON ICON DISCARDABLE "c:\masm32\mymasm\icondemo.ico". The masm source file contains the statement IDI_ECO equ 101. And, finally, I have in the .code section the statement invoke LoadIcon, NULL, IDI_ICON.
The icon does not show up. I haven't messed with icons in the past so I'm largely clueless. Any suggestions?
Thank you,
Mark Allyn
invoke LoadIcon, hInst, IDI_APPLICATION will work, Mark.
Mark,
Just have a look at any of the GUI apps in masm32, they all can use the attached icon as the main window icon. JJ has shown how to use a pre-defined system icon but you can use your own easily. I personally use number IDs for icons but if you are going to use equates, make sure the equate in your source code matches the ID in the RC file.
Quote from: hutch-- on November 15, 2009, 11:38:19 PM
JJ has shown how to use a pre-defined system icon but you can use your own easily.
Hutch,
IDI_App does load the "own" icon, not a predefined system icon. All you need is this line as an rc file (for example):
32512 ICON "\\masm32\\RichMasm\\icons\\Smiley.ico"
Note that IDI_APPLICATION is precisely 32512.
In fact, RichMasm (http://www.masm32.com/board/index.php?topic=12460) generates that line with the option...
OPT_Icon Smiley ; see \Masm32\RichMasm\Icons
... using this sequence in the batch file (\masm32\RichMasm\RES\bldallRM.bat):
QuoteIF DEFINED oIcon (
echo 32512 ICON "\\masm32\\RichMasm\\icons\\%oIcon%.ico" >MyIcon.rc
if exist %oRes% (copy MyIcon.rc + %oRes% MyIcon.rc)
set oRes=MyIcon.rc
)
:bg
http://msdn.microsoft.com/en-us/library/ms648072(VS.85).aspx
IDI_APPLICATION
Default application icon.
It is an interesting method you are using but you have overwridden a system default ID for no purpose. Using the system default means you don't have to include a resource to display an icon.
In the resource file, something like this.
500 ICON MOVEABLE PURE LOADONCALL DISCARDABLE "MYICON.ICO"
In source code,
invoke LoadIcon,hInstance,500
mov hIcon, eax
Use the icon handle in the WNDLASSEX structure and a CreateWindowEx() window will display the icon in the normal manner.
Quote from: hutch-- on November 16, 2009, 12:03:03 AM
It is an interesting method you are using but you have overwridden a system default ID for no purpose.
Well, I am using, not overwriting, the system default ID. But I will change the ID in case I find a second use for IDI_APPLICATION :bg
Quote
In the resource file, something like this.
500 ICON MOVEABLE PURE LOADONCALL DISCARDABLE "MYICON.ICO"
The options MOVEABLE PURE LOADONCALL DISCARDABLE are obsolete (http://www.masm32.com/board/index.php?topic=5960.0), you can omit them. In case you store your icons in a particular folder, see usage of double backslashs as shown above.
:bg
> MOVEABLE PURE LOADONCALL DISCARDABLE
I know its obsolete but if you have resource editors that create them in that form and it works OK, I don't lose sleep over it.
Hi Hutch and JJ -
Thank you for your help on this. Can you help me understand what the number is in the first field of your .rc file-- for instance, 500. I looked in the masm32 script pulldown and saw similar syntax. Is the "500" functionally the same as the "101" I was using?
Do I need a "equ 500" in my source file?
Regards,
Mark
Mark,
The number is the ID. You can use whatever you want (including 32512 ;-), but make sure the ID appears only once in your code. You may use MyIcon = 123 or MyIcon equ 456, but the number itself is what counts. And in the rc file, the MyIcon is not known, so there you definitely need the 123...
For a resource ID the high-order word must be zero, so the maximum value is 65535.
Don't forget that it can be a string as well - one reason for the FFFF limit.
Hi,
I only remember you that in the wndclassex structure there are two icon handles: one for the large one (I create it always of 32x32 pixels) and another one for the small one (that I create always of 16x16 pixels). I think that in the upper left corner of the window will appear the small one.
Forgive me if I am wrong.