LoadIcon (Api) problem, i know the syntax, but doesn't work...

Started by white scorpion, January 27, 2005, 06:48:48 AM

Previous topic - Next topic

white scorpion

Hi All,

i'm having a big problem using the LoadIcon function, i'm trying to load a custom icon into a program for about 2 weeks now, but i can only get the default icons like IDI_APPLICATION to work, but my custom icon won't load :(

here's the info from msdn:

Quote
LoadIcon Function

The LoadIcon function loads the specified icon resource from the executable (.exe) file associated with an application instance.
Note  This function hase been superseded by the LoadImage function.

Syntax

HICON LoadIcon(     

    HINSTANCE hInstance,
    LPCTSTR lpIconName
);

Parameters

    hInstance
        [in] Handle to an instance of the module whose executable file contains the icon to be loaded. This parameter must be NULL when a standard icon is being loaded.
    lpIconName
        [in]

        Pointer to a null-terminated string that contains the name of the icon resource to be loaded. Alternatively, this parameter can contain the resource identifier in the low-order word and zero in the high-order word. Use the MAKEINTRESOURCE macro to create this value.

        To use one of the predefined icons, set the hInstance parameter to NULL and the lpIconName parameter to one of the following values.

        IDI_APPLICATION
            Default application icon.
        IDI_ASTERISK
            Same as IDI_INFORMATION.
        IDI_ERROR
            Hand-shaped icon.
        IDI_EXCLAMATION
            Same as IDI_WARNING.
        IDI_HAND
            Same as IDI_ERROR.
        IDI_INFORMATION
            Asterisk icon.
        IDI_QUESTION
            Question mark icon.
        IDI_WARNING
            Exclamation point icon.
        IDI_WINLOGO
            Windows logo icon. Windows XP: Default application icon.

Return Value

    If the function succeeds, the return value is a handle to the newly loaded icon.

    If the function fails, the return value is NULL. To get extended error information, call GetLastError.


Remarks

    LoadIcon loads the icon resource only if it has not been loaded; otherwise, it retrieves a handle to the existing resource. The function searches the icon resource for the icon most appropriate for the current display. The icon resource can be a color or monochrome bitmap.

    LoadIcon can only load an icon whose size conforms to the SM_CXICON and SM_CYICON system metric values. Use the LoadImage function to load icons of other sizes.

the things i have tried:



.data

MyIcon     db "wscorpion.ico",0


.code

invoke LoadIcon,hInst,addr MyIcon
mov wce.hIcon,eax
mov wce.hIconSm,eax



for the rest the code is the same as the template in Iczelion's tutorial.


i've also tried

invoke LoadIcon,NULL,addr MyIcon


and MyIcon without a '0' at the end, but both of them doesn't work..

i'm pretty sure it is something easy i am overlooking, but i really can't get it to work :(

btw, the icon i am using is 32x32 and of filetype .ICO . i have created the icon with an icon creator, so i doubt the icon is the problem...


Thanks in advance for your reply,


Kind regards

thomasantony

Hi,
     In order to use LoadIcon, you have to include the icon as a resource in your executable. you do this by creating file called <yourprogramname>.rc and add the fllowing lines to it

100       ICON     "wscorpion.ico"

You can use any string also in place of 100. Compile this with the command

rc yourprogramname.rc

Then you will get yourprogramname.res Use this file while linking your obj file like this

link /Subsystem:windows yourprogramname.obj yourprogramname.res

The in the program you use

  invoke LoadIcon,0,100
  mov wce.hIcon,eax
  mov wce.hIconSm,eax

If you declared you Icon with  a string name put that string as a variable like this

.data
IconName    db "MyIconName",0

.code

invoke LoadIcon,0,ADDR IconName

you can also load the icon directly from an Iconfile usng the API LoadImage,specifying the option LR_LOADFROMFILE

Thomas Antony  :U
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

white scorpion

#2
thanks, that's all i needed to know... i didn't knew about the part from the resource file (that the line had to be added), i think the documentation about this API isn't good, the only documentation you can find is using the default icon...

but thank you very much for your reply, i think i will manage now :D


[EDIT] Well, i still can not get it to work, please take a look at my complete file here. the zipfile contains the icon, the source code, the rc file and everything should work, but it still doesn't load the icon....

thanks in advance,

[/EDIT]


petezl

Your rc file:
#define icon  is missing and it needs to be declared as ICON not ICO
In the asm file, name the icon as MyIcon equ "what ever number was allocated to it"
See attached file.
Peter.

[attachment deleted by admin]
Cats and women do as they please
Dogs and men should realise it.

white scorpion