[Lazarus] GetWindowSize misleading documentation or bug?

Giuliano Colla giuliano.colla at fastwebnet.it
Sat Sep 27 00:05:21 CEST 2014

Il 26/09/2014 22:47, Luca Olivetti ha scritto:
> El 26/09/14 22:45, Luca Olivetti ha escrit:
>> Strange, on mageia 4, kde, lazarus 1.2.4 it doesn't work. What I'm
>> trying to do is to tile windows one next to the other. Using
>> GetWindowRect under windows I can do it properly, while on linux gtk the
>> windows overlap (i.e. with this layout
>>       A  B  C
>>       D  E
>> A overlaps D and B overlaps E, the amount of overlap seems to be equal
>> to the height of the title bar).
> Oh, and there's also a slight overlap between A-B, B-C and D-E

Something which could affect your results is the timing. The window 
manager takes a time to add the decorations. Different window managers 
take different time. It's meant for human observers, which don't 
perceive a delay of some tens of milliseconds. Therefore it's given a 
low priority (and the mechanism is quite different from Windows to 
Linux). If you ask the size too early, you get a size which has not yet 
been adjusted.

You may verify if the function works properly by adding somewhere in 
your form a button and a label, and with the onClick of the button write 
in the label caption both the result of GetWindowSize and of 
GetWindowRect. You can't possibly push the button faster than the time 
it takes the window manager to decorate your window!

If you get the expected result, (i.e. size of client area and size with 
decorations) then you know that the problem is just of timing.
If you add a delay of let's say 50ms from window paint, or window show 
to getting its size and positioning the next window, you should be out 
of trouble. A total delay of 200ms should be unnoticeable and harmless, 
even if maybe useless in Windows.

>> So in theory GetWindowRect is the "right" function while GetWindowSize
>> is redundant (since there's already width and height)?

That's at least what I gather by comparing documentation with actual 


Giuliano Colla

Project planning question: when it's 90% done, are we halfway or not yet?

More information about the Lazarus mailing list