locked
Load an Icon File in WM6.1 RRS feed

  • Question

  • Hello.

    I'm having trouble loading an external .ico file to my windows mobile application.
    I usually use either ImagingFactory.LoadImage or  ImageList.LoadImage to load images
    but upon further checking i found out that they don't support loading of .ico files.

    I was hoping to get suggestions on how I can successfully load the ico file and show it on screen.

    Thanks and looking forward to suggestions.
    Friday, October 2, 2009 9:52 AM

Answers

  • Thank you for trying the code too ranosoft.
    I also got the same results.

    I think it is time to accept the fact that there is no official API that can
    load icons in windows mobile. (I am still hoping I'm wrong.)

    I will now start writing the code to parse the .ico file
    and use the values parsed as parameters to the CreateIcon function.

    • Marked as answer by warrentang Thursday, October 8, 2009 2:53 AM
    Wednesday, October 7, 2009 1:58 AM

All replies

  • You can use ExtractIconEx to read an .ico file (works on executables as well). If you need it as a bitmap, you will have to call DrawIcon on a memory DC created on your bitmap
    Alex Feinman. MVP .NET Compact Framework
    Friday, October 2, 2009 9:54 PM
  • Hello Alex and thank you for your response.

    I checked the ExtractIconEx link that you posted and the API description was as follows:
    "This function retrieves icon handles from the specified executable file or dynamic-link library (DLL)."

    It seems that in Windows Mobile the capability to load an icon file image is not enabled like in
    the standard ExtractIconEX which described the function as follows:
    "The ExtractIconEx function creates an array of handles to large or small icons extracted from the specified executable file, DLL, or icon file . "

    Actually, my goal is to show the favicon.ico of certain websites on screen.
    I access the websites during runtime, so the icons themselves cannot be available as a resource
    during compile time, which is necessary to access the icons using the Windows Mobile ExtractIconEx.

    In order to achieve this does this mean that I have to write my own function to parse the .ICO File and extract
    the bitmap?
    • Proposed as answer by santosh_kumar Monday, October 5, 2009 8:48 AM
    Monday, October 5, 2009 12:27 AM
  • Hi Marvin Go!

                        Have you tried with LoadIcon api......i think it works and LoadImage as well. While using LoadImage you have to set the flag as

    IMAGE_ICON.

    Monday, October 5, 2009 8:54 AM
  • Hello santosh_kumar

    I first tried using LoadImage but it doesn't support LR_LOADFROMFILE as a parameter, (undefined error), so I just set it to null.
    But the return value is also NULL. Is there something wrong with the code?
    hTemp = LoadImage(NULL, //hinst
    TEXT("\\My Documents\\www.google.com.ico"), //file
    IMAGE_ICON, //type
    32, //cx
    32, //cy
    /*LR_LOADFROMFILE*/ NULL //fuLoad);
    
    
    
    While LoadIcon can only be used for "icon resource from the executable (.exe) file" and not for external .ico files.





    Monday, October 5, 2009 11:23 AM
  • hi Marvin Go,

                         In LoadImage api first parameter is handle to instance so current instance handle and second parameter you give as L"\\My Documents\\www.google.com.ico ". This is can be used to load a image from the dll also. First you load the dll using LoadLibraryEx() with the dwFlags parameter set to LOAD_LIBRARY_AS_DATAFILE. You pass the handle to library as first parameter for LoadImage.hTemp = LoadImage(NULL, //hinst


    handle = LoadImage(CurrentInst,L"\\My Documents\\www.google.com.ico ",IMAGE_ICON,32,32,0);

    For Image to from Dll

    handle  =  LoadLibraryEx(L"smaple.dll",0,LOAD_LIBRARY_AS_DATAFILE);


    handle2 = LoadImage(handle,L"\\My Documents\\www.google.com.ico ",IMAGE_ICON,32,32,0);
    Tuesday, October 6, 2009 11:52 AM
  • By your advice I tried the following code, and it does NOT work:

    BOOL FileExists (LPCTSTR c) {
    int attr= GetFileAttributes (c);
    return ((attr!=INVALID_FILE_ATTRIBUTES) && (!(attr & FILE_ATTRIBUTE_DIRECTORY)));
    }
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) {
    WCHAR* iconfile= L"\\testicon.ico";
    BOOL iconexists= FileExists (iconfile);
    HICON hicon= (HICON)LoadImage (hInstance,iconfile,IMAGE_ICON,32,32,0);
    printf ("fileexists=%i, handle=%i\n", (int)iconexists, (int)hicon);
    if (hicon) DestroyIcon (hicon);
    return 0;
    }

    the debug output is as follows:

    fileexists=1, handle=0

    so the file exists, but LoadImage fails to load it.

    So how to load .ico files?

    Tuesday, October 6, 2009 12:15 PM
  • Thank you for trying the code too ranosoft.
    I also got the same results.

    I think it is time to accept the fact that there is no official API that can
    load icons in windows mobile. (I am still hoping I'm wrong.)

    I will now start writing the code to parse the .ico file
    and use the values parsed as parameters to the CreateIcon function.

    • Marked as answer by warrentang Thursday, October 8, 2009 2:53 AM
    Wednesday, October 7, 2009 1:58 AM
  • You may consider sharing the code once you write it :) Thanks
    Wednesday, October 7, 2009 11:15 PM
  • Hi ,

    Any Solution for this.
    Wednesday, January 6, 2010 5:29 PM