[Lazarus] GetWindowSize misleading documentation or bug?
Luca Olivetti
luca at wetron.es
Sat Sep 27 16:01:18 CEST 2014
El 27/09/14 14:32, zeljko ha escrit:
> On 09/27/2014 12:26 PM, Luca Olivetti wrote:
>> El 27/09/14 12:23, Luca Olivetti ha escrit:
>>> El 27/09/14 12:09, Luca Olivetti ha escrit:
>>>>
>>>> I'm puzzled: with a test program I see no difference in the size in
>>>> both
>>>> cases (right after showing the form and after pressing the button)
>>>> *and*
>>>> the size is the right one (in FormShow is always 1,1 btw).
>>>> I must be doing something else wrong (though the tiling is the correct
>>>> on under windows, mmmh..).
>>>
>>> Found it, nothing wrong on my part: the test program used an auto
>>> created form, the real application creates the form at run time *and*
>>> right after creating the form, after the show GetWindowRect only returns
>>> the client size. I have to introduce a delay for it to return the whole
>>> window's size (and even then, from time to time, it only returns the
>>> client size), so you were correct and this is insane.
>>
>> And, for the record, with qt it's the same (only it seems the delay have
>> to be bigger).
>
> Under X11 nobody knows exact window size (except client size setted up
> by LCL or widgetset) until window is decorated by wm (read mapped -
> shown on screen). See
> http://qt-project.org/doc/qt-4.8/application-windows.html#x11-peculiarities
Yes, I understand, the "insanity" I referred to was about the underlying
environment, not Lazarus.
Anyway, I tried with this snipped of code to measure the decoration
procedure TForm1.Button1Click(Sender: TObject);
var f:TForm;
i:integer;
wr: TRect;
h: Integer;
w: Integer;
begin
f:=TForm.Create(nil);
f.top:=10000;
f.left:=10000;
f.width:=100;
f.height:=100;
f.show;
i:=0;
while true do
begin
Application.ProcessMessages;
GetWindowRect(f.Handle,wr);
h:=wr.bottom-wr.top;
w:=wr.Right-wr.left;
if (w<>f.width) and (h<>f.height) then
break;
i:=i+1;
if i>1000 then
break;
end;
Label1.Caption:=format('%d w:%d h:%d',[i,w-f.width,h-f.height]);
f.free;
end;
The f.top and f.left assignment was a (futile) attempt to avoid flashing
the form on screen.
With gtk2 2 I consistently get the result at the first iteration (i=0),
while with qt it takes at least 2 cycles, on occasions i counted up to 20.
Just FYI.
Bye
--
Luca Olivetti
Wetron Automation Technology http://www.wetron.es
Tel. +34 935883004 Fax +34 935883007
More information about the Lazarus
mailing list