alvinleetya
alvinleetya

Reputation: 464

Visual C++ Get a resource's path

I'm trying to add an image to Visual C++ project and obtain it's path. Basically what I want is to add a few images to the projects so it can run on any computer by fetching the necessary images inside the project instead that on the local drive.

I added the images by a right click on resources files (in the solution explorer menu) and add->existing element.

But the element still have it's local path (C:/images/.../img.jpg). How can I properly add these images to my project and be able to obtain their paths?

Thanks

Upvotes: 4

Views: 8063

Answers (2)

BigBoss
BigBoss

Reputation: 6914

Images that added to resource file will be compiled and embedded into your code not in a directory outside of your program and you can access them at runtime using FindResource/LoadResource

Upvotes: 2

Mert Akcakaya
Mert Akcakaya

Reputation: 3129

Create a resources directory, copy your images into this directory (basic file system operation), then from VS click Add Existing Item and browse this directory and add all images.

Now you have copied all your images into this directory but you still have to know the relative path, in this case it will be something like "Resources/myImage.png".

Upvotes: 1

Related Questions