Recent

Author Topic: [SOLVED] Strange Window Location Problem?  (Read 10995 times)

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
[SOLVED] Strange Window Location Problem?
« on: January 24, 2013, 08:57:46 am »
Hi to everyone, i had got struck at a very annoying at this place, in my code

Code: [Select]
Procedure Tform1.Formcreate(Sender: Tobject);
var
  i : Integer;
Begin
   i:=(Screen.Width - Self.Width) - Screen.Width;
   Self.Left:=i;
End;

Some portion of window is still displayed, but according to the above code nothing must be displayed.

Do i am wrong on this issue.

I had tested this example in delphi and it works the way it should.
« Last Edit: January 27, 2013, 12:52:38 pm by deepaak99 »
Holiday season is online now. :-)

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Strange Window Location Problem?
« Reply #1 on: January 24, 2013, 09:57:36 am »
Lazarus cannot tell real Width of window. In Delphi the ClientWidth means inner form, and Width outer form. This bug has existed in Lazarus for very long time. Could be solved with few OS dependant IFDEF's... As for you, may have to rely on WinAPI directly.

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: Strange Window Location Problem?
« Reply #2 on: January 24, 2013, 10:24:48 am »
Lazarus cannot tell real Width of window. In Delphi the ClientWidth means inner form, and Width outer form. This bug has existed in Lazarus for very long time. Could be solved with few OS dependant IFDEF's... As for you, may have to rely on WinAPI directly.

Can you please guide what sort of win api i have to look for.

Is this bug is reported in bug list.
Holiday season is online now. :-)

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Strange Window Location Problem?
« Reply #3 on: January 24, 2013, 11:21:46 am »
Please report the bug.

This should solve your problem:
Code: [Select]
i := - Width - 100; 
« Last Edit: January 24, 2013, 11:26:21 am by typo »

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: Strange Window Location Problem?
« Reply #4 on: January 24, 2013, 12:43:54 pm »
Please report the bug.

This should solve your problem:
Code: [Select]
i := - Width - 100; 


This will not solve my problem, as i am creating a sliding window, as to show the problem i had created this sample, that will show visible bug.
Holiday season is online now. :-)

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: Strange Window Location Problem?
« Reply #5 on: January 24, 2013, 01:40:50 pm »
I am going to report this bug, please guide is this the correct location

Project - LAZARUS
Category - LCL
Reproducibility - always
Holiday season is online now. :-)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Strange Window Location Problem?
« Reply #6 on: January 24, 2013, 02:30:39 pm »
Sounds good.

Don't forget to mention your operating system and preferably attach a sample project that demonstrates the problem.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Bart

  • Hero Member
  • *****
  • Posts: 5757
    • Bart en Mariska's Webstek
Re: Strange Window Location Problem?
« Reply #7 on: January 24, 2013, 03:01:35 pm »
Code: [Select]
Procedure Tform1.Formcreate(Sender: Tobject);
var
  i : Integer;
Begin
   i:=(Screen.Width - Self.Width) - Screen.Width;
   Self.Left:=i;
End;

Which is the same as:
Code: [Select]
  Left := - Width;

Some portion of window is still displayed, but according to the above code nothing must be displayed.

Currenlty Widht returns ClientWidth: read the FAQ

So, no need to post it in bugtracker.
Eventually it will be fixed when a reliable cross-platform method is found.

Bart

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: Strange Window Location Problem?
« Reply #8 on: January 24, 2013, 04:05:17 pm »
Code: [Select]
Procedure Tform1.Formcreate(Sender: Tobject);
var
  i : Integer;
Begin
   i:=(Screen.Width - Self.Width) - Screen.Width;
   Self.Left:=i;
End;

Which is the same as:
Code: [Select]
  Left := - Width;

Some portion of window is still displayed, but according to the above code nothing must be displayed.

Currenlty Widht returns ClientWidth: read the FAQ

So, no need to post it in bugtracker.
Eventually it will be fixed when a reliable cross-platform method is found.

Bart

