Board index » cppbuilder » (basic window graphics) How to display a graphic with a component

(basic window graphics) How to display a graphic with a component

I've got a library of graphic function calls, such as load_file() and
display_image().  However, I don't know anything about the calls I need
to make to Windows in terms of message handling and device contexts.
Could someone please describe what I need to do in a component in order
to load an image from a file and display it onscreen in a window?  

Thank you.

TJ

 

Re:(basic window graphics) How to display a graphic with a component


Hi TJ --

Quote
> I've got a library of graphic function calls, such as load_file() and
> display_image().  However, I don't know anything about the calls I need
> to make to Windows in terms of message handling and device contexts.
> Could someone please describe what I need to do in a component in order
> to load an image from a file and display it onscreen in a window?

If you library is designed to work with the GDI, chances are, the load_file()
function returns a handle to a bitmap or DIBSection (HBITMAP) or DIB (HANDLE),
and/or the display_image() function accepts the handle to a device context
(HDC).  If the load_file() function returns an HBITMAP, you can simply drop a
create a TBitmap object, then assign the returned HBITMAP to the Handle property
of your TBitmap instance.  You can alternatively Assign() this Bitmap to the
Picture property of a TImage (which you drop on your Form at design-time), or
use the OnPaint event of your Form and it's Canvas property to Draw() the
bitmap...

void __fastcall TForm1::FormPaint(TObject *Sender)
{
   Canvas->Draw(0, 0, MyBitmap);  

Quote
}

To use your display_image() function, assuming it accepts a handle to a device
context, you can use the OnPaint event again....

void __fastcall TForm1::FormPaint(TObject *Sender)
{
   // Handle property of TCanvas returns an HDC
   display_image(Canvas->Handle);  

Quote
}

Or, drop a TImage on your Form at design-time and display_image() to this TImage
once...

display_image(Image1->Canvas->Handle);

TImage components are self-refreshing.

Good luck!

--
Damon Chandler (TeamB)
http://bcbcaq.freeservers.com

Other Threads