No Window Icon Using SDL_SetWindowIcon() - c++

I'm currently developing a game with SDL2 in C++ and I want to set my game's icon for the task bar and for the Alt-Tab switcher. I am trying to achieve this by using SDL_SetWindowIcon():
SDL_Surface* icon = IMG_Load("icon.png");
SDL_SetWindowIcon(sdlWindow, icon);
Even if my window is correctly initialized and the surface is loaded, the icon does not appear in the task bar or in the Alt-Tab switcher. I am on Ubuntu 16.04 LTS.
Does anyone know what I'm doing wrong?

I'm not going to claim that I understand how this function works, but I can share with you how I got it to work. Even though I could use a 600x600 (pixels) image in the desktop.my_app file, and using that launcher would work fine, SDL2 would NOT load a 600x600 image. I tried 128x128 too, and that didn't work.
Changing the image size to 64x64 miraculously fixed it. Storage issue? I don't know why SDL2 can handle huge SDL_Surface s in other parts of the app but not the window icon....

Rather then taking this tough path, if you set Icon through the IDE it will appear everywhere, I mean everywhere such as File explorer, Taskbar, SDL Window or its(exe) shortcut etc.
follow these steps for Visual Studio
You need to use an .ico file. You cannot use a PNG image file for your executable's icon, it will not work. You must use .ico. There are online converters available for image to .ico files.
I will recommend this https://convertico.com/
because it was multiple icons in single file option which many tools dont provide (this is not a promotion/Ad)
The ico used for your exe will be the ico with the LOWEST RESOURCE ID. In order to change the .ico
Open VIEW > RESOURCE VIEW (in the middle of the VIEW menu), or press Ctrl+Shift+E to get it to appear.
In Resource view, right click the project name and right click "ADD" -> "RESOURCE..."
Single Click on "Icon" then from the list of many items, then click "IMPORT..".
When a file selection will open *.ico files aren't listed, and you can't use a regular PNG or JPG image as an icon, so change the file filter to *.ico using the dropdown.
Now you are done. you can see the icon available everywhere
If you load a bunch of ICO files into the project for whatever reason, be sure the .ico you want Visual Studio to use has the lowest id in resource.h. You can edit this file manually with no problems
Eg.
//resource.h
#define IDI_ICON1 102
#define IDI_ICON2 103
IDI_ICON1 is used
//resource.h
#define IDI_ICON1 106
#define IDI_ICON2 103
Now IDI_ICON2 is used.

Related

Change my executable icon

I am new to changing default icons on c++ console applications. But recently, I have been wanting to know how it is accomplished. I managed to save an .ico file and when I build my application in Release mode I open it and I see the new image show up when my window is running and then a tiny icon showing up in the top left hand of the screen, and seeing that made me very happy.
But I wanted to know how can I change the image of my executable file so that it is consistent with my program?
From this...
To this...
Can anyone help me figure out what the steps are to change the default executable icon to the one I want? Many thanks in advanced!
Add a new file to the existing projekt and select as file type
"Symbol (ico)" in the "Resource" category.
Draw it, save it, compile again, finished.
Windows will automatically display the icon with the lowest ID (if any).
If there is only one icon, it can be only that one...
edit: You should make different sizes (16x16, 32x32, 64x64 etc.).

How can I change the default .exe icon in Visual Studio 2012 (C++)

I was wondering if there was a way to change the default icon that VS2012 makes when I compile my app. Just for those wondering, I am trying to change the .exe program's icon, not the window icon at the top left of the window and on the start menu. I already know how to do that. I have been Google-ing this for ever and it always shows up how to change the window icon, not the actual file's icon. Thanks in advance!!!
EDIT: This is what I want to do...
I want to replace this...
with this...
]
Thanks, hope this clarifies.
Adding icon to executable
Tested for VS2012 Express
Create a icon.rc file next to your .vcxproj file and fill it with the following text:
// Icon Resource Definition
#define MAIN_ICON 102
MAIN_ICON ICON "your_icon.ico"
Then add the following to your .vcxproj file anywhere within the Project tag:
<ItemGroup>
<ResourceCompile Include="icon.rc">
</ResourceCompile>
</ItemGroup>
Additional options
If you want you may forward definitions to your icon.rc file like so:
<ItemGroup>
<ResourceCompile Include="icon.rc">
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">/D_DEBUG %(AdditionalOptions)</AdditionalOptions>
</ResourceCompile>
</ItemGroup>
Notice the /D_DEBUG definition, which defines _DEBUG for your resource file. Then within your icon.rc file check for definitions normally:
#define MAIN_ICON 102
#if defined(_DEBUG)
MAIN_ICON ICON "debug_icon.ico"
#else
MAIN_ICON ICON "release_icon.ico"
#endif
Add an icon in the resource section of you C++ project. This icon will be shown as an Application icon for your executable. [Note: make sure you are in the Resource View window, not the Solution Explorer window. Then right-click on the rc folder to Add Resource...]
I have tried this with Win32 Console Application and it shows the icon in the Explorer as Application Icon. This should work with other types of applications also.
Also note that while adding the icon you need to add different size images for the Icon like 16*16, 32*32. These different icon images will be used by Windows Explorer to display Application Icon in different View Modes(Small Icons, Medium Icons, Larget Icons, Extra Large icons etc.)
This is not really how it works. The size of the icon of your program as displayed by Windows isn't determined by you, the user selects it. It is a user preference, very simple to change on later Windows versions by just rolling the mouse scroll button on the desktop. And an icon doesn't have just a single size, it is capable of storing multiple images. Windows picks the one that fits best. And the one you get when starting a new project is just a stock one that's stored in the project template. You can change it by tinkering with the project template .zip file but that's kinda pointless, you want to give your program a custom icon that personalizes it.
Best thing to do is to steal, beg or borrow one, making a good looking icon is an art. Lots of web sites where you can download free ones. If you want to take a shot at creating your own then that's supported as well. Simply double-click the project's .rc file to open the resource view, open the Icon node and double-click the default icon to open the icon editor. You add a new size with Image + New Image Type. Plenty of freeware icon editors available as well.
If its a Win32 application then you can add a resource to your project and then put the icon in there. Then you can assign the icon to your application by sending the WM_SETICON method. For MFC applications, resources are already present and there is a nominated icon resource that you can just change.
You can also load it directly from an external file as suggested here:
Setting program icon without resources using the WIN32 API
I would recommend the resource route though. Resources get embedded in your executable and it is the recommended way to do this sort of thing in Win32 and MFC.

