Lazarus

Programming => Operating Systems => Windows => Topic started by: Pascal on August 17, 2017, 06:23:12 am

Title: How to link with "winver = 6.0"
Post by: Pascal on August 17, 2017, 06:23:12 am
How can i link my executable with "winver = 6.0"?
Title: Re: How to link with "winver = 6.0"
Post by: marcov on August 17, 2017, 06:59:56 am
winver afaik is a macro in the (C) windows headers. We don't use the C windows headers.

What are you trying to achieve exactly?
Title: Re: How to link with "winver = 6.0"
Post by: Pascal on August 17, 2017, 08:37:37 am
On Windows 10 TForm.Left, Top, Width, Height have strange values. Top/Left is not 0/0.
See http://forum.lazarus.freepascal.org/index.php/topic,37918.msg256621.html#new (http://forum.lazarus.freepascal.org/index.php/topic,37918.msg256621.html#new)

If i want to position a Window to one or more of the screen edges i need the position and dimensions of the
drawn window without the extended resize aware area around the window.

But if this a macro/define in the c headers this will not help here :D

I think best is to use:

Code: Pascal  [Select][+][-]
  1. uses
  2.   Windows,
  3.   DwmApi;
  4.  
  5. procedure xyz;
  6. var
  7.   frame: Windows.RECT;
  8. begin
  9.   DwmGetWindowAttribute(Handle, DWMWA_EXTENDED_FRAME_BOUNDS, @frame, sizeof(Windows.RECT));
  10.   ...
  11. end;
  12.  
  13. initialization
  14.   InitDwmLibrary;
  15. end.
Title: Re: How to link with "winver = 6.0"
Post by: taazz on August 17, 2017, 08:56:59 am
On Windows 10 TForm.Left, Top, Width, Height have strange values. Top/Left is not 0/0.
See http://forum.lazarus.freepascal.org/index.php/topic,37918.msg256621.html#new (http://forum.lazarus.freepascal.org/index.php/topic,37918.msg256621.html#new)

If i want to position a Window to one or more of the screen edges i need the position and dimensions of the
drawn window without the extended resize aware area around the window.
use clientrect, clientwidth and clientheight instead.
But if this a macro/define in the c headers this will not help here :D

I think best is to use:

Code: Pascal  [Select][+][-]
  1. uses
  2.   Windows,
  3.   DwmApi;
  4.  
  5. procedure xyz;
  6. var
  7.   frame: Windows.RECT;
  8. begin
  9.   DwmGetWindowAttribute(Handle, DWMWA_EXTENDED_FRAME_BOUNDS, @frame, sizeof(Windows.RECT));
  10.   ...
  11. end;
  12.  
  13. initialization
  14.   InitDwmLibrary;
  15. end.
I would use this one instead https://msdn.microsoft.com/en-us/library/windows/desktop/ms633503(v=vs.85).aspx
Title: Re: How to link with "winver = 6.0"
Post by: Pascal on August 17, 2017, 10:26:16 am
I would use this one instead https://msdn.microsoft.com/en-us/library/windows/desktop/ms633503(v=vs.85).aspx
No, that are not the positions and dimensions of the window (without extended resize areas). It's the usable inner space of the window.
Title: Re: How to link with "winver = 6.0"
Post by: taazz on August 17, 2017, 10:40:39 am
I would use this one instead https://msdn.microsoft.com/en-us/library/windows/desktop/ms633503(v=vs.85).aspx (https://msdn.microsoft.com/en-us/library/windows/desktop/ms633503(v=vs.85).aspx)
No, that are not the positions and dimensions of the window (without extended resize areas). It's the usable inner space of the window.
I guess the 0,0 for top left through me off then. I have no idea what the "extended resize areas" are.
Title: Re: How to link with "winver = 6.0"
Post by: Pascal on August 17, 2017, 10:51:12 am
I guess the 0,0 for top left through me off then. I have no idea what the "extended resize areas" are.
On Windows 10 you have an extended area to the left, top and bottom where the cursor changes to the resize cursor and
this size is included in the window position and dimensions (equal to TForm.Left, Top, Width and Height).
Title: Re: How to link with "winver = 6.0"
Post by: taazz on August 17, 2017, 10:53:15 am
I guess the 0,0 for top left through me off then. I have no idea what the "extended resize areas" are.
On Windows 10 you have an extended area to the left, top and bottom where the cursor changes to the resize cursor and
this size is included in the window position and dimensions (equal to TForm.Left, Top, Width and Height).
isn't that called a frame/border in older windows?
Title: Re: How to link with "winver = 6.0"
Post by: Pascal on August 17, 2017, 11:03:02 am
isn't that called a frame/border in older windows?
Yes, but it doesn't look like one. The visible border is 1 pixel but the whole border is 8 pixel.

I am curious how Delphi handles this (Setting window position to 0/0) on Windows 10.
Will there be a visible gap of 7 pixels to left of the window?

Title: Re: How to link with "winver = 6.0"
Post by: taazz on August 17, 2017, 11:10:10 am
isn't that called a frame/border in older windows?
Yes, but it doesn't look like one. The visible border is 1 pixel but the whole border is 8 pixel.

