[Lazarus] Getting update rect/region in Windows

Max Vlasov max.vlasov at gmail.com
Sun May 22 16:16:53 CEST 2011


2011/5/22 Zaher Dirkey <parmaja at gmail.com>

> 2011/5/22 Max Vlasov <max.vlasov at gmail.com>
>
>>
>>
>> 2011/5/22 Zaher Dirkey <parmaja at gmail.com>
>>
>>>
>>> 2011/5/22 Max Vlasov <max.vlasov at gmail.com>
>>>
>>>> Hi,
>>>> I encountered a problem I don't know how to solve.
>>>>
>>>> In Delphi I used the following trick. In the WM_Paint before inheried
>>>> call I got update region with successive calls to GetUpdateRect (to
>>>> determine if it exists) and GetUpdateRgn afterwards. This allowed to get the
>>>> correct region before BeginPaint is called (it validates the region so
>>>> getting it after BeginPaint makes no sense).
>>>>
>>>> But in Lazarus WM_Paint handler already contains DC and also
>>>> GetUpdateRect call is failed. As I understand, this is because the
>>>> WindowProc from win32callback.inc already did BeginPaint and provided the dc
>>>> for the following call to the control WM_Paint.
>>>>
>>>>
>>>> Max Vlasov
>>>>
>>>>
>>> Check Canvas.ClipRect
>>>
>>>
>>>
>>
>> Zaher, thanks,
>> but this is irrelevant, clipping rects and regions is just  the way to
>> define canvas/device context limiting area until explicitly canceled. It was
>> used by Delphi and (probably) Lazarus to implement TGraphicControl,
>> component working almost as TWinControl but without window handles.
>> ...
>> Max
>>
>>
> Not understand u, can u give us an example
> Thanks
> --
>


Ok,
simple form, one button. The following code works in Delphi (press button,
redrawing with Alt-Tab or by dragging some other window over this window).
In Lazarus it always goes to 'failed'.
My version: with Delphi vcl logic BeginPaint will be inside inherited, with
Lazarus it already was before in the non-object WindowProc

Max
...

procedure TForm1.Button1Click(Sender: TObject);
begin
  { change Bounds to @ARect in Delphi since it's declared as PRect }
  InvalidateRect(Handle, Bounds(0, 0, 100, 100), true);
end;

...
  private
    procedure  WmPaint(var Msg: TWmPaint);message WM_Paint;


procedure TForm1.WmPaint(var Msg: TWmPaint);
var
  ARect: TRect;
begin
  if GetUpdateRect(Handle, ARect, false) then
  begin
    Caption:=format('Update Rect is ok (%d, %d, %d, %d)', [ARect.Left,
ARect.Top, ARect.Right, ARect.Bottom]);
  end
  else
    Caption:='Update Rect is failed';

  inherited;
end;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110522/436b31aa/attachment-0003.html>


More information about the Lazarus mailing list