Canvas doesn't allow drawing
Hi !!
I have a fairly complex shaped window that I can move and resize. Its frame is made of
TShapes and TImages, which are resized immediately when the window itself is being
resized. Same goes for the shape of the window, set via SetWindowRgn (COMPLEXREGION).
I have slimmed down all drawing procedures as far as possible, but still get the message
"Canvas doesn't allow drawing" after a few seconds of resizing the window. Disabling
double-buffering increases the timespan until the error occurs, but doesn't solve the problem.
I have found several questions regarding this error, on the net, but no solution. When
using a TImage, I could lock its canvas, but would that work with a window (TMyFrame is a
TCustomPanel descandent) ? If you think so, how can get and lock its canvas ?
Any other solutions are welcome, of course !!
Daniel
---------
Resizing procedures (simplified):
procedure TMyFrame.MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
ReactOnFocus(Sender); // bring window to front
if (not Fixed) and (AResizable) then
begin
OnResize := nil;
DragX := X;
DragY := Y;
AmResizing := true;
end;
end;
procedure TMyFrame.MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
if (AmResizing) then
begin
if (not Evaluating) then
begin
Evaluating := true;
if (Width + X-DragX > 50) then Width := Width + X-DragX else Width := 50;
if (Height + Y-DragY > 50) then Height := Height + Y-DragY else Height := 50;
ResizeAllSubComponents(Self); // This function also uses SetWindowRgn
Parent.Update;
Evaluating := false;
end;
end;
end;
procedure TMyFrame.MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
if (AmResizing) then
begin
if (Width + X-DragX > 50) then Width := Width + X-DragX else Width := 50;
if (Height + Y-DragY > 50) then Height := Height + Y-DragY else Height := 50;
AmResizing := false;
OnResize := ResizeAllSubComponents;
end;
end;