Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on a project in Code:Blocks c++ win32. I have read on the internet the use of LoadIcon and MAKEINTRESOURCE. However, it seems I am not using them correctly. I have created an image with paint and named it 'ico1'. It is in the format '.png'.

When I execute the program I get an error code at line 1 "error: request for member 'png' in '1002', which is of non-class type 'int'."

Below is the code.

/* Use default icon and mouse-pointer */
    wincl.hIcon   = LoadIcon (ico1.png, MAKEINTRESOURCE(IDI_ico1));
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_HIGHLIGHTTEXT;


What should I do next? Any help is much appreciated. Thanks.

What I have tried:

#define IDI_ico1 1001
#define ico1 1002

/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (ico1.png, MAKEINTRESOURCE(IDI_ico1));
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_HIGHLIGHTTEXT;
Posted
Updated 24-Feb-16 4:32am
v2

1 solution

LoadIcon function (Windows)[^] requires the image to be stored as resource in the executable or a loaded DLL using the Windows icon format.

If you want to load an icon from a file you can use the LoadImage function (Windows)[^] with LR_LOADFROMFILE. But even this function requires the file to be a Windows icon or bitmap file. So you must convert your PNG file to one of the supported formats.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900