how use resource files?

Pages: 12
May 19, 2016 at 10:48pm
i undertsand that the MAINICON it's for exe icon:
1
2
3
4
5
6
#ifndef _resource_rc
#define _resource_rc

	MAINICON ICON  "x-7.ico"

#endif 

imagine that i need add more files like MP3 or even a GIF... how can i add them?
May 20, 2016 at 7:22am
i'm confused:
nameID typeID filename
'typeID' it's like a keyword, or i can use any name?
May 20, 2016 at 8:45am
typeId refers to the type of the resource like ICON or WAV or BITMAP etc. The nameID you can choose freely
May 20, 2016 at 10:22am
anotherthing: from resource name(nameID), can i get just the string of filename?
May 20, 2016 at 5:41pm
Why do you need the filename when you have both the resource and its name? That information is lost because it is irrelevant.
May 20, 2016 at 5:47pm
my big problem is how i can get the file extension. what you can tell me?
May 20, 2016 at 8:31pm
Why do you need the file extension? You already know what it is - you're already hard-coding the files in the resources, may as well hard-code the file extensions in your code.
May 20, 2016 at 10:02pm
you have right.. the typeID can be the file format for help more ;)
thanks for all
May 22, 2016 at 6:56pm
i need more help... i'm falling on using the resources :(
resource file:
1
2
3
4
5
6
7
#ifndef _resource_rc
#define _resource_rc


	MAINICON ICON  "x-7.ico"
    songoku ICO "C:\\Users\\Cambalinho\\Documents\\CodeBlocks\\classcontrols\\bin\\Release\\x-7.ico"
#endif 

on main.cpp:
mnuExitSys.imgMenu.FromResource(songoku, "ICO");
error: 'songoku' was not declared in this scope.
can anyone tell me where i faill?
May 22, 2016 at 9:14pm
Cambalinho wrote:
mnuExitSys.imgMenu.FromResource
I am not familiar with this code - what library or framework are you using? Is this pure C++, or is this C++/CLI?
May 22, 2016 at 9:17pm
my how library... it's pure C++. but i was doing several problems without know it. give me sometime, i will be back. and now i get the image.
May 22, 2016 at 9:43pm
i need create a resource.h for resource consts:
#define songoku 101
the resource.h must be inclued on main.cpp and on resource.rc:
1
2
3
4
#include "resource.h"

MAINICON ICON  "x-7.ico"
songoku ICON "C:\\Users\\Cambalinho\\Documents\\CodeBlocks\\classcontrols\\bin\\Release\\x-7.ico"

and on LoadImage():
1
2
3
void FromResource(DWORD strResource, string strType)
{
HICON hicon = (HICON)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(strResource), IMAGE_ICON, 0, 0, NULL);

how i use it:
mnuExitSys.imgMenu.FromResource(songoku, "ICON");
i need more help:
- with 'songoku', can i get the type?(because i use 2 parameters on FromResource)
May 22, 2016 at 10:14pm
Read the documentation more carefully:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms648045

The second parameter should be MAKEINTRESOURCE(songoku), since you are loading by ordinal and not by name. You may need to refactor your FromResource function.
May 22, 2016 at 10:43pm
honestly i don't know use the string name. just with ' MAKEINTRESOURCE(songoku)'.
maybe you can teach me how use it... but i continue with same problem :(
how can i get the resource type?
i'm sorry, but what means 'refactor'?(i'm portuguese)
May 23, 2016 at 12:11am
Why do you need to get the resource type? You already know what it is - you wrote it once in the resource file, just write it again in your code.

Refactor:
https://en.wikipedia.org/wiki/Code_refactoring
https://pt.wikipedia.org/wiki/Refatora%C3%A7%C3%A3o
May 23, 2016 at 10:36am
i mean for avoid the second parameter on FromResource(). what you can advice me more?
May 23, 2016 at 2:35pm
Why is it a problem to provide the second parameter?
May 23, 2016 at 5:01pm
for do the things automatic
May 23, 2016 at 5:03pm
for do the things automatic

Huh? Could you rephrase that?
Pages: 12