Click to See Complete Forum and Search --> : Icon problem


alsyed
June 28th, 2008, 03:32 PM
I have used a number of icon files as resource and gave my project proper coding but the window doesnot display the small icon at the top left corner when i start the compiled file. It displays the big icon correctly (to represent the file) and I am sure that I included 16x16 version of icon 32bit, 256 colors, 16 colors.

I use Dev C++.

I used the following lines of code in the project:-

WNDCLASSEX win;
win.hIcon = LoadIcon(NULL, MAKEINTRESOURCE(IDI_BICON));
win.hIconSm = LoadIcon(NULL, MAKEINTRESOURCE(IDI_BICON));
CreateWindowEx(...parameters...);

it displays IDI_APPLICATION icon where it should display my icon


//THIS TEXT HAS BEEN ADDED LATER ON
THIS PROBLEM IS NOW SOLVED BY REPLACING
win.hIconSm = LoadIcon(NULL, MAKEINTRESOURCE(IDI_BICON));
BY
win.hIconSm = static_cast<HICON>(LoadImage(hInstance, MAKEINTRESOURCE(IDI_BICON), IMAGE_ICON, 16, 16, LR_DEFAULTSIZE));

egawtry
June 28th, 2008, 06:35 PM
If you are using MFC, in your OnCreate or OnInitDialog, do a SetIcon() command.

SetIcon(m_hIcon, TRUE); // Set big icon

SetIcon(m_hIconSmall, FALSE); // Set small icon



If you are using Win32, in your WM_CREATE or WM_INITDIALOG:


::SendMessage(hWnd, WM_SETICON, TRUE, (LPARAM)m_hIcon);

::SendMessage(hWnd, WM_SETICON, FALSE, (LPARAM)m_hIconSmall);



You can use the same HICON handle for both if you want, the icon of the proper size is extracted from the handle.

If you want the icon to paint correctly while minimized, you can do an IsIconic() check in OnPaint or WM_PAINT and paint the icon using DrawImage. You really don't need this unless you are using Win95/98 or NT4 versions of explorer where the icon is actually painted.

-Erik

alsyed
June 29th, 2008, 02:04 AM
I Don't use MFC.

And I tried all the non-MFC methods Erik posted, but no luck. :(

egawtry
June 29th, 2008, 11:29 AM
What is your scope on the HICON? The WM_SETICON will set the icon for the system menu, but if it is closed it will not work. Make the HICON a global and try it. Also you could pass it to the Class Instance and the CreateWindow.

-Erik

ovidiucucu
June 29th, 2008, 02:17 PM
[ Redirected thread ]

alsyed
June 29th, 2008, 04:32 PM
ORIGINAL POST

THE PROBLEM HAS NOW BEEN SOLVED

ovidiucucu
June 29th, 2008, 04:45 PM
THE PROBLEM HAS NOW BEEN SOLVED
Great!
Can you please, share with us the solution?

alsyed
July 3rd, 2008, 05:49 AM
Great!
Can you please, share with us the solution?

The solution to this problem is written at the end of the original post (1st post, origin of this thread).