Question

I'm currently linking to the >dynamic< libs in SFML but I have no idea how to add resources in Visual Studio 2013 Express C++. I've quite recently started out with C++, coming from C# where adding resources is as simple as drag-n-drop.

I know there's something with .rc files and headers, but I didn't find any guide on it. What I need to do is add the dll's so I don't have to manually paste them with the .exe and I also need to add .png's. Right now I'm loading them from a folder next to the executable, I don't wanna do that.

How do I do this?

Was it helpful?

Solution

You can just add an [.rc] file to the project.

An [.rc] file is a purely textual resource script that you can edit as text, or you can use various 3rd party resource editors (you don't need that for adding image resources, just check out the RC syntax).

Visual Studio Express lacks resource editors, but does support automatic recognition of, compilation of and linking of resources.


Example

Here's an example [.rc] file, just a single line, using a free icon that I just downloaded from the net:

100 ICON "resources\\Bad-Blood-Yolks-Grin.ico"

Corresponding C++ source code, presenting the icon in a message box:

#undef UNICODE
#define UNICODE
#include <windows.h>

auto main() -> int
{
    MSGBOXPARAMS params = {sizeof( params )};
    params.hInstance        = GetModuleHandle( nullptr );
    params.lpszText         = L"Click OK to dismiss this box.";
    params.lpszCaption      = L"Καλὴ τύχη!";        // "Good luck!" in Greek.
    params.dwStyle          = MB_USERICON;
    params.lpszIcon         = MAKEINTRESOURCE( 100 );

    MessageBoxIndirect( &params );
}

Result:

enter image description here

All done in Visual C++ Express for Desktop 2013, or whatever it calls itself. :-)

In order to synchronize identifiers between resource script and C or C++ code it's common to include a header. The resource compiler understands the most basic C preprocessor directives.

Oh, also, I added the [.rc] file as just a text file. Visual Studio Express reacts to the renaming, "rc" file extension, by popping up a warning box that it isn't supported. Just ignore the box, and to edit the file right-click and choose text editor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top