Board index » cppbuilder » Loading bitmaps from resource

Loading bitmaps from resource

I am trying to use TBitmap::LoadFromResourceName function to load bitmaps
from a separate resource file. But the problem is the Instance parameter
required by the function. Online help declares HInstance variable as an int,
but it definitively isn't in BCB, but a void pointer. So what is the proper
way to use LoadFromResourceName function?
 

Re:Loading bitmaps from resource


This has worked for me.

Declare a Graphics::TBitmap variable, then instantiate and set the dimensions...

Graphics::TBitmap* FLeftArrow;

FLeftArrow = new Graphics::TBitmap;
FLeftArrow->Height = IMAGE_HEIGHT;
FLeftArrow->Width = IMAGE_WIDTH;

Next, assuming you have a resource file already associated with the project, and
that it contains, in this case, a bitmap with the name 'SS_LEFT_ARROW', you cast
HINstance to int...

         FLeftArrow->LoadFromResourceName((int)HInstance,"SS_LEFT_ARROW");

And of course when you're done with it don't forget to

delete FLeftArrow;

Quote
> So what is the proper
> way to use LoadFromResourceName function?

Like I said, it has worked for me....

Re:Loading bitmaps from resource


Quote
Dave Richards wrote:
>FLeftArrow->LoadFromResourceName((int)HInstance,"SS_LEFT_ARROW");

So it only needs simple typecasting with (int)HInstance statement. Thanks!
(The online help would need some updating because of this, because the
HInstance variable isn't declared as int like the help states.)

Elmo Alln

Other Threads