Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add resources and to use them

In my application i want to add 2 images as resources

I want to use those images ,when i click yes button in my application first image will be set as wallpaper and when i click on No button in my application second image will be set as desktop wallpaper

thanks in advance

regards

like image 351
noob Avatar asked Dec 18 '09 14:12

noob


1 Answers

The easiest way is to create a text file and name it resources.rc or something (as long as it isn't the same name as your project file as that already has a resource file of its own).

If you're adding images, you'll need to add lines such as:

IMG_1 BITMAP "c:\my files\image1.bmp"
IMG_2 RCDATA "c:\my files\image2.jpg"

Note that the first parameter is an unique identifying resource name. The second parameter is the resource type. Some constants are available such as BITMAP and AVI. For others, use RCDATA. The third parameter is the full path and file name of the resource.

Now, in Delphi, you can add this .rc file to your project in the project manager.

To use the resources, you need different methods according to the resource type.

To load a bitmap, you can use:

imgWallpaper1.Picture.Bitmap.LoadFromResourceName(HInstance, 'IMG_1');

To load a JPEG, you need to convert it like this:

var
   jpgLogo: TJpegImage;
   RStream: TResourceStream;
begin
     RStream := TResourceStream.Create(HInstance, 'IMG_2', RT_RCDATA);
     Try
        jpgLogo := TJpegImage.Create;
        Try
           jpgLogo.LoadFromStream(RStream);
           imgLogo.Picture.Graphic := jpgLogo;
        Finally
           jpgLogo.Free;
        End;
     Finally
        RStream.Free;
     End; {Try..Finally}
like image 60
J__ Avatar answered Sep 27 '22 22:09

J__