Solved

how to use a resource file

Posted on 1998-11-11
7
175 Views
Last Modified: 2010-04-04
I've created an object that uses a lot of small bitmaps and resources.

I used to load a file whenever I needed it, but this takes too long and a file gets loaded everytime I want to display a bitmap or play a wave file.

I put these files in a resource file and have created and compiled a .res file. I'm now looking for a way to load these files into memory and use them from there on without having to reload it everytime. I think I can use streams for this, but I'm not sure what exactly they are and how I can use them.

Can someone explain to me how to load wave and bitmap files from a resource into memory and then load them from memory into a tbitmap and play the sound using PlaySound as much as I want to without having to reload it?

Thanks,
Michael
0
Comment
Question by:michaelsanders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 3

Expert Comment

by:philipleighs
ID: 1346587
The easiest way is to put a TImage on your form, set the picture property and make it invisible.
You can draw it onto the form canvas by:

Canvas.Draw(50, 50, Image1.Picture);

The bitmap is part of the exe, and is loaded when the form is created.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1346588
Here is how....

Once way to do that is to create a bitmap and load it at run-tim as follows.,..

//Gloabal Var...

var
  b : TBitmap;

OnCreate()
b := TBitmap.Create;
b.loadfromfile(Filename);

OnPaint() //Or somewhere else...wherever you want to draw it...
Canvas.Draw(x,y, b);

OnDestroy()
b.Free;
--------------
The other way by using resource file is as follows...

Use the LoadBitmap(hInstance, 'MYBITMAP'); To load a bitmap from a resource file...

Cheers,
Viktor
0
 
LVL 1

Author Comment

by:michaelsanders
ID: 1346589
I can't use the loadfromfile since that was what I was doing before...
I could use loadbitmap to load a bitmap from my resource file, but how would I deal with the wave file?
I don't want to put lots of tbitmaps in my object either, since most of them will not be used everytime the program runs this would be to much overkill.

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Accepted Solution

by:
BoRiS earned 100 total points
ID: 1346590
michealsanders

Viktornetr is right again :-) to load the bitmap from resource use

LoadBitmap(hInstance, 'MYBITMAP');

To play a wav file from the resource use

PlaySound('NameOf WavFileHere', Hinstance, SND_RESOURCE or SND_SYNC);
The name is from the name you gave it in the .res file

Remember to add mmsystem to your uses clause...
uses
Windows, Forms,..., mmSystem;
And the .res file is added to your app that contains the wavs...
{&R yourres.res}

Later
BoRiS

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1346591
Well, that's what I said but no one listens to me...
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1346592
viktornet

Now now :-)

Later
BoRiS
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1346593
:)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question