Window within the viewable screen while dragging

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Window within the viewable screen while dragging

Post by BackupUser »

Code updated For 5.20+

Restored from previous forum. Originally posted by Kale.

keep a window within the viewable screen while dragging :)

Code: Select all

;====================================================================
; CONSTANTS
;====================================================================

#ROOT_WINDOW = 1
#ROOT_WINDOW_WIDTH = 200
#ROOT_WINDOW_HEIGHT = 100
#TASKBAR_HEIGHT = 52

;====================================================================
; GLOBAL FLAGS / VARIABLES / STRUCTURES / ARRAYS
;====================================================================

quit.b
Global clipBox.RECT

;====================================================================
; PROCEDURES
;====================================================================

Procedure checkClipBox()
  clipBox\left = WindowMouseX(#ROOT_WINDOW)
  clipBox\top = WindowMouseY(#ROOT_WINDOW)
  clipBox\right = GetSystemMetrics_(#SM_CXSCREEN) - (#ROOT_WINDOW_WIDTH - WindowMouseX(#ROOT_WINDOW))
  clipBox\bottom = GetSystemMetrics_(#SM_CYSCREEN) - (#ROOT_WINDOW_HEIGHT - WindowMouseY(#ROOT_WINDOW)) - #TASKBAR_HEIGHT
EndProcedure

Procedure windowCallback(WindowID, Message, wParam, lParam)
  ReturnValue = #PB_ProcessPureBasicEvents
  Select Message
    Case #WM_MOVE
      checkClipBox()
      ClipCursor_(@clipBox)
  EndSelect
  ProcedureReturn  ReturnValue
EndProcedure

;====================================================================
; GEOMETRY
;====================================================================

OpenWindow(#ROOT_WINDOW, 0, 0, #ROOT_WINDOW_WIDTH, #ROOT_WINDOW_HEIGHT, "Clipped Window", #PB_Window_SystemMenu | #PB_Window_WindowCentered)

;====================================================================
; MAIN LOOP
;====================================================================

SetWindowCallback(@windowCallback())

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      quit = 1
  EndSelect
Until quit = 1

CloseWindow(#ROOT_WINDOW)
End


--Kale

In love with PureBasic! :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by plouf.

these tricks do not work if the user has deactivated "View While Dragging"
(like mine :))

Christos
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Kale.

Doh! :) *goes back to the drawing board*

--Kale

In love with PureBasic! :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Berikco.
Post Reply