Accessing Resources in Source Code

How do I access resources for use in C++ source code? For example: if I wanted to use a resource icon for a window icon.

So far I have used resource files to create icons for my executables, but I don't know how to use them within the programs.
I think this is what you are looking for: http://gpwiki.org/index.php/C:Custom_Resource_Files
Firstly, you use MAKEINTRESOURCE to covert your resource ID into a usable format. Then, you call LoadIcon or LoadImage to get an HICON. Lastly, you assign that HICON to a value in your window class. hIconSm is used for the icon in the top left corner of the window.
@Computergeek01: I'm glad that you pointed me to that, I will definitely want to use a custom resource file at some point. But for now, I am talking about resources that are stored in the executable. For example, I've got two icons that will be in the executable:
1
2
3
IDI_ICON1 ICON DISCARDABLE "data/icon.ico"

IDI_ICON2 ICON DISCARDABLE "data/smicon.ico"


But, in my code if I try to access "IDI_ICON1", this error comes back:
'IDI_ICON1' was not declared in this scope


@Vexer: I will look into that, thank you.
Last edited on
You will need to define IDI_ICON1 and IDI_ICON2 in your header file, then include that header in your resource file by the standard "#include <>" directive.
Like this:

In your header file:
1
2
#define IDI_ICON1 1
#define IDI_ICON1 2 


Then in your resource file:
1
2
3
4
5
#include "resource.h"

IDI_ICON1 ICON DISCARDABLE "data/icon.ico"

IDI_ICON2 ICON DISCARDABLE "data/smicon.ico"
Thanks vexer, just what I needed. Except I did not need to include the header in the resource file.
Last edited on
Topic archived. No new replies allowed.