How to add an icon to a console application - c++

This seems like a thing that should be quite simple to do, but for some reason I have problems even to google anything on the subject...
How do you add an icon to a console application in Visual Studio. Now, I know how this works with Win32 desktop applications - you have the resource file, and the icon with the lowest ID is simply used as the app's icon. But if I add a new resource file to a console application and even mess around with the icon editor - nothing happens. The target executable still has the same default icon. Is there some kind of difference between a console application and a desktop one regarding resources? Or do I need to also do set something else apart from just adding the resource file with an icon?
Thanks

It should work the same as with normal WinAPI application. In my case the problem was probably caused by windows icons caching. You can verify this is the case by moving the executable to another directory.

Related

Adding a tile to an MFC application

I have a C++ MFC application that has a bunch of dialogs which are defined in an .rc file. I need to add a tile to the application for pinning it to the start menu because the default "tile" that Windows creates from the icon doesn't look very good. Rewriting the whole application to use XAML instead of the .rc file isn't an option right now. The tile doesn't need to be interactive, just display a better looking picture than just slapping the small icon in.
Is there a way to add a tile to an MFC application with an .rc file?
If not, the other idea I had was to create a wrapper application which uses XAML to create a tile, and the only thing the wrapper application would do is launch the MFC application. Does anybody have a better solution?
I am using Visual Studio 2015.
The .ico file I'm using has 768x768, 512x512, 256x256, 150x150, 48x48, 32x32, and 16x16 versions of the image in it.
Edit
There was some confusion about what exactly I needed. Here is an annotated screen shot which hopefully shows the issue clearly.
One other clarification, I don't think this makes any difference, but I thought I'd add it just to be safe. The program does not need to run on Windows 8/8.1, just Windows7 and Windows10
After extensive research it is clear that this is not possible. Not only is it not possible with MFC, but the only way to create a tile (live or static) is with a Windows Universal App. So my solution here is to create a simple launcher program that starts up the MFC application and then exists. However, one caveat here is that Windows Universal programs are not allowed to directly run other programs. What they are allowed to do is open a file with it's default program. So I created a new file extension and assigned the default application to be the MFC program.
this->SetWindowText("SudeshMFCDemo");
https://msdn.microsoft.com/en-us/library/yhczy8bz(v=vs.90).aspx

Qt GUI application with console output - hide console on normal startup on Windows

If I open my application an empty console window appears, since I added CONFIG += console to my .pro file. I need the console, because I've implemented a CLI, where some stuff needs to get printed out on the console. On Linux and Mac OSX, I don't actually need the CONFIG += console there. It just works.
How can I prevent opening a windows console, if the .exe gets executed normally over a double click, but display some outputs if my .exe gets started via a console window?
Basically, I use qDebug() << "myText"; and then after that I exit the application with return 0;.
Unfortunately, Windows is somewhat deficient in this area. A console application will always open up a console, even if you don't want it. You can close it right away, but it still looks bad.
Your application must be a non-console application. On startup, check if you have access to a console, as you would when launched from cmd.exe. Then access cmd's console and inject your output into it.
See my question about this for details.
It is a GUI application? AFAIK it is not possible (or at least not trivial) writing a mixed Qt application that can act as both, a desktop (GUI) application and a console (CLI) application.
I am not sure what you intend to do. If you really need a console variant, try to build two different applications based on the same sources (one console build and one GUI build).
If you only need a GUI application that is able to print out some information, remove the console code and write the output into a file instead.
I think here is an answer for you question: https://stackoverflow.com/a/3370017/1091536
You need console application, than launch your GUI application and prints it's output.
The application for launch your GUI application you can find here https://github.com/gomons/AppDebugLauncher
It's worth noting that under some circumstances the console window won't briefly appear. For example if you run in gui mode via a shortcut with Run set to Minimized: the console window won't appear. Then, in your code, you can restore the size of the gui window. Its a bit of a nasty workaround but masks the behaviour from the user that bit more.
If you're program is going to be installed and usually started via shortcut, then its maybe its an option.

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.

c++ icon in tray

i used qt to make an application in the tray. on my pc its a good project and i see the icon in the traybar, but when i release it to give it to sombody else they dont see the icon, its just an invissible square that can be used but it dont show the icon. but on my pc it shows the icon. :S i know it sounds weird but does anybody know how to solve it? or how to set the traybar icon in the resource file?
this->setWindowIcon(QIcon("favicon.ico"));
a.start();
createActions();
createTrayIcon();
trayIcon->setIcon(QIcon("favicon.ico"));
trayIcon->setVisible(true);
trayIcon->show();
Well, I assume that you forgot to provide the icon together with the executable. But in any case, it would be better to embed the icon as resource in the executable.
Have a look at the Qt resource documentation. Basically, you just need to create a resource file, add the icon and then change the filename to something like this ":/favicon.ico". By adding the ":/" in front of the filename, Qt knows to load this from the embedded resources.

Carbide / Symbian C++ - Change Application Icon

I am using Carbide (just upgraded to 2.0) to develop an S60 3rd Edition application.
I would like to know the easiest way to change the icon (both the application icon on the device menu and the icon at the top left of the main view) because I have the need to skin my application in many different ways as easily as possible.
All my efforts with messing around with .mif files have so far failed. I have a 44x44 .svg icon I made with Illustrator, could someone please help me in the right direction?
Thanks!
To change the app icon when you run your app use (in the status bar):
CEikStatusPane* sp=iEikonEnv->AppUiFactory()->StatusPane();
CAknContextPane* cp=(CAknContextPane *)sp->ControlL(TUid::Uid(EEikStatusPaneUidContext));
_LIT(KContextBitMapFile, "my_bitmap_file.mbm");
CFbsBitmap* bitmap = iEikonEnv->CreateBitmapL(KContextBitMapFile, EMbmBitmap);
CleanupStack::PushL(bitmap);
CFbsBitmap* bitmapmask = iEikonEnv->CreateBitmapL(KContextBitMapFile, EMbmBitmapMask);
CleanupStack::PushL(bitmapmask);
cp->SetPicture(bitmap, bitmapmask);
CleanupStack::Pop(); // bitmapmask
CleanupStack::Pop(); // bitmap
DrawNow();
I'm not aware of any possibility of changing the app icon in the menu list programmatically, other than reinstalling the app with different mif file.
If you want to change the icon in your SIS file and then overinstall it on device then you may have to reboot your device after installation - the application icon is in the Symbian cache and is not updated.
http://wiki.forum.nokia.com/index.php/CS000808_-_Creating_and_adding_an_icon_to_an_S60_3rd_Edition_application
With latest QMake and Qt SDK (4.6.2) you don't need to create any .mif file yourself. An SVG file will do.
For more detailed instructions see: How to Set Qt Application Icon and Title in Symbian S60.
Although the article uses Qt Creator, as long as you use QMake then it's the same thing.