I am curious how Delphi handles this (Setting window position to 0/0) on Windows 10.
Will there be a visible gap of 7 pixels to left of the window?
Sorry I do not have access to windows 10 and I'll probably never will in the near future but that sounds like a windows bug. If my memory serves me correctly in all windows versions from 95 upwards the mouse check for the borders had an error of 1 or 2 pixels on top of the border width to make it more user friendly but that friendliness was never part of the window it self. Are you sure its not an artifact of your current theme? Are you using the default windows theme?
Title: Re: How to link with "winver = 6.0"
Post by: Pascal on August 17, 2017, 12:00:39 pm
It's not a bug it's a feature  :D

https://stackoverflow.com/questions/34139450/getwindowrect-returns-a-size-including-invisible-borders (https://stackoverflow.com/questions/34139450/getwindowrect-returns-a-size-including-invisible-borders)
Title: Re: How to link with "winver = 6.0"
Post by: rvk on August 17, 2017, 12:21:06 pm
I am curious how Delphi handles this (Setting window position to 0/0) on Windows 10.
Will there be a visible gap of 7 pixels to left of the window?
Yes there is.
Title: Re: How to link with "winver = 6.0"
Post by: Pascal on August 17, 2017, 12:25:40 pm
Yes there is.
Thanks!
Title: Re: How to link with "winver = 6.0"
Post by: taazz on August 17, 2017, 12:50:45 pm
I am curious how Delphi handles this (Setting window position to 0/0) on Windows 10.
Will there be a visible gap of 7 pixels to left of the window?
Yes there is.
Good to know! which is the Delphi version used?
Title: Re: How to link with "winver = 6.0"
Post by: rvk on August 17, 2017, 01:08:30 pm
I am curious how Delphi handles this (Setting window position to 0/0) on Windows 10.
Will there be a visible gap of 7 pixels to left of the window?
Yes there is.
Good to know! which is the Delphi version used?
Delphi 10.1 Berlin on Windows 10 Pro 64 bit.

B.T.W. for setting winver=6 you need to set the MajorSubsystemVersion, not the MajorOperatingSystemVersion, in the IMAGE_OPTIONAL_HEADER flags to 6. In Delphi you can do this by adding {$SETPESUBSYSVERSION 6.0}
( for MajorSubsystemVersion it would be {$SETPEOSVERSION 6.0} )

But both have no effect on Windows 10.
(I checked with PEview (http://wjradburn.com/software/) that the PE-flags where really set correctly.)
Title: Re: How to link with "winver = 6.0"
Post by: Pascal on August 17, 2017, 01:32:16 pm
B.T.W. for setting winver=6 you need to set the MajorSubsystemVersion, not the MajorOperatingSystemVersion, in the IMAGE_OPTIONAL_HEADER flags to 6. In Delphi you can do this by adding {$SETPESUBSYSVERSION 6.0}
( for MajorSubsystemVersion it would be {$SETPEOSVERSION 6.0} )

But both have no effect on Windows 10.
(I checked with PEview (http://wjradburn.com/software/) that the PE-flags where really set correctly.)
This may only affect other things: https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/6c1c67a9-5548-4e9b-989f-c7dbac0b1375/getwindowrect-on-nonresizable-windows-under-aero-glass?forum=windowsuidevelopment (https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/6c1c67a9-5548-4e9b-989f-c7dbac0b1375/getwindowrect-on-nonresizable-windows-under-aero-glass?forum=windowsuidevelopment)
Title: Re: How to link with "winver = 6.0"
Post by: rvk on August 17, 2017, 01:37:05 pm
So you can do something like this (like you mentioned) but it's far from optimal.

Code: Pascal  [Select][+][-]
  1. uses Windows, dwmapi;
  2.  
  3. function GetRealWindowRect(Handle: HWND; var R: TRect): Boolean;
  4. begin
  5.   Result := (GetParent(Handle) = 0) and DwmCompositionEnabled and
  6.     (DwmGetWindowAttribute(Handle, DWMWA_EXTENDED_FRAME_BOUNDS, @R, SizeOf(R)) = S_OK);
  7.   if not Result then
  8.     Result := GetWindowRect(Handle, R);
  9. end;
  10.  
  11. function GetInvisibleBorder(Handle: Hwnd): Integer;
  12. var
  13.   R1, R2: TRect;
  14. begin
  15.   Result := 0;
  16.   if GetRealWindowRect(Handle, R1) and GetWindowRect(Handle, R2) then
  17.   begin
  18.     Result := R1.Left - R2.Left;
  19.   end;
  20. end;
  21.  
  22. procedure TForm1.FormCreate(Sender: TObject);
  23. begin
  24.   InitDwmLibrary;
  25.   Top := 0;
  26.   Left := 0;
  27. end;
  28.  
  29. procedure TForm1.FormActivate(Sender: TObject);
  30. begin
  31.   Left := 0 - GetInvisibleBorder(Handle); // only possible after window is visible
  32. end;
TinyPortal © 2005-2018