Solved

how to use a resource file

Posted on 1998-11-11
7
171 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

912 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now