Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problems with Handles in Delphi

285 views
Skip to first unread message

Ray Cramer

unread,
Nov 28, 1995, 3:00:00 AM11/28/95
to
In article b...@pf2.phil.uni-sb.de, cla...@cscip.uni-sb.de (Ulrich Clanget) writes:
>I have a problem with Handles in Delphi. I want to copy images from a
>delphi TImage component into a FORM. I used the API-Function BitBlt :
>
> BitBlt( Form.Handle, 0,0, 100,100,Image1.Picture.BitMap.Handle, 0,0, scrCOPY)
>
> But, there was not result in my FORM at Run-time.
>
> Clanget.

I'm no expert, but I have used Bitblt. I still get confused with the Picture stuff, but my
Image->Image copy used Image1.Picture.BitMap.Canvas.Handle.

Otherwise maybe you could use Form.Canvas.Handle.

Otherwise (!) maybe you must have a TImage on the Form

HTH

Ray Cramer
R...@Pol.ac.uk


Thomas Ridgeway

unread,
Nov 28, 1995, 3:00:00 AM11/28/95
to
cla...@cscip.uni-sb.de (Ulrich Clanget) wrote:
>I have a problem with Handles in Delphi. I want to copy images from a
>delphi TImage component into a FORM. I used the API-Function BitBlt :
> BitBlt( Form.Handle, 0,0, 100,100,Image1.Picture.BitMap.Handle, 0,0, scrCOPY)
> But, there was not result in my FORM at Run-time.

I believe form.handle is a handle to a window; form.canvas.handle is a
handle to a device context, which is most likely what you want.

Tom


Ulrich Clanget

unread,
Nov 28, 1995, 3:00:00 AM11/28/95
to
I have a problem with Handles in Delphi. I want to copy images from a
delphi TImage component into a FORM. I used the API-Function BitBlt :

BitBlt( Form.Handle, 0,0, 100,100,Image1.Picture.BitMap.Handle, 0,0, scrCOPY)

But, there was not result in my FORM at Run-time.

Clanget.

Bill Pantoja

unread,
Nov 29, 1995, 3:00:00 AM11/29/95
to

If the form is an MDI Parent form, you will never see a result.
You need the handle for the MDI Client area to paint on it.

If the form is NOT an MDI parent form then use the Delphi
bitmap functions and use the canvas of the form (search under
Canvas in the help, look for copying bitmaps)

To solve the problem with your code fragment, you need to use
Form1.Canvas.Handle. Form1.Handle is the windows handle to the
form. Form1.Canvas.Handle is a Device Context handle.


Huet Bartels

unread,
Dec 6, 1995, 3:00:00 AM12/6/95
to
Hi Clanget,

You need to use a HDC not a THANDLE included is the help text for
GetDeviceContext and the WinAPI for BitBlt.


GetDeviceContext Method

Unit

Controls

Applies to TControl, TWinControl

Declaration

function GetDeviceContext(var WindowHandle: HWnd): HDC; virtual;

Description

The GetDeviceContext method returns a device context for the
control represented by the window handle passed in the
WindowHandle parameter. TControl implements GetDeviceContext
by returning the device context returned from its parent control's
GetDeviceContext. TWinControl overrides GetDeviceContext to call
the Windows API function GetDC, passing the windowed control's
Handle property and setting WindowHandle to Handle.

Windows API BitBlt

BitBlt (2.x) (WINPROCS unit)

function BitBlt(DestDC: HDC; X, Y, nWidth, Height: Integer; SrcDC: HDC;

XSrc, YSrc: Integer; Rop: LongInt): Bool;

The BitBlt function copies a bitmap from a specified device
context to a destination device context.

So off the top of my head (It may be wrong don't flame me) here is what
I would do to start coding this.

Var
MyDC:HDC;
BitIt:Boolean;
Devcaps:Integer;
Begin
MyDC:=GetDeviceContext(Form1.Handle);
DevCaps:=GetDeviceCaps(MyDC,RASTERCAPS); {Read WINAPI may need
more work?}
BitIt:=BitBlt(MyDC,10,10, 100, 10,DcToCopyFrom,10,10,MERGECOPY)
MyDC.Free;
End;

Not all devices support the BitBlt function. An application can
determine whether a device supports BitBlt by calling the
GetDeviceCaps function and specifying the RASTERCAPS
index.

Hope this helps I have not tested it but it is a start

Huet Bartels


0 new messages