I was trying to get this code running:
procedure TPainter.Paint;
var
bmpDisplay, bmpOutput: TBitmap;
ScreenDC: HDC;
begin
bmpDisplay := TBitmap.Create;
bmpOutput := TBitmap.Create;
try
bmpOutput.Width := 500;
bmpOutput.Height := 500;
bmpOutput.Canvas.Rectangle(Form2.RectX, Form2.RectY, 100, 100);
Canvas.Draw(0, 0, bmpOutput);
finally
bmpDisplay.Free;
bmpOutput.Free;
end;
inherited Paint;
end;
Where TPainter is a TCustomControl descendent created on a form.
So I added this function (read the comments on it to understand what I was thinking when I wrote it):
{------------------------------------------------------------------------------ Function: TQtDeviceContext.setImage
Params: None
Returns: Nothing
This function will destroy the previous DC handle and generate a new one based on an image. This is necessary because when painting is being done to a TBitmap, LCL will create a completely abstract DC, using GetDC(0), and latter use SelectObject to associate that DC with the Image.
------------------------------------------------------------------------------} procedure TQtDeviceContext.setImage(AImage: TQtImage); begin
vImage := AImage.Handle;
QPainter_destroy(Widget);
Widget := QPainter_Create(vImage);
end;
Maybe this function is the cause?
More debugging and thinking is necessary ...
Is there any regression on the functionality? Your app seams to work here ... and without a console I don't see error messages.
What you think about going yet one step further and use
DebugLn('msg',[vars]); as standard syntax for logging?
If it produces the same hex output for handles sure, but we need someone to go througth all the code and change this ...
Felipe Monteiro de Carvalho