The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: ossama on December 27, 2007, 02:18:20 PM

Title: how to load icon from resources
Post by: ossama on December 27, 2007, 02:18:20 PM
hi, :bg
i have an icon file that has many icon formats in it.
let say that the icon file has 4 icon formats in it (16*16,32*32,48*48,128*128),the question is how can i load a specific icon format?

i have attached a demo icon file.

[attachment deleted by admin]
Title: Re: how to load icon from resources
Post by: VLaaD on December 27, 2007, 08:32:42 PM
It depends on how do you load these resources; there are three different approaches:

First, simplest:
   push hModule         ;DWORD, SDK type is HMODULE, that what you got after a call to GetModuleHandle(NULL)
   push IconOrdinal      ;DWORD, LOWORD contains ordinal
   push IMAGE_ICON         ;DWORD, one of { IMAGE_BITMAP, IMAGE_CURSOR, IMAGE_ICON }
   push cxDesired         ;Icon that will be loaded has this X pixels
   push cyDesired         ;Icon that will be loaded has this Y pixels
   push fuLoad         ;DWORD, usually only LR_DEFAULTCOLOR
   call [user32!LoadImage]
   test eax, eax
   jz L_exit         ;Failed, you must get non-zero value which you'll free later with DestroyIcon() call
   mov [hIcon], eax
   ....

Second, find your resource and lock it, getting pointer to it:

   FindResourceEx,
   SizeofResource,
   LoadResource,
   LockResource (after this you'll get direct mem ptr to the resource)

Third, you are obviously not using icon resource in order to make your exe more colorful :) probably you're loading it to stick it to a button or something;
if this is the case, consider using device indenpendent bitmap (DIB) or image list (even better, you can do some animation as well :)

HTH,
^VlaaD^




Title: Re: how to load icon from resources
Post by: donkey on December 27, 2007, 10:02:36 PM
Just use LoadImage, if you specify cxDesired and cyDesired you can load any one you want.
Title: Re: how to load icon from resources
Post by: ossama on December 28, 2007, 09:21:00 AM
thank you a lot