Assign to console app an icon (program code) in VS2005 - c++

Hi guys :)
I have my console app finished (c++).
And now I'm looking for a way to give it an icon. So when I distribute it, it keeps the icon.
I didn't find anything yet. I would really appreciate some help!
Nobody want to continue helping me? :(

You will need a resource file (.rc) and specify an icon to get it included in the binary. The first icon (the one with the lowest ID number) will be the icon of your application.
Unfortunately the new express editions do not come with an integrated resource editor anymore, but you can use the excellent free alternative ResEd for this task.
You simply have to create a new .rc file, add the icon and then include the .rc file in your c++ project.

Related

How to add an icon to a console application

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.

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

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.

need help using 2 mfc projects in one solution

ive created the first project as mfc application and i have tried to enter the solution another project which created as mfc dll. when i running program the gui from the first solution(demodlg) is shows up. and i want that in a prss of a button in the gui the second gui(CAnalyzerDialog) will show up. i've tried a lot of options and i cant get it done right.
the last option ive tried is this code :
CAnalyzerDialog dlg;
dlg.Create(CAnalyzerDialog::IDD);
please help. thank you for your time
I think the problem is that the program and DLL both have their own resource files, but MFC is only accessing the program resources and ignoring the DLL ones. Look into AFX_MANAGE_STATE and see if that helps.
Have you tried to set CAnalyzerDialog as primary project?
On solution explorer, right click on the CAnalyzerDialog, tick "Set as startup project".
Probably you are trying to elaborate that:
demodlg - EXE
CAnalyzerDialog - DLL
Check the way you link both project(static or dynamic-runtime/compile time).

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.