Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get delphi TPaintBox handle

im working on an application using delphi 6, where im trying to integrate camera into the existing application, the camera code displays the captured frames onto a Tpanel, in my application i need to display the captured frame on Tpaintbox ( i am not the original coder),

this is a code sample from the

  procedure TFrameThreadX.DrawFrame;
    var
    hdc:THandle; 
     begin
       
       //do processing
      .
      . 
       hdc := GetDC( ViewForm.ViewPanel.Handle );
       SetStretchBltMode(hdc,COLORONCOLOR);
       StretchDIBits(hdc,0,0,nW,nH,0,0,ScW,ScH,DibPixels,TBitMapInfo((@FDib)^),DIB_RGB_COLORS,SRCCOPY);
       ReleaseDC( ViewForm.ViewPanel.Handle, hdc );


     //do processing
    end;

here is get the Tpanel handle as 87248682 from this

  hdc := GetDC( ViewForm.ViewPanel.Handle );

so when i try to use Tpaintbox in the code like this

       hdc := GetDC( ViewForm.PaintBox1.Canvas.Handle);

The result is 0,

so the camera frames are not displayed..

so i tried this

using the GetDC and GetWindowDC but in both the cases the result of the functions is 0 for the handle,

enter image description here

my code

   var
     hdc  : THandle;
     begin
       hdc := GetDC(Panel1.Handle);
       Label1.Caption:=inttostr(hdc);
       hdc := GetDC(Image1.Canvas.Handle);
       Label2.Caption:=inttostr(hdc);
       hdc := GetDC(PaintBox1.Canvas.Handle);
       Label3.Caption:=inttostr(hdc);
     end;

And for GetWindowDC

    var
     hdc  : THandle;
     begin
     hdc := GetWindowDC(Panel1.Handle);
     Label4.Caption:=inttostr(hdc);
     hdc := GetWindowDC(Image1.Canvas.Handle);
     Label5.Caption:=inttostr(hdc);
     hdc := GetWindowDC(PaintBox1.Canvas.Handle);
     Label6.Caption:=inttostr(hdc);
    end;

So please tell me how to get the Tpaint handle?

like image 331
PresleyDias Avatar asked Dec 01 '25 09:12

PresleyDias


2 Answers

Canvas.Handle is the DC handle you're looking for, so HDC := PaintBox1.Canvas.Handle

like image 90
dwrbudr Avatar answered Dec 02 '25 22:12

dwrbudr


TPaintBox and TImage are TGraphicControl descendants and have no handle (they receive handle when they process WMPaint message). TPanel is TWinControl descendant and has a handle.

like image 25
kludg Avatar answered Dec 03 '25 00:12

kludg