Page 1 of 2

Open new window with same height and Y position as another

Posted: Sun Aug 28, 2016 7:17 am
by Dude
Check this out... all I want to do is open a second window at the same screen position and vertical size as the first. The only difference is the #PB_Window_SizeGadget flag, which the second window purposely doesn't have. How can I make both windows be the exact same screen position and vertical size, then?

If I remove #PB_Window_SizeGadget from the first window, then yes, it works; but I need that size flag there. :shock:

Image

Code: Select all

y=200 ; Both windows should open at this vertical position!

OpenWindow(0,200,y,200,100,"Lower",#PB_Window_SystemMenu|#PB_Window_SizeGadget)
OpenWindow(1,300,y,WindowWidth(0),WindowHeight(0),"Higher - why?",#PB_Window_SystemMenu)

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
[Edited] To clarify that I don't want the second window to be centered inside the first. Just X/Y position and height must be the same, not the width.

Re: Open new window with same size and position as another

Posted: Sun Aug 28, 2016 9:04 am
by bbanelli
I don't know technical answer to your question, but maybe you can use this as a workaround?

Code: Select all

y=200 ; Both windows should open at this vertical position!

OpenWindow(0,200,y,200,100,"Lower",#PB_Window_SystemMenu|#PB_Window_SizeGadget)
OpenWindow(1,300,y,WindowWidth(0),WindowHeight(0),"Higher - why?",#PB_Window_SystemMenu|#PB_Window_WindowCentered,WindowID(0))

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

Re: Open new window with same size and position as another

Posted: Sun Aug 28, 2016 9:47 am
by Dude
Hi, yes #PB_Window_WindowCentered works for this example, but sometimes the first window will be wider than the second, and I really need the second to be the same X/Y position, and height only, as the first (like in my code).

In the example image I posted, I really want the second window to be the same Y position as the first, even if X is different. I didn't clearly explain that in my first post, sorry (I've now edited it).

I think this is a bug with the resize flag or something, because it should work as coded in my first post.

Re: Open new window with same height and Y position as anoth

Posted: Sun Aug 28, 2016 9:56 am
by Bisonte
Interesting. On Windows 10 the window is not higher... The window have another height .... (PB5.43LTS)

Image

Re: Open new window with same height and Y position as anoth

Posted: Sun Aug 28, 2016 10:26 am
by RASHAD
With window(0) you are using #PB_Window_SizeGadget it means different theme
Try

Code: Select all

y=200 ; Both windows should open at this vertical position!

OpenWindow(0,200,y,200,100,"Lower",#PB_Window_SystemMenu|#PB_Window_SizeGadget)
OpenWindow(1,300,WindowY(0,#PB_Window_FrameCoordinate),WindowWidth(0),WindowHeight(0),"Higher - why?",#PB_Window_SystemMenu)

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

Re: Open new window with same height and Y position as anoth

Posted: Sun Aug 28, 2016 10:52 am
by DontTalkToMe
@Dude

Using /subsystem:windows,6.0 work as expected with and without #PB_Window_SizeGadget

Re: Open new window with same height and Y position as anoth

Posted: Sun Aug 28, 2016 11:17 am
by Dude
Rashad: Your #PB_Window_FrameCoordinate example didn't make any difference; the second window was still slighter higher than the first.

DontTalkToMe: I really don't want to change the default PureBasic settings for this. There must be an easier way to make this work. Anyway, I entered "windows,6.0" in Compiler Options as a test, and it didn't work (it said: "The following subsystem cannot be found: windows").

At the end of the day, shouldn't something as simple as setting WindowHeight(win) match the height of "win"...?

Re: Open new window with same height and Y position as anoth

Posted: Sun Aug 28, 2016 11:25 am
by DontTalkToMe
Dude wrote: Anyway, I entered "windows,6.0" in Compiler Options as a test, and it didn't work (it said: "The following subsystem cannot be found: windows").
it's not THAT subsystem :wink:

http://www.purebasic.fr/english/viewtop ... =3&t=61679

instructions on how to use it

http://purebasic.fr/english/viewtopic.p ... 88#p461188

all the problems mentioned in these different threads, and yours mentioned here, will probably never go away without that linker option. fred added a workaround (instead of the linker option) but later on removed it because was causing other problems
http://purebasic.fr/english/viewtopic.p ... 74#p468874

what surprises me if it has taken so long for someone to report it and for someone to report the fix, the problem must be here from years ago

Re: Open new window with same height and Y position as anoth

Posted: Sun Aug 28, 2016 11:45 am
by Dude
Tried the linker options fix, and it works for Y position and height (woohoo!) but now the X position of the second window is off by 5 pixels to the right. :(

Why is this so freaking hard? Why can't WindowX(new) match WindowX(old), and WindowHeight(new) match WindowHeight(old)? Seems so basic to get right... what's going on? Why do we need linker options and all this other crap?

Re: Open new window with same height and Y position as anoth

Posted: Sun Aug 28, 2016 11:48 am
by TI-994A
Dude wrote:...only difference is the #PB_Window_SizeGadget flag...
This is a Windows issue, by design. The #WS_SIZEBOX property is synonymous with #WS_THICKFRAME; and thus the offset.

Pure-API windows yield exactly the same results:

Code: Select all

Procedure WndProc(hWnd, uMsg, wParam, lParam)
  Select uMsg
    Case #WM_CLOSE
      DestroyWindow_(hWnd)
    Case #WM_DESTROY
      PostQuitMessage_(0)
    Default
      result = DefWindowProc_(hWnd, uMsg, wParam, lParam)
  EndSelect
  ProcedureReturn result
EndProcedure

wndClass$ = "API Window"
wndClass.WNDCLASSEX
With wndClass
  \lpfnWndProc = @WndProc()
  \lpszClassName = @wndClass$
  \cbSize = SizeOf(WNDCLASSEX)
EndWith
RegisterClassEx_(@wndClass)

client.RECT
With client
  \top = 0
  \left = 0
  \right = 200
  \bottom = 100
  AdjustWindowRect_(@client, #WS_CAPTION | #WS_SYSMENU | #WS_SIZEBOX, 0);
  hWnd  = CreateWindowEx_(0, wndClass$, "Resizable Win",  
                          #WS_VISIBLE | #WS_SYSMENU | #WS_SIZEBOX,
                          200, 400, \right - \left, \bottom - \top, 0, 0, 0, 0)
  \top = 0
  \left = 0
  \right = 200
  \bottom = 100
  AdjustWindowRect_(@client, #WS_CAPTION | #WS_SYSMENU, 0);
  hWnd2 = CreateWindowEx_(0, wndClass$, "Regular Win",  
                          #WS_VISIBLE | #WS_SYSMENU,
                          300, 400, \right - \left, \bottom - \top, 0, 0, 0, 0)
EndWith

While GetMessage_(uMsg.MSG, 0, 0, 0)
  TranslateMessage_(uMsg)
  DispatchMessage_(uMsg)
Wend
Bug or not, it's not a PureBasic issue. :wink:

Re: Open new window with same height and Y position as anoth

Posted: Sun Aug 28, 2016 11:59 am
by Dude
So... is the value of #WS_THICKFRAME somewhere to be evaluated at runtime, so I can just add that to the window's Y position? GetSystemMetrics_() or something?

Re: Open new window with same height and Y position as anoth

Posted: Sun Aug 28, 2016 12:17 pm
by TI-994A
Dude wrote:...is the value of #WS_THICKFRAME somewhere to be evaluated at runtime...
Not that I'm aware of. However, although the difference could simply be calculated, it's not bulletproof, as the results differ on different versions of Windows. The results of your original post are consistent with Windows 8.1, but not with Windows 10; on 10, the y-position is correct, while the height differs.

Nevertheless, the difference could be calculated like so:

Code: Select all

Procedure metricsDifference(width, height)
  client.RECT
  With client
    \top = 0
    \left = 0
    \right = width
    \bottom = height
    AdjustWindowRect_(@client, #WS_CAPTION | #WS_SYSMENU | #WS_SIZEBOX, 0);
    bottom = \bottom
    \top = 0
    \left = 0
    \right = width
    \bottom = height
    AdjustWindowRect_(@client, #WS_CAPTION | #WS_SYSMENU, 0);
    yDifference = bottom - \bottom
  EndWith
  ProcedureReturn yDifference
EndProcedure

y = 200
yOffset = metricsDifference(200, 100)
OpenWindow(0, 200, y, 200, 100, "Same!", #PB_Window_SystemMenu | #PB_Window_SizeGadget)
OpenWindow(1, 300, y + yOffset, WindowWidth(0), WindowHeight(0), "Same!", #PB_Window_SystemMenu)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
On Windows 10, the difference could be offset from the window height.

But, like I said, not bulletproof. :wink:

Re: Open new window with same height and Y position as anoth

Posted: Sun Aug 28, 2016 1:10 pm
by Dude
Hi TI-994A, your solution is perfect for a small fonts (DPI) Windows system, and I can even shorten it to the following; but both yours and my shortened version fail on a large fonts Windows system. Oh well. Most users have small fonts by default, so I can live with that. :lol:

Code: Select all

y=200 ; Both windows should open at this vertical position!

noresize=GetSystemMetrics_(#SM_CYSIZEFRAME)-GetSystemMetrics_(#SM_CYFIXEDFRAME)

OpenWindow(0,200,y,200,100,"Original",#PB_Window_SystemMenu|#PB_Window_SizeGadget)
OpenWindow(1,300,y+noresize,WindowWidth(0),WindowHeight(0),"Same Y pos!",#PB_Window_SystemMenu)

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

Re: Open new window with same height and Y position as anoth

Posted: Sun Aug 28, 2016 1:50 pm
by DontTalkToMe
Dude wrote:Tried the linker options fix, and it works for Y position and height (woohoo!) but now the X position of the second window is off by 5 pixels to the right. :(
It's the other way around. Now it is at the right place. Previously without the linker option was n pixels off to the left.

Anyway PB does something wrong when the #PB_Window_SizeGadget is applied, even the linker option seems not enough to make all work correctly.

The second window is now positioned at x=300 but the first one is not at x=200 using PB openwindow with the linker option.

If you use a full API only program, with the linker option which microsoft compilers specify when targeting newer OSes, the windows are positioned correctly. So using API and the flags as prescribed by MS (as idiotic as it may be) all seems to work, at least on windows 7 where I tested this, don't know if MS has furtherly botched this in newer OSes.

Re: Open new window with same height and Y position as anoth

Posted: Sun Aug 28, 2016 2:07 pm
by RASHAD
I hate to switch between windows versions
Simple solution
Tested with windows 7 x86

Code: Select all

y=200 ; Both windows should open at this vertical position!

OpenWindow(0,200,y,200,100,"Lower",#PB_Window_SystemMenu)
OpenWindow(1,300,y,WindowWidth(0),WindowHeight(0),"Higher - why?",#PB_Window_SystemMenu)
SetWindowLongPtr_(WindowID(0),#GWL_STYLE,GetWindowLongPtr_(WindowID(0),#GWL_STYLE)|#WS_THICKFRAME)

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow