I have a two part question:
1) how can I determine the size of my screen
2) how can I prevent my window from being dragged off the screen
Screen size
Re: Screen size
1) Check the 'Desktop' chapter in the PB Help.
2) Windows only or platform independent?
2) Windows only or platform independent?
PB 5.73 on Windows 10 & OS X High Sierra
Re: Screen size
Hello kpeters58
Thank you, I have been through a lot of the manual but obviously not this chapter.
Right now it is Windows only.
Thank you, I have been through a lot of the manual but obviously not this chapter.

Right now it is Windows only.
Re: Screen size
Hi
It could be cross platform
Code: Select all
Global DesktopWidth, DesktopHeight ,ww,hh
ExamineDesktops()
DesktopWidth = DesktopWidth(0)
DesktopHeight = DesktopHeight(0)
Procedure winCB(hWnd, uMsg, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
Select uMsg
Case #WM_SIZING
ww = WindowWidth(0)
hh = WindowHeight(0)
Case #WM_MOVING
*winRect.Rect = lparam
If *winRect\left <= 0
*winRect\left = 0
*winRect\right = *winRect\left + ww
EndIf
If *winRect\Top < 0
*winRect\Top = 0
*winRect\bottom = *winRect\Top + hh
EndIf
If *winRect\right >= DesktopWidth
*winRect\left = DesktopWidth - ww
*winRect\right = *winRect\left + ww
EndIf
If *winRect\bottom >= DesktopHeight
*winRect\Top = DesktopHeight - hh
*winRect\bottom = *winRect\top + hh
EndIf
EndSelect
ProcedureReturn result
EndProcedure
OpenWindow(0, 0,0,400,300, "Restrict moving", #PB_Window_SystemMenu | #PB_Window_SizeGadget|#PB_Window_ScreenCentered)
ww = 400
hh = 300
SetWindowCallback(@winCB())
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit = 1
End
Code: Select all
Global DesktopWidth, DesktopHeight ,ww,hh
ExamineDesktops()
DesktopWidth = DesktopWidth(0)
DesktopHeight = DesktopHeight(0)
Procedure moveCB()
xl = -8
yt = 0
xr = DesktopWidth - WindowWidth(0) - 8
yb = DesktopHeight - WindowHeight(0)
If WindowX(0) < 0
ResizeWindow(0,xl,#PB_Ignore,#PB_Ignore,#PB_Ignore)
EndIf
If WindowY(0) < 1
ResizeWindow(0,#PB_Ignore,yt,#PB_Ignore,#PB_Ignore)
EndIf
If (WindowX(0) + WindowWidth(0)) > DesktopWidth-1
ResizeWindow(0,xr,#PB_Ignore,#PB_Ignore,#PB_Ignore)
EndIf
If (WindowY(0) + WindowHeight(0)) > DesktopHeight-1
ResizeWindow(0,#PB_Ignore,yb,#PB_Ignore,#PB_Ignore)
EndIf
EndProcedure
OpenWindow(0, 0,0,400,300, "Restrict moving", #PB_Window_SystemMenu | #PB_Window_SizeGadget|#PB_Window_ScreenCentered)
ww = 400
hh = 300
BindEvent(#PB_Event_MoveWindow,@moveCB())
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit = 1
End
Egypt my love