Page 1 of 3

OpenWindow

Posted: Thu Jan 04, 2018 12:05 am
by GenRabbit
When using the OpenWindow command the width and height is for the client area. But is there away to get a Windows Frame thickness before opening the window?

Like if I wish to open a Window with the height and with of 1920x1080, how do I get the Windows border thickness?

Re: OpenWindow

Posted: Thu Jan 04, 2018 1:24 am
by Mijikai
Before only with API (example):

Code: Select all

GetSystemMetrics_(#SM_CXSIZEFRAME)
Or u could do something like this and just hide the Window before showing it:

Code: Select all

If OpenWindow(0,0,0,100,120,"TestWindow",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)
  BorderWidth.i = (WindowWidth(0,#PB_Window_FrameCoordinate) - WindowWidth(0,#PB_Window_InnerCoordinate)) / 2
  BorderHeightTop.i = WindowHeight(0,#PB_Window_FrameCoordinate) - WindowHeight(0,#PB_Window_InnerCoordinate) - BorderWidth
  BorderHeightBottom.i = BorderWidth
  MessageRequester("ShowWindow","BorderWidth: " + Str(BorderWidth) + Chr(10) + 
                                "BorderHeightTop: " + Str(BorderHeightTop) + Chr(10) +
                                "BorderHeightBottom: " + Str(BorderHeightBottom))
  HideWindow(0,#False)
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
    EndSelect
  ForEver
EndIf

Re: OpenWindow

Posted: Thu Jan 04, 2018 3:39 am
by GenRabbit
Thanks for the tip, I've tried this so far. No Success.

Code: Select all

EnableExplicit
; Result = ExamineDesktops()
;y = DesktopHeight(0)
;x = DesktopWidth(0)
;Debug Str(x) + "/"+ Str(y)
Define a.rect
Define.i PrimaryWindowHandler, PrimaryWindowEvent
SystemParametersInfo_(#SPI_GETWORKAREA,0,@a,0)
Debug Str(a\left) + "," + Str(a\right) + "," + Str(a\top) + "," + Str(a\bottom)
PrimaryWindowHandler = OpenWindow(#PB_Any, 0,0,a\right,a\bottom - GetSystemMetrics_(#SM_CYSIZEFRAME),"Test", #PB_Window_SystemMenu)
Repeat
    PrimaryWindowEvent = WindowEvent()
    Select PrimaryWindowEvent
        Case #PB_Event_CloseWindow
            Break
    EndSelect
    Delay(1)
ForEver
CloseWindow(PrimaryWindowHandler)

Re: OpenWindow

Posted: Thu Jan 04, 2018 3:50 am
by Mijikai

Re: OpenWindow

Posted: Thu Jan 04, 2018 5:02 am
by nco2k
you could use AdjustWindowRect:

Code: Select all

Define WinRect.RECT, WinStyle, WinMenu, WinWidth, WinHeight

WinStyle = #WS_CAPTION; change to the style you are planning to use
WinMenu = #False; change to #True if your window has a menubar
WinWidth = 640
WinHeight = 480

AdjustWindowRect_(@WinRect, WinStyle, WinMenu)
OpenWindow(0, 0, 0, WinWidth - (WinRect\right - WinRect\left), WinHeight - (WinRect\bottom - WinRect\top), "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

Debug WindowWidth(0, #PB_Window_FrameCoordinate)
Debug WindowHeight(0, #PB_Window_FrameCoordinate)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
however, if you want your window to be of exact size, you should create a linker option file and target windows vista and greater: /SUBSYSTEM:WINDOWS,6.0

c ya,
nco2k

Re: OpenWindow

Posted: Thu Jan 04, 2018 6:47 am
by RASHAD
Simple and clean

Code: Select all

;AdjustWindowRectEx_(r.RECT,window styles,menu-present flag,extended style)
  
  AdjustWindowRectEx_(r.RECT,#PB_Window_BorderLess,0,0)
  Debug r\right
  Debug -r\top
  AdjustWindowRectEx_(r.RECT,#PB_Window_SystemMenu,0,0)
  Debug r\right
  Debug -r\top
  AdjustWindowRectEx_(r.RECT,#PB_Window_SizeGadget,0,0)
  Debug r\right
  Debug -r\top

Re: OpenWindow

Posted: Thu Jan 04, 2018 7:38 pm
by nco2k
pb constants dont necessarily have to match winapi constants. they could contain custom bits, or change in the future, which could produce unwanted side-effects. using pb constants for winapi functions and vice versa, was never officially supported and should be avoided.

c ya,
nco2k

Re: OpenWindow

Posted: Thu Jan 04, 2018 8:57 pm
by GenRabbit
Thanks for all the tips. I think I'll use this for the time being. It also takes the taskbar into account.

Code: Select all

EnableExplicit
Define.rect a, b
Define.i PrimaryWindowHandler, PrimaryWindowEvent
SystemParametersInfo_(#SPI_GETWORKAREA,0,@b,0)
;Debug Str(b\left) + "," + Str(b\right) + "," + Str(b\top) + "," + Str(b\bottom)
AdjustWindowRectEx_(a,#WS_SYSMENU | #WS_CAPTION,0,0)
;Debug Str(a\left) + "," + Str(a\right) + "," + Str(a\top) + "," + Str(a\bottom)
PrimaryWindowHandler = OpenWindow(#PB_Any, b\left,b\top,b\right-a\right,b\bottom-abs(a\top),"Test", #PB_Window_SystemMenu)
Repeat
    PrimaryWindowEvent = WindowEvent()
    Select PrimaryWindowEvent
        Case #PB_Event_CloseWindow
            Break
    EndSelect
    Delay(1)
ForEver
CloseWindow(PrimaryWindowHandler)

Re: OpenWindow

Posted: Thu Jan 04, 2018 9:58 pm
by RASHAD
Adapt it for your needs

Code: Select all

AdjustWindowRectEx_(a.RECT,#WS_SYSMENU | #WS_CAPTION,0,0)

OpenWindow(0,0,0,0,0,"Window & TaskBar",#PB_Window_SystemMenu|#PB_Window_MaximizeGadget | #PB_Window_Invisible)
SetWindowState(0,#PB_Window_Maximize)
SetWindowLongPtr_(WindowID(0), #GWL_STYLE, GetWindowLongPtr_(WindowID(0),#GWL_STYLE)&~ #WS_MAXIMIZEBOX)
ResizeWindow(0,WindowX(0),WindowY(0),WindowWidth(0),WindowHeight(0))
HideWindow(0,0)
 
Repeat
  Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
          Quit = 1
  EndSelect
Until Quit = 1

Re: OpenWindow

Posted: Thu Jan 04, 2018 10:13 pm
by Dude
GenRabbit wrote:It also takes the taskbar into account.
No, it doesn't. My taskbar is on the left, so I don't see the window's "Close" button at all. ;) You can't assume the taskbar will always be on the bottom of the screen.

Re: OpenWindow

Posted: Thu Jan 04, 2018 10:20 pm
by nco2k
@GenRabbit
the window has a border on each side, left/right, top/bottom. currently you only substract one. do it like this:

Code: Select all

PrimaryWindowHandler = OpenWindow(#PB_Any, b\left,b\top,(b\right-b\left)-(a\right-a\left),(b\bottom-b\top)-(a\bottom-a\top),"Test", #PB_Window_SystemMenu)
also consider my suggestion about the linker option file.

c ya,
nco2k

Re: OpenWindow

Posted: Thu Jan 04, 2018 10:22 pm
by RASHAD
@GenRabbit
See my previous post
But if you want to use Windows API for Taskbar

Code: Select all

SHAppBarMessage_(#ABM_GETTASKBARPOS,@Info.AppBarData) 
If Info\uEdge	 = 0 : Position$ = "left" : EndIf 
If Info\uEdge = 1 : Position$ = "top" : EndIf 
If Info\uEdge = 2 : Position$ = "right" : EndIf 
If Info\uEdge = 3 : Position$ = "bottom" : EndIf
Debug Info\rc\left
Debug Info\rc\top
Debug Info\rc\right
Debug Info\rc\bottom
Debug Position$ 

Re: OpenWindow

Posted: Thu Jan 04, 2018 10:23 pm
by GenRabbit
nco2k wrote:@GenRabbit
the window has a border on each side, left/right, top/bottom. currently you only substract one. do it like this:

Code: Select all

PrimaryWindowHandler = OpenWindow(#PB_Any, b\left,b\top,(b\right-b\left)-(a\right-a\left),(b\bottom-b\top)-(a\bottom-a\top),"Test", #PB_Window_SystemMenu)
also consider my suggestion about the linker option file.

c ya,
nco2k
Thanks. I do not know what you mean by linker option file
I pasted your code into my program. :)

Re: OpenWindow

Posted: Thu Jan 04, 2018 10:26 pm
by GenRabbit
RASHAD wrote:@GenRabbit
See my previous post
But if you want to use Windows API for Taskbar

Code: Select all

SHAppBarMessage_(#ABM_GETTASKBARPOS,@Info.AppBarData) 
If Info\uEdge	 = 0 : Position$ = "left" : EndIf 
If Info\uEdge = 1 : Position$ = "top" : EndIf 
If Info\uEdge = 2 : Position$ = "right" : EndIf 
If Info\uEdge = 3 : Position$ = "bottom" : EndIf
Debug Info\rc\left
Debug Info\rc\top
Debug Info\rc\right
Debug Info\rc\bottom
Debug Position$ 
Thanks. I hoped my way of doing it also took the taskbars placement into consideration. I prefer to do as much as possible using PB commands rather than API calls due to Hopefully on day make them MAC/Linux compitable.

Re: OpenWindow

Posted: Thu Jan 04, 2018 10:31 pm
by GenRabbit
Dude wrote:
GenRabbit wrote:It also takes the taskbar into account.
No, it doesn't. My taskbar is on the left, so I don't see the window's "Close" button at all. ;) You can't assume the taskbar will always be on the bottom of the screen.
That came to me a little later. like "hm... but if the taskbar change position.." ;)