问题描述
我想使用的从的。
我已经验证了资源的正确链接 - 检查与十六进制编辑器的最终EXE显示位图正确的包装里面的EXE
I've verified that the resource is linked correctly -- examining the final EXE with a hex editor shows that the bitmap is packed inside the EXE correctly.
我也验证了位图是有效的 - 使用的LoadImage与LR_LOADFROMFILE从在运行时加载磁盘位图工作正常,我看到它的时候出现我把它添加到一个GUI元素后
I've also verified that the bitmap is valid -- using LoadImage with LR_LOADFROMFILE to load the bitmap from disk at runtime works fine and I see it appear when I add it to a gui element later.
我已经验证了,我用它来访问资源的ID是有效的,以及 - 在FindResource函数查找资源和SizeofResource打印的确切字节数预计为位图
I've verified that the ID that I use to access the resource is valid as well -- the FindResource function finds the resource and SizeofResource prints the exact expected number of bytes for the bitmap.
所以我有一个有效的链接资源,有效身份证,以及一个可加载位图。
So I have a valid linked resource, a valid ID, and a loadable bitmap.
不过,LoadBitmap返回NULL也是如此的LoadImage,如果我从一个资源,而不是从磁盘加载。 GetLastError返回0。
However, LoadBitmap returns NULL and so does LoadImage if I load from a resource instead of from disk. GetLastError returns 0.
任何想法?难道我#defining RT_BITMAP在RESOURCE.RC是否正确?
Any ideas? Am I #defining RT_BITMAP in resource.rc correctly?
感谢。
RESOURCE.H
#define BMP_TEST_ID 2
RESOURCE.RC
#include "resource.h" // defines BMP_TEST_ID
#define RT_BITMAP 2
BMP_TEST_ID RT_BITMAP "TEST24.BMP"
test.c以
#include <windows.h> // defines RT_BITMAP as MAKEINTRESOURCE(2)
#include "resource.h" // defines BMP_TEST_ID
HINSTANCE instance = GetModuleHandle(NULL);
if (!instance) { /* handle error */ }
/* find a bitmap resource with the ID we want -- OK! */
HRSRC rsc = FindResource(instance, RT_BITMAP, MAKEINTRESOURCE(BMP_TEST_ID));
if (!rsc) { /* handle error */ }
/* prints the exact size of the found resource -- GIVES CORRECT OUTPUT */
printf("SizeofResource: %d\n", (int) SizeofResource(instance, rsc));
// ***** THIS BIT DOESN'T WORK *****
/* load bitmap resource -- FAIL! */
HBITMAP bitmap = (HBITMAP)LoadBitmap(instance, MAKEINTRESOURCE(BMP_TEST_ID));
if (!bitmap) { /* handle error */ }
/* load bitmap from file -- OK! */
HBITMAP bitmap2 = (HBITMAP)LoadImage (NULL, "TEST24.BMP", IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
if (!bitmap2) { /* handle error */ }
我的编译器是AMD64的mingw32msvc-GCC 4.6.3
My compiler is amd64-mingw32msvc-gcc 4.6.3
推荐答案
首先,你不应该定义 RT_BITMAP
可言。它是通过 WINUSER.H
要包含在你的c / cpp文件已定义。而事实证明,你不需要在你的资源文件反正。
First, you should not have to define RT_BITMAP
at all. It is already defined through winuser.h
to be included in your c/cpp files. And it turns out you don't need it in your resource file anyway.
的 BITMAP
资源类型将正确地分配你的位图文件正确的资源类型ID。更改您的位图资源的声明是:
The BITMAP
resource type will properly assign the right resource type id for your bitmap file. Change your bitmap resource declaration to be:
BMP_TEST_ID BITMAP "TEST24.BMP"
和你应该是好去。
这篇关于FindResource工作,LoadBitmap从磁盘的作品不,的LoadImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!