GLUT_ICON not working on top left window

am trying to add an icon application that uses freeglut, according to the doc here it seems is enough to have an icon resource GLUT_ICON.
Although it worked, it only appears on the icon of the console window and the executable in windows explorer, but the main window remains with the default windows icon (as shown in the image). I tried building without the console window mode, but I get same behavior, is this the way it suppose to work or am getting a wrong behavior?
This might help clear things for others running into the same problem:
https://www.gamedev.net/forums/topic/151647-opengl-glut-icon/
Basically, in the "file.rc"resource-file (right click view code) that appears after adding an ico resouce, where you should have
MAINICON ICON "compiler_assets\\icon-name.ico" //set main icon to "file"
You should add another line
GLUT_ICON ICON DISCARDABLE "compiler_assets\\icon-name.ico"
Which is basically setting GLUT_ICON to a specific .ico file
Finally fixed this problem. Whether this issues come from the VStudio2012 environment or not is uncertain.
But generating the resource id like this; GLUT_ICON creates a non-defined behavior. The exe is unable to identify this tag as a valid one, therefore no icon can be indexed and found.
By just changing to lower case the string, all problems get fixed.
I did this process manually and the fix seems to be consistent between PC's.

Add icon resource without changing the EXE icon?

I've added an icon resource to my program. Unfortunately, it's a 16x16 icon meant as a visual aid on a button, and now it's set as the executable's main icon. Obviously, this looks terrible.
Is it possible to add a resource while retaining the EXE's icon as the Windows default?
I'm using Visual Studio 2010, if that helps.
It looks like your 16x16 icon is the only icon resource in your application, or the one with the smallest identifier. In that case, both Explorer (for its file lists) and the window manager (for the window's title bar) will default to that icon.
You should add another icon to your application, with an id less than the id of your 16x16 icon, so it will become the default icon. If you want to use the default application icon, you can get it from the Visual Studio Image Library.
You can do it manually. You can add an identifier in resource.h, rc file and then use it by calling required function with parameter MAKEINTRESOURCE(IDENTFIER) to make the cast from id to image.
One option would be to put your icons in a separate module, i.e. a DLL. This would stop the system using them for application icons and avoid the need to add your own copy of the default system application icon.

Changing program icon dynamically

In C++, is there anyway to let the user chose the icon of the app? For example, Winamp lets you select which icon you wish to use from a list of icons in it's preferences. How is it done?
There is the icon that you see in explorer. This is a resource in your executable. You could change that, but I wouldn't advise you too. Virus scanners can get nervous if executables are modified, and in Windows Vista you will not even be allowed to write in the Program Files folder.
But the icon that is displayed on the task bar or in the system tray can be changed. This is actually the icon of your application window and it can be set by sending a WM_SETICON message.
And there are shortcuts. They can be changed too, and in a shortcut you can specify which icon should be used.
I found a discussion on changing icons that has information about the first two options.
For Visual Studio 2010 in an MFC dialog based app
A. In the resource view, rightclick Icon folder and add icon. Give it an ID like IDI_MYICON. Leave it as is or draw something nice.
B. Go to OnInitDialog. Add the following two lines of code:
HICON hMyIcon = LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_MYICON) );
SetIcon( hMyIcon, FALSE ); // FALSE == use as small icon
You can read about these functions in the help to understand what is happening.
This sets the icon as icon for the sysmenu (topleft) and in the taskbar. This is however not automatically reflected in all situations. E.g. for a systray icon you need to explicitly specify the icon again in the call to Shell_NotifyIcon().