News:

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

Loading Icons From Shell32.dll

Started by xandaz, August 23, 2009, 02:39:42 PM

Previous topic - Next topic

xandaz

    Hey guys. How you been? I'm desperate to find out how to load the icons from shell32.dll. I'm using my own icons in my prog and iot lt looks awful. I haven't found refferences to this in assembly language so i'm in the dark for now. Would someone fill me in pls?
thx xandaz :bdg

dedndave

i'd like to know that myself - lol
let's play with it
let's start with these...

LoadLibrary
GetModuleHandle
LoadIcon

of course, we'll have to figure out the index numbers ourselves

dedndave

#2
ExtractAssociatedIcon for icons associated with specific file types
once we get the load working - probably a good idea to find indexes using this function
the icons probably have different indexes on different OS's

dedndave


Sh32Name db 'shell32.dll',0
hSh32dll dd ?
hIconImg dd ?

        INVOKE  GetModuleHandle,
                OFFSET Sh32Name
        mov     hSh32dll,eax
        INVOKE  LoadImage,
                hSh32dll,
                4,
                IMAGE_ICON,
                96,
                96,
                LR_LOADFROMFILE or LR_SHARED
        mov     hIconImg,eax

i am still playing with the LoadImage parameters
the 4 is the resource index
and the 96's are the desired x and y size

dedndave

i also found this post that shows something totally different - lol
that probably means he is right and i am wrong
http://www.masm32.com/board/index.php?topic=2361.msg18705#msg18705

2-Bit Chip

(WNDCLASSEX PTR eax).hIcon, FUNC(LoadIcon, hInstance, IDI_APPLICATION)

This will load the following icon into your application:


Tedd

What do you want to use the icons for? - there's probably a better way to do it than extracting them directly from shell32.dll

For file-type icons you can use SHGetFileInfo, which gives you an index into the system image list - you then draw the icon directly from there with ImageList_Draw.
For toolbar icons, you can use the system standard icons using TB_LOADIMAGES to get the image list, then pick the right index when adding the buttons (http://msdn.microsoft.com/en-us/library/bb760433%28VS.85%29.aspx gives a list of the index values.)
Other.. you'll have to ask :wink
No snowflake in an avalanche feels responsible.

xandaz

   Hi DednDave. i tried both methods but it doesn't seem to work. is there a limit of icons you can send to Static control?
i was doing something like:

LoadLibrary,'shell32.dll'
mov iIconResource,eax
LoadIcon,iIconResource, IconIndex
SendMessage,hStatic,STM_SETICON,eax,NULL

...and it was working for the first time i load an icon but then the next icons come out blank or at least the static control doesnt show them.

Feel free to answer when appropriate

xandaz

    And also thx Tedd. I'm looking into that technique. I guess i just want to get around a method that fits my current capacities which are kinda low. :cheekygreen:

xandaz

   Hey again. Seems to be working fine with the LR_SHARED flag but there might be something else - i dunno what - i was doing wrong. thanks for the support guys. you're the best

ty x

dedndave

hi xandaz
you might try to see which function is failing
you should only have to LoadLibrary once (or not at all - it is part of the system)
(GetModuleHandle should get it)
so it's probably either LoadIcon or SendMessage that is failing
in console mode, i would test it something like this
notice that GetLastError must be called immediately after the error occurs
getting last error for SendMessage is a bit different
basically, the function returns once the message has been sent
so - if it hangs - it isn't working - lol

        INVOKE  LoadIcon,iIconResource,IconIndex
        or      eax,eax
        jnz     test00

        INVOKE  GetLastError
        push    eax
        print   chr$('LoadIcon failed, error ')
        pop     eax
        print   str$(eax),13,10
        jmp short test01

test00: INVOKE  SendMessage,hStatic,STM_SETICON,eax,NULL

test01:

xandaz

   thx dave once more but it seems to be working fine. any other dll's with icon resources besides shell32.dll?
   i'm making these little proggy to check the icons and respective indexes

dedndave

many exe's have icons - windows explorer.exe has several that you are familiar with
also a file windows\system32\moreicons.dll has several
many of the other dll's in system32 have them, as well

this link Tedd gave us has the standard menu icons
http://msdn.microsoft.com/en-us/library/bb760433%28VS.85%29.aspx

profdracula

#13
To get other application icons in various color-modes you can use SHGetFileInfo. For example if you are making a ProcessManager like LordPE, you can get individual app icons using this method.

P.S. If you want a working demo/code post a request.
--Priory of Sion--

xandaz

   yeah prof dracula. I think i took too long to answer your post. See if you can gimme the code for demo.zip
   Thanks blood-sucker