📄 rc.c
字号:
return n;
}
//-------------------------------------------------------------------------
void define_dlginclude(RES_ID *id, RES_INFO *resinfo, char *filename)
{
unsigned char *data;
RES_RES *r;
long size;
data = AllocateMemory(size = strlen(filename) + 1);
strcpy(data, filename);
r = define_standard_resource(&resources, RT_DLGINCLUDE, id, resinfo
->language, 0);
r->type = RST_DLGINCLUDE;
r->u.data.length = size;
r->u.data.data = data;
r->info = *resinfo;
}
//-------------------------------------------------------------------------
void define_font(RES_ID *id, RES_INFO *resinfo, char *filename)
{
FILE *e;
unsigned char *data;
RES_RES *r;
long offset;
long fontdatalength;
unsigned char *fontdata;
struct fontdir *fd;
const char *device, *face;
struct fontdir **pp;
char buf[256];
long size;
strcpy(buf, filename);
e = SearchPath(buf, prm_searchpath, "rb");
if (!e)
fatal("File Not Found %s in line %d", filename, lineno);
size = filesize(e);
data = AllocateMemory(size);
get_data(e, data, size);
fclose(e);
r = define_standard_resource(&resources, RT_FONT, id, resinfo->language, 0);
r->type = RST_FONT;
r->u.data.length = size;
r->u.data.data = data;
r->info = *resinfo;
offset = ((((((data[47] << 8) | data[46]) << 8) | data[45]) << 8) |
data[44]);
if (offset > 0 && offset < size)
device = (char*)data + offset;
else
device = "";
offset = ((((((data[51] << 8) | data[50]) << 8) | data[49]) << 8) |
data[48]);
if (offset > 0 && offset < size)
face = (char*)data + offset;
else
face = "";
++fonts;
fontdatalength = 58+strlen(device) + strlen(face);
fontdata = AllocateMemory(fontdatalength);
memcpy(fontdata, data, 56);
strcpy((char*)fontdata + 56, device);
strcpy((char*)fontdata + 57+strlen(device), face);
fd = AllocateMemory(sizeof *fd);
fd->link = NULL;
fd->index = fonts;
fd->length = fontdatalength;
fd->data = fontdata;
for (pp = &fontdirs; *pp != NULL; pp = &(*pp)->link)
;
*pp = fd;
fontdirs_resinfo = *resinfo;
}
//-------------------------------------------------------------------------
void define_icon(RES_ID *id, RES_INFO *resinfo, char *filename)
{
FILE *e;
int type, count, i;
struct icondir *icondirs;
int first_icon;
RES_RES *r;
struct group_icon *first, **pp;
char buf[256];
strcpy(buf, filename);
e = SearchPath(buf, prm_searchpath, "rb");
if (!e)
fatal("File Not Found %s in line %d", filename, lineno);
get_word(e);
type = get_word(e);
count = get_word(e);
if (type != 1)
fatal("icon file `%s' does not contain icon data", buf);
/* Read in the icon directory entries. */
icondirs = AllocateMemory(count *sizeof * icondirs);
for (i = 0; i < count; i++)
{
icondirs[i].width = getc(e);
icondirs[i].height = getc(e);
icondirs[i].colorcount = getc(e);
getc(e);
icondirs[i].u.icon.planes = get_word(e);
icondirs[i].u.icon.bits = get_word(e);
icondirs[i].bytes = get_long(e);
icondirs[i].offset = get_long(e);
if (feof(e))
fatal("Data too short in %s", buf);
}
/* Define each icon as a unique resource. */
first_icon = icons;
for (i = 0; i < count; i++)
{
unsigned char *data;
struct res_id name;
if (fseek(e, icondirs[i].offset, SEEK_SET) != 0)
fatal("file i/o error on %s", buf);
data = AllocateMemory(icondirs[i].bytes);
get_data(e, data, icondirs[i].bytes);
++icons;
name.hasname = 0;
name.v.id = icons;
r = define_standard_resource(&resources, RT_ICON, &name, resinfo
->language, 0);
r->type = RST_ICON;
r->u.data.length = icondirs[i].bytes;
r->u.data.data = data;
r->info = *resinfo;
}
fclose(e);
/* Define an icon group resource. */
first = NULL;
pp = &first;
for (i = 0; i < count; i++)
{
struct group_icon *cg;
/* For some reason, at least in some files the planes and bits
are zero. We instead set them from the color. This is
copied from rcl. */
cg = AllocateMemory(sizeof *cg);
cg->link = NULL;
cg->width = icondirs[i].width;
cg->height = icondirs[i].height;
cg->colors = icondirs[i].colorcount;
cg->planes = 1;
cg->bits = 0;
while ((1 << cg->bits) < cg->colors)
++cg->bits;
cg->bytes = icondirs[i].bytes;
cg->index = first_icon + i + 1;
*pp = cg;
pp = &(*pp)->link;
}
free(icondirs);
r = define_standard_resource(&resources, RT_GROUP_ICON, id, resinfo
->language, 0);
r->type = RST_GROUP_ICON;
r->u.group_icon = first;
r->info = *resinfo;
r->info.memflags |= MF_PURE;
}
//-------------------------------------------------------------------------
void define_menu(RES_ID *id, RES_INFO *resinfo, struct menuitem *menuitems)
{
struct menu *m;
RES_RES *r;
m = AllocateMemory(sizeof *m);
m->items = menuitems;
m->help = 0;
r = define_standard_resource(&resources, RT_MENU, id, resinfo->language, 0);
r->type = RST_MENU;
r->u.menu = m;
r->info = *resinfo;
}
void define_messagetable(RES_ID *id, RES_INFO *resinfo, char *filename)
{
FILE *e;
unsigned char *data;
RES_RES *r;
char buf[256];
long size;
strcpy(buf, filename);
e = SearchPath(buf, prm_searchpath, "rb");
if (!e)
fatal("File Not Found %s in line %d", filename, lineno);
size = filesize(e);
data = AllocateMemory(size);
get_data(e, data, size);
fclose(e);
r = define_standard_resource(&resources, RT_MESSAGETABLE, id, resinfo
->language, 0);
r->type = RST_MESSAGETABLE;
r->u.data.length = size;
r->u.data.data = data;
r->info = *resinfo;
}
//-------------------------------------------------------------------------
void define_rcdata(RES_ID *id, RES_INFO *resinfo, struct rcdata_item *data)
{
RES_RES *r;
r = define_standard_resource(&resources, RT_RCDATA, id, resinfo->language,
0);
r->type = RST_RCDATA;
r->u.rcdata = data;
r->info = *resinfo;
}
struct rcdata_item *define_rcdata_string(char *string, int len)
{
struct rcdata_item *ri;
char *s;
ri = AllocateMemory(sizeof *ri);
ri->link = NULL;
ri->type = RCDATA_STRING;
ri->u.string.length = len;
s = AllocateMemory(len);
memcpy(s, string, len);
ri->u.string.s = s;
return ri;
}
struct rcdata_item *define_rcdata_number(long val, int dword)
{
struct rcdata_item *ri;
ri = AllocateMemory(sizeof *ri);
ri->link = NULL;
ri->type = dword ? RCDATA_DWORD : RCDATA_WORD;
ri->u.word = val;
return ri;
}
void define_stringtable(RES_INFO *resinfo, long stringid, char *string)
{
RES_ID id;
RES_RES *r;
id.hasname = 0;
id.v.id = (stringid >> 4) + 1;
r = define_standard_resource(&resources, RT_STRING, &id, resinfo->language,
0);
if (r->type == RST_UNINITIALIZED)
{
int i;
r->type = RST_STRINGTABLE;
r->u.stringtable = AllocateMemory(sizeof(struct stringtable));
for (i = 0; i < 16; i++)
{
r->u.stringtable->strings[i].length = 0;
r->u.stringtable->strings[i].string = NULL;
}
r->info = *resinfo;
}
r->u.stringtable->strings[stringid &0xf].length = unicode_from_ascii( &r
->u.stringtable->strings[stringid &0xf].string, string, strlen(string));
}
//-------------------------------------------------------------------------
void define_user_data(RES_ID *id, RES_ID *type, RES_INFO *resinfo, struct
rcdata_item *data)
{
RES_RES *r;
r = AllocateMemory(sizeof(*r));
r->type = RST_USERDATA;
r->u.userdata = data;
r->info = *resinfo;
AddResource(&resources, r, type, id, resinfo->language, 0);
} void define_user_file(RES_ID *id, RES_ID *type, RES_INFO *resinfo, char
*filename)
{
FILE *e;
unsigned char *data;
RES_RES *r;
char buf[256];
long size, xsize;
strcpy(buf, filename);
e = SearchPath(buf, prm_searchpath, "rb");
if (!e)
fatal("File Not Found %s in line %d", filename, lineno);
xsize = size = filesize(e);
// if (size & 1)
// size++ ;
data = AllocateMemory(size);
get_data(e, data, xsize);
fclose(e);
r = AllocateMemory(sizeof(*r));
r->type = RST_USERDATA;
r->u.userdata = AllocateMemory(sizeof(struct rcdata_item));
r->u.userdata->link = NULL;
r->u.userdata->type = RCDATA_BUFFER;
r->u.userdata->u.buffer.length = size;
r->u.userdata->u.buffer.data = data;
r->info = *resinfo;
AddResource(&resources, r, type, id, resinfo->language, 0);
}
//-------------------------------------------------------------------------
void define_versioninfo(RES_ID *id, RES_INFO *info, struct fixed_versioninfo
*fixedverinfo, struct ver_info *verinfo)
{
RES_RES *r;
r = define_standard_resource(&resources, RT_VERSION, id, info->language, 0);
r->type = RST_VERSIONINFO;
r->u.versioninfo = AllocateMemory(sizeof(struct versioninfo));
r->u.versioninfo->fixed = fixedverinfo;
r->u.versioninfo->var = verinfo;
r->info = *info;
}
static void define_fontdirs(void)
{
RES_RES *r;
RES_ID id;
id.hasname = 0;
id.v.id = 1;
r = define_standard_resource(&resources, RT_FONTDIR, &id, 0x409, 0);
r->type = RST_FONTDIR;
r->u.fontdir = fontdirs;
r->info = fontdirs_resinfo;
}
//-------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -