An analog for Qt resource files? - c++

I need something similar to the resource system that Qt has.
Instead of writing the full path to the files and dragging them with the program, I would like to create a single file like Qt does and enter relative file paths.
I can't use Qt in my project, and using the. rc files that Visual Studio provides is very complex and cumbersome.
What can I use instead?

You might need the .resx Resource Files.
A way to create this is to open Visual Studio:
Right-click your project
Select Add | New Item
Select Resources File
Give it a name (e.g. Resources)
Click Add
You will now have a Resources file in your project with the name you provided, and it should auto-open the resources editor. If it doesn't, double-click it in the project.
In the top-left of the editor, click the "Strings v" drop down and select "Icons".
Drag your icon into this screen.
Rename it to whatever you want (e.g. something).
If you familiar with the QT Resource files you will get to use it in no time.
Source: How to create resx files
Brief doc: https://learn.microsoft.com/en-us/dotnet/framework/resources/creating-resource-files-for-desktop-apps
https://learn.microsoft.com/en-us/dotnet/framework/resources/working-with-resx-files-programmatically

Related

How to specify an application icon for C++ Visual Studio 2019?

I've seen this documentation for C#/Visual Basic application icons, but there is nothing I can find for how to do this with the C++ version.
This StackOverflow question is for Visual Studio 2008, not 2019. This one is also obsolete, as it works for Visual Studio 2017 but not Visual Studio 2019.
After some fiddling I figured it out. This answer for VS2017 was basically correct, but it didn't fully explain what you have to do to get it to work and the documentation it links to was vague enough to confuse me, so I'll post this answer as the VS2019 version with full and complete easy-to-follow instructions.
Navigate to your Solution Explorer tab.
Find the Resource Files folder in your project, probably near your Header Files and Source Files folders.
Right-click on the Resource Files folder and select "Add > Resource."
In the "Add Resource" window that pops up, select Icon and select Import.
Import either a bitmap file or your custom .ico file.
Now a Resource File (.rc) is created which contains your application Icon, in the form of an Icon node. Click on that .rc file to open the Resource View tab.
You'll see that there's a folder called Icon. It should contain your new icon.
If it contains a default Icon file, probably named IDI_ICON1, you'll have to edit that node to make it the icon you want to use. I don't know why it does that.

Can we change an exe icon according to the current solution configuration?

I want to know if there's a simple way to change my exe icon depending on compilation in release / debug / other configuration.
IDE is Visual Studio 2013, source code in C++.
Thanks in advance.
It may be possible using a combination of tricks.
Create an icon for each configuration and store them each in a folder with the same name as the configurations you use (like Debug, Release).
Use $(ConfigurationName) in a pre-build command line. Create a batch file to copy the correct icon to the 'source' location. In other words if the application icon is .\App.ico create a batch file: 'copy .\%1\App.ico .\App.ico' or similar. (obviously get the paths correct).
The batch will execute and overwrite the app icon with the custom build icon.
Change configuration and the icon can change. Just make sure that all icons are the same size.
I have used this to copy a text file into my builds - cannot see why it cannot work with icons.

How do you create the "Shader" folder in Visual Studio interface

I have seen several projects with the "Shader" folder in the Solution Explorer.
However, when I create one myself, I can only see "Header files", "Source files", "Resource files", and "External dependencies" folder.
Is there a way to tell Visual Studio I need a "Shader" folder because I'm going to use shaders?
If not, how can I create it manually?
Visual Studio has virtual folders called "Filters". These can map to real folders in the file system or you can just use them to define logical/conceptual groups of items inside your projects.
To create a filter under a project in Visual Studio, just right-click with the mouse on your project in the Solution Explorer, expand "Add" and click "New Filter". A new filter ("NewFilter1") will be created under your project which you can then rename as you like.
You can drag items from your project inside it in order to group them "logically" or you can right-click on your new filter and choose Add>Existing Item or Add>New Item. You can even nest multiple filters inside each other.
For example in your case, you would call this filter "Shader" and you can drag-and-drop all shader-related files inside it. This only affects your project and not the directory structure in the file system.
You can still create a "real" folder in the file system and then add files into it, which you can then reference in your project's filter.

How to build the project which contains the active file in visual studio?

I am using visual studio 2010. My code is in C++ and my solution contains many projects and each project again contains multiple folders under it. Whenever I change a file it gets automatically selected in solution explorer as I have enabled the option "Track Active Item in Solution Explorer" in Tools->Options->Projects and Solutions->General. But after changing the file I have to manually select the project (this could be cumbersome as I have to scroll up and down due to many files present) and then right click on it and select "build". Is there any other simple way to do this?
You could assign a shortcut to Build.BuildSelection or Build.BuildOnlyProject
Go to Tools menu, then Options=>Environment=>Keyboard and enter Build.BuildSelection or Build.BuildOnlyProject in the Show commands containing search text area. Then assign two free shortcuts. Build.BuildSelection is for building the current file; Build.BuildOnlyProject will build its project.
I use ctrl-shift+b to build all the solution. I hate to use the mouse for those repetitive tasks.

How to change the default *.exe icon in C/C++?

I want to change the default .exe icon to some other icon in C/C++. Does anybody know how to do that?
Already answered.
Change app icon in Visual Studio 2005?
You have to place your .ico file in the resources folder first of course.
Use this one: http://www.angusj.com/resourcehacker/
Since you specified that you are using VS2008 I can point you here: How do I set the icon for my application in visual studio 2008? (duplicate question)
On Windows, if the executable contains many icons, the 1st of them will be the default.
If you have icons resource in your programming environment, place the icon you want first in the list.
Edit: since you created an empty project, to add an icon, follow these instructions:
(as I said in my comment, I don't have VS2008, but the steps should be the same)
Menu: Insert -> Resource -> Import
Select "Icon", press the import button and select your icon file.
Now, close the icon editor, and save the resource script in the project folder.
Select "Files View" and add the resource script file in the "Resource Files".
That's it.
if you are using any ide like dev c++, then you can specify the icon you want to appear on your file in project options