I've been playing with the math but it got a little complex for me after a few hours.
The below is as far as I got. Part of it workd, the rest is bbeing converted to shorter variables. But I need help.
Code: Select all
;============================================================================================================================
; Snap the main form to any of the current window borders
;============================================================================================================================
Procedure SnapWindowToBorder(Window.l)
If ExamineDesktops() ; < Less than, > Greater than
CurrentScreenWidth.l = DesktopWidth(0) ; The current desktop width, can change dynamically!!
CurrentScreenheight.l = DesktopHeight(0) ; The current desktop height, can change dynamically!!
WindowHeight.l = WindowHeight(Window.l) ; The passed window height, can change dynamically!!
WindowWidth.l = WindowWidth(Window.l) ; The passed window width, can change dynamically!!
CurrentXPos.l = WindowX(Window.l) ; Current top left x position of the window
CurrentYPos.l = WindowY(Window.l) ; Current top left x position of the window
If CurrentXPos.l < 20
If CurrentYPos.l < 0
ResizeWindow(Window.l, 0, #PB_Ignore, #PB_Ignore, #PB_Ignore)
Else
ResizeWindow(Window.l, 0, 0, #PB_Ignore, #PB_Ignore)
EndIf
ElseIf CurrentYPos.l < 20
If CurrentXPos.l > 0
ResizeWindow(Window.l, #PB_Ignore, 0, #PB_Ignore, #PB_Ignore)
Else
ResizeWindow(Window.l, 0, 0, #PB_Ignore, #PB_Ignore)
EndIf
ElseIf CurrentXPos.l < 20 And CurrentYPos.l < 20
ResizeWindow(Window.l, 0, 0, #PB_Ignore, #PB_Ignore)
EndIf
If CurrentXPos.l + WindowWidth.l > CurrentScreenWidth.l - 30 ; Is form beyond right x position?
If CurrentYPos.l + CurrentScreenheight.l > CurrentScreenheight.l - 30
ResizeWindow(Window.l, CurrentScreenWidth.l - WindowWidth.l - 7, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ElseIf CurrentXPos.l + WindowWidth.l > CurrentScreenWidth.l - 30 And CurrentYPos.l >
ResizeWindow(Window.l, CurrentScreenWidth.l - WindowWidth.l - 7, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ElseIf CurrentYPos.l + WindowHeight.l > CurrentScreenheight.l - 30
ResizeWindow(Window.l, #PB_Ignore, CurrentScreenheight.l - WindowHeight.l - 26, #PB_Ignore, #PB_Ignore)
ElseIf CurrentXPos.l + WindowWidth.l > CurrentScreenWidth.l - 30 And CurrentYPos.l + WindowHeight.l > CurrentScreenheight.l - 30
ResizeWindow(Window.l, CurrentScreenWidth.l - WindowWidth.l - 7, CurrentScreenheight.l - WindowHeight.l - 26, #PB_Ignore, #PB_Ignore)
EndIf
EndIf
EndProcedure

