When I started learning C++ nobody gave me straight answers. In the end, it was all about finding the answers on your own so you can learn. With this, I present to you the three things I would have loved to know when I was starting to learn.
Start by downloading Microsoft Visual Studio Express (the free version). Buying the full version isn’t an option for many of us, and many young learners cannot afford this.
I recommended staying away from MinGW and Java.
How to create program executables compatible with other Windows computers?
Open Visual Studio Express 2013
File > New Project > Installed > Templates > Visual C++ > General > Empty Project
Give your project a Name, Location, and Solution Name (optional)
Navigate to the Solution Explorer and right-click your project name and select “Properties”. In this case, “Datacrunch”.
Configuration Properties > C/C++ > Code Generation > Runtime Library > Multi-threaded (/MT) > Apply > OK
Create a New Text Document and rename it to have the extension “.cpp”
You can set .cpp files to open with Notepad by default.
Changing file extension from .txt to .cpp will give you this prompt:
Open your .cpp file Notepad and type in some C++ code. Save it and close.
Notice the use of #include and system(“PAUSE”).
In the Solution Explorer, under your project, right-click Source Files > Add > Existing Item…
Add your .cpp file and Save just in case. On the menu bar, BUILD > Build Solution
The Output Window should say the build is successful. Follow the path in the Output window to get your executable.
Browse to your project folder and go into the “Debug” folder to find your executable.
Double click the executable to run it like any other program.
Now go ahead and run this executable on other Windows machines. It should work without downloading or installing anything extra.
After getting more fluent with C++, I made all sorts of programs: calculating GPA, converting temperature, solving quadratic equations, and so on. But after making all of these executables, they all looked ugly and had the same generic executable icon (pretty looks like virus you don’t want to open).
Asking other people how to change the icon was a bad idea. They all tell me “you can do it in Visual Studio, the non-express edition”. As with most beginners and young learners, we don’t have (legit) access to this.
Here’s some tips for Express users: Start by creating in icon. Use paint or anything you have access to. Then, save it as a 256-color Bitmap.
Go to http://www.icoconverter.com and convert your image into an icon.
Once you convert, you should get a favicon.ico file downloaded.
Next, create a New Text Document and type in the following:
programIcon ICON “favicon.ico”
Save and close.
If you have Visual Studio installed, check this path for a file called “rc.exe”:
C:\Program Files (x86)\Windows Kits\8.1\bin\x86
Once you confirm it exists, add the path above to your system variables.
Control Panel > System > Advanced System Settings > Environment Variables
Under System Variables, look for “Path” and click “Edit…”
At the end of the “Variable Value”, type in a semi-colon (;) and the path to rc.exe;
Click OK.
Open the command prompt and change directory to where the New text Document was created. Assume the text document is called “datacrunch.txt”.
Type in the following:
rc.exe datacrunch.txt
If you get any errors at this stage, check the .txt file and type the quotation marks (“).
Once successful, a new file with the same name will be created in the same directory, but with the extension “.res”, a resource file (encrypted).
Go back to Visual Studio and go to the Solution Explorer > Right-Click Resource Files > Add > Existing Item…
Browse to your .res file and rebuild your solution.
Check the Output window for the path to your new executable with a custom icon.
Your new program now has a custom icon (so it won’t look like some virus).
Stay tuned for Part III on how to create executable installers!