Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How cand I include a bitmap in my custom component (if is possible)?

I am writing a component (a button) which needs a bitmap to be displayed on it. I don't want to make an ImageList property and the user assigns an image. I want that button to have only the image chosen by me.

I tried to include the bitmap in a resource file but when I try to access it I get "Resource not found" error message. This is what I've done:

myres.rc

FIXED BMP "fixed.bmp"

I compiled the resource file with: brcc32 myres.rc

Then I included it in my component unit...

implementation
{$R .\resources\myres.res}

And access it with...

MyComponent.Glyph.LoadFromResourceName(HInstance,'FIXED');
// MyComponent = class(TSpeedButton)

Edit1: I deleted the {$R .\resources\myres.res} directive and I loaded the resource from menu Project -> Resources and it's working, both with HInstance or FindClassHInstance(MyComponent).

Using a resource editor I found that when I load the resource from the menu the resource appears with the name "FIXED" as it should, but when I load the resource compiled with brcc32 it appears with the name "0". It seems that brcc32 doesn't set the name correctly.

But I don't want to load it from menu, I want it to be loaded automatically with the component.

Edit2: Remy Lebeau is correct. I was using a wrong BMP format (the file starts with 'BM6' characters instead 'BM8' like Photoshop produce it, and it works).

like image 344
Marus Gradinaru Avatar asked Jan 08 '23 05:01

Marus Gradinaru


1 Answers

Change BMP to BITMAP in your RC file, and change HInstance to FindClassHInstance() in your code:

FIXED BITMAP "fixed.bmp"

Glyph.LoadFromResourceName(FindClassHInstance(MyComponent), 'FIXED');
like image 89
Remy Lebeau Avatar answered Jan 19 '23 02:01

Remy Lebeau