My application uses this in major part so, what should i do know, wait for this bug to get fixed or there is any other workaround to this problem, my program only targets windows x86/x64. Please guide.
Holiday season is online now. :-)

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Strange Window Location Problem?
« Reply #9 on: January 24, 2013, 04:10:34 pm »
Quote
Eventually when there is a reliable way to get the size and position of a window with its frame on all platforms, then it will be changed. To keep compatibility with older LCL forms, a version number and some extra methods will be added.
Couldn't they make it work for those operating systems that do have a reliable way? There could be linux, portable or any other future OS's that will never have that support. Some people may be getting used to refer to Width when they mean ClientWidth, and that is an issue when dealing with Delphi or backwards compatibility later.

Simply put Width and Height properties are broken as they are, and should not be used until fixed. ClientWidth, ClientHeight are the correct ways to get inner form size.

Quote
Without a reliable way, the LCL would move the forms around on the screen or resize them endlessly.
And programming errors make their ways to FAQ too  >:(  Sorry, it sounds just poor excuse.

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Strange Window Location Problem?
« Reply #10 on: January 24, 2013, 04:13:56 pm »
is any other workaround to this problem, my program only targets windows x86/x64. Please guide.
Google search on: winapi get window size

I found something like this (add Windows in uses list):
Code: [Select]
  RECT rcWind;
  GetWindowRect(hWnd, &rcWind);
(not tested)

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Strange Window Location Problem?
« Reply #11 on: January 24, 2013, 05:06:14 pm »
Using User137 suggestion I quickly put this together and it seems to work for Windows.

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var
  rcWind: TRect;
begin
  rcWind.Left:= 0;
  rcWind.Right:= 0;
  rcWind.Top:= 0;
  rcWind.Bottom:= 0;
  GetWindowRect(HANDLE, &rcWind);
  Label1.Caption:= IntToStr(rcWind.Right-rcWind.Left);
end;

Edit: It looks like you only need to initialize rcWind and the values are reset by GetWindowRect.
« Last Edit: January 24, 2013, 05:11:48 pm by Avishai »
Lazarus Trunk / fpc 2.6.2 / Win32

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: Strange Window Location Problem?
« Reply #12 on: January 25, 2013, 04:32:09 am »
Using User137 suggestion I quickly put this together and it seems to work for Windows.

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var
  rcWind: TRect;
begin
  rcWind.Left:= 0;
  rcWind.Right:= 0;
  rcWind.Top:= 0;
  rcWind.Bottom:= 0;
  GetWindowRect(HANDLE, &rcWind);
  Label1.Caption:= IntToStr(rcWind.Right-rcWind.Left);
end;

Edit: It looks like you only need to initialize rcWind and the values are reset by GetWindowRect.

wow you had saved my day, Thanx a lot.  :) :D ;D

But the above code works when the following settings are.

BorderStyle := bsSizeable, bsSizeToolWindow.
                   := bsNone was already working with default settings.
                   := bsDialog, bsToolWindow not worked at all

When the width of Form was 320 - for first case it returns 336 and for last case it returns 326.
Any workaround for this, as i don't need toolwindow but bsDialog is required.
Holiday season is online now. :-)

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: Strange Window Location Problem?
« Reply #13 on: January 26, 2013, 04:28:48 am »
GetWindowRect does not work correctly when the borderstyle is equal to bsDialog

If Borderstyle=bsSizeable and width is 320 then GetWindowRect returns the width as 336.
and when BorderStyle = bsDialog and width is 320 then GetWindowRect returns the width as 326.

I am missing some things,

I had found
Code: [Select]
GetWindowInfo(hWnd: THandle, pwi : TWindowInfo)
function in delphi, is this exists in freepascal,because TWindowInfo sturcture has   

Quote
cxWindowBorders: LongWord; //width of window border frame
cyWindowBorders: LongWord; //height of window border frame.

It may be very usefull. please help.
Holiday season is online now. :-)

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Strange Window Location Problem?
« Reply #14 on: January 26, 2013, 09:51:10 am »
I haven't tried it but I think TWindowInfo will give you the same problem.

This is just a thought:

1. Create the Form with BorderStyle:= bsSizable completely off-screen or Invisible.

2. Store the Size info.

3. Change the BorderStyle:= bsDialog.

4. Move the Form to the location you want based on the stored Size info.
Lazarus Trunk / fpc 2.6.2 / Win32

 

TinyPortal © 2005-2018