OpenWindow

Just starting out? Need help? Post your questions and find answers here.
GenRabbit
Enthusiast
Enthusiast
Posts: 118
Joined: Wed Dec 31, 2014 5:41 pm

OpenWindow

Post 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?
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: OpenWindow

Post 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
GenRabbit
Enthusiast
Enthusiast
Posts: 118
Joined: Wed Dec 31, 2014 5:41 pm

Re: OpenWindow

Post 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)
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: OpenWindow

Post by Mijikai »

User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: OpenWindow

Post 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
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: OpenWindow

Post 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
Egypt my love
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: OpenWindow

Post 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
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
GenRabbit
Enthusiast
Enthusiast
Posts: 118
Joined: Wed Dec 31, 2014 5:41 pm

Re: OpenWindow

Post 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)
Last edited by GenRabbit on Thu Jan 04, 2018 10:20 pm, edited 1 time in total.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: OpenWindow

Post 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
Egypt my love
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: OpenWindow

Post 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.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: OpenWindow

Post 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
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: OpenWindow

Post 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$ 
Egypt my love
GenRabbit
Enthusiast
Enthusiast
Posts: 118
Joined: Wed Dec 31, 2014 5:41 pm

Re: OpenWindow

Post 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. :)
Last edited by GenRabbit on Thu Jan 04, 2018 10:33 pm, edited 1 time in total.
GenRabbit
Enthusiast
Enthusiast
Posts: 118
Joined: Wed Dec 31, 2014 5:41 pm

Re: OpenWindow

Post 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.
GenRabbit
Enthusiast
Enthusiast
Posts: 118
Joined: Wed Dec 31, 2014 5:41 pm

Re: OpenWindow

Post 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.." ;)
Post Reply