News:

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

how to load icon from resources

Started by ossama, December 27, 2007, 02:18:20 PM

Previous topic - Next topic

ossama

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]

VLaaD

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^





donkey

Just use LoadImage, if you specify cxDesired and cyDesired you can load any one you want.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable