Board index » cppbuilder » Loading a bmp from a .res file, into an ImageList, from within a package

Loading a bmp from a .res file, into an ImageList, from within a package

Hi.

I posted something of the sort earlier, but i couldnt get my question
through.

I'm making a component that uses a few bmps. Instead of hardcoding paths to
these bmps, im including them in a .res file, using the Image editor. Now,
basically, my component has an ImageList. I want to load the bmps from the
defuault res file (MyPackage.res) into this imagelist. I took a look at the
help for TCustomImageList and found 3 functions i could use to load a bmp
from resource file. 2 were said to be used outside a package (beacuse im
making a component), which is not the case for me. I saw that the function i
needed to use is :

            ResInstLoad(int Instance, TResType ResType, System::AnsiString
Name, Graphics::TColor MaskColor);

(... Remember this is from within a new component). I filled out everything
except Instance. I tried passing HInstance but got a compilation error. All
i want to do is load a bmp from a res file, for my compoment... Am i doing
something wrong? Is this the correct routine? If someone could enlighten me
(possibly with some code) i would really appreciate it.

Thanks

 

Re:Loading a bmp from a .res file, into an ImageList, from within a package


Quote
: "Pave" <p...@hotmail.com> wrote:
>I posted something of the sort earlier, but i couldnt get my question
>through.

You did post and it did make it through. You even replied. Pave, it is
advisable to stay in a thread.

Quote
>(... Remember this is from within a new component). I filled out everything
>except Instance. I tried passing HInstance but got a compilation error.

Please *always*, religiously *always*, give the complete exact text of the
error message.

Quote
>Am i doing something wrong?

You don't show us what you do, hence it is impossible what causes this
compilation error that you don't really tell us about and how to fix this.

--
General information:
  * Post to the right group - http://www.borland.com/newsgroups/
    * Do not cross- or multipost
      * Research at http://www.mers.com/searchsite.html

Stefan Hoffmeister - http://www.econos.de/
TeamB - http://www.teamb.com/

Re:Loading a bmp from a .res file, into an ImageList, from within a package


Quote
> You did post and it did make it through. You even replied. Pave, it is
> advisable to stay in a thread.

When i said "didnt make it through" i didnt mean as it didnt make it to the
server, rather i couldnt rephrase my question good enough to show people
what i meant..

Quote
> Please *always*, religiously *always*, give the complete exact text of the
> error message.

OK. All i have is a derived component (derived from TStatusBar). This has an
ImageList and a .res file. In the constructor i write (amongst other things)
:

__fastcall TRemoteBar::TRemoteBar(TComponent* Owner)
    : TStatusBar(Owner)
{
    m_PicIndex = 0;
    m_Status = NULL;
    OnDrawPanel = DoDrawPanel;
    m_STK_Status = new TStatusStock(hInstance); <----- here i pass hInstance
to my custom object.

Quote
}

and the constructor for TStatusStock is :

__fastcall TStatusStock::TStatusStock(HINSTANCE hInstance)
{
    m_hInstance = hInstance;

    /* start creating IDs */

    // -- IDLE --
    TRemoteStatus *rs_idle = new TRemoteStatus("ST_IDLE_IDLE", ST_IDLE,
"Idle", amNone);
    if (rs_idle->Images->GetInstRes(m_hInstance, rtBitmap,"ST_IDLE_IDLE" ,
16, TLoadResources() << lrDefaultColor, (TColor)RGB(255,255,255)))
        ShowMessage("loaded");
    else
        ShowMessage("error"); <- for debugging only

    AddToStock(rs_idle);

Quote
}

And i get the errors :

[C++ Error] RemoteBar.cpp(35): E2034 Cannot convert 'void *' to 'unsigned
int'.
[C++ Error] RemoteBar.cpp(35): E2343 Type mismatch in parameter 'Instance'
in call to '_fastcall TCustomImageList::GetInstRes(unsigned
int,TResType,AnsiString,int,TLoadResources,TColor)'.

If i just go ahead and cast the m_hInstance to (int) the project compiles,
but once i put my custom statusbar on a form it pops the "error"
showmessage - the resource wasnt loaded...

If i need to post anything else, please tell me.

Thanks

Re:Loading a bmp from a .res file, into an ImageList, from within a package


Quote
: "Pave" <p...@hotmail.com> wrote:
>__fastcall TStatusStock::TStatusStock(HINSTANCE hInstance)
>{
>    m_hInstance = hInstance;

>    if (rs_idle->Images->GetInstRes(m_hInstance, rtBitmap,"ST_IDLE_IDLE" ,
>[C++ Error] RemoteBar.cpp(35): E2034 Cannot convert 'void *' to 'unsigned
>int'.
>[C++ Error] RemoteBar.cpp(35): E2343 Type mismatch in parameter 'Instance'
>in call to '_fastcall TCustomImageList::GetInstRes(unsigned
>int,TResType,AnsiString,int,TLoadResources,TColor)'.

>If i just go ahead and cast the m_hInstance to (int) the project compiles,

This is the correct approach.

Quote
>but once i put my custom statusbar on a form it pops the "error"
>showmessage - the resource wasnt loaded...

Is a resource named "ST_IDLE_IDLE" present in the file where

  TStatusStock::TStatusStock

lives? I.e. if TStatusStock::TStatusStock is located in a runtime package,
is "ST_IDLE_IDLE" located in the runtime package; if
TStatusStock::TStatusStock is linked into the EXE, is "ST_IDLE_IDLE"
located in the EXE?

--
General information:
  * Post to the right group - http://www.borland.com/newsgroups/
    * Do not cross- or multipost
      * Research at http://www.mers.com/searchsite.html

Stefan Hoffmeister - http://www.econos.de/
TeamB - http://www.teamb.com/

Re:Loading a bmp from a .res file, into an ImageList, from within a package


Quote
> Is a resource named "ST_IDLE_IDLE" present in the file where

>   TStatusStock::TStatusStock

> lives? I.e. if TStatusStock::TStatusStock is located in a runtime package,
> is "ST_IDLE_IDLE" located in the runtime package; if
> TStatusStock::TStatusStock is linked into the EXE, is "ST_IDLE_IDLE"
> located in the EXE?

In my package .cpp file i have the : #pragma resource "RemoteBarPack.res"
and in the directory of the .bpk i have the RemoveBarPack.res file. I
openned it with Image Editor and confirmed that i made the bitmap there (add
bitmap and rename to "ST_IDLE_IDLE").

.... Then i recompiled the package and the bitmap was gone! Does the project
autocreate a res file every compilation ?

I recreate the bmp (after the installation) and throw my component, and i
still get the "error" showmessage - resource hasnt been loaded... What am i
doing wrong ?? Should i post the whole project (its not very big ) ?

Thanks

Re:Loading a bmp from a .res file, into an ImageList, from within a package


Hi.
I tried creating a totally different application (this time not a
component - to make things simple). I opened the Project1.res file with
Image Editor created a new Bitmap named "BITMAP1". Openned the res file
again to make sure it was saved. OK. Now, i threw a TImage and a TButton. I
gave the TButton onclick the following line

    Image1->Picture->Bitmap->LoadFromResourceName((int)HInstance,
"BITMAP1");

and i wrote : #pragma resource "Project1.res" right below the *.dfm line. i
ran and clicked and got an EResNotFound exception - Resource Bitmap1 not
found.. I then openned my .res file and saw that the bitmap was still there
and named Bitmap1... So what am i doing wrong? Am i supposed to compile the
res file or link it with RLINK32 or something ?

Re:Loading a bmp from a .res file, into an ImageList, from within a package


Quote
: "Pave" <p...@hotmail.com> wrote:
>In my package .cpp file i have the : #pragma resource "RemoteBarPack.res"

What is the name of your package?

Quote
>Does the project autocreate a res file every compilation ?

Yes, possibly. Always use a different name for the RES file than the
project's (package's) file name

Quote
>I recreate the bmp (after the installation) and throw my component,

I do not understand what you are saying, sorry.

Quote
>Should i post the whole project

No, please do NOT do this.

--
General information:
  * Post to the right group - http://www.borland.com/newsgroups/
    * Do not cross- or multipost
      * Research at http://www.mers.com/searchsite.html

Stefan Hoffmeister - http://www.econos.de/
TeamB - http://www.teamb.com/

Re:Loading a bmp from a .res file, into an ImageList, from within a package


Quote

> >Should i post the whole project

> No, please do NOT do this.

:). Something ill remember in future posts.

Anyways, when i say "throw the component" i mean put it on the form. I dont
know what had changed, but the GetInstRes function now returns "true". God
knows if it really loaded the bmps. I have put this part aside and i will
probably post followups in a few days or so. As always, thanks for the help
Stefen.

Other Threads