Detecting a window move event
Posted: Sun Aug 27, 2023 12:11 am
I can't find anything about detecting when a window is being moved/resized?
Thank you...
Thank you...
http://www.purebasic.com
https://www.purebasic.fr/english/
Possible Events are :
#PB_Event_Menu : a menu has been selected
#PB_Event_Gadget : a gadget has been pushed
#PB_Event_SysTray : an icon in the systray zone was clicked
#PB_Event_Timer : a timer has reached its timeout
#PB_Event_CloseWindow : the window close gadget has been pushed
#PB_Event_Repaint : the window content has been destroyed and must be repainted (useful for 2D graphics operations)
#PB_Event_SizeWindow : the window has been resized
#PB_Event_MoveWindow : the window has been moved
#PB_Event_MinimizeWindow : the window has been minimized
#PB_Event_MaximizeWindow : the window has been maximized
#PB_Event_RestoreWindow : the window has been restored to normal size (either from a minimum or maximum size)
#PB_Event_ActivateWindow : the window has been activated (got the focus)
#PB_Event_DeactivateWindow: the window has been deactivated (lost the focus)
#PB_Event_WindowDrop : a Drag & Drop operation was finished on a window
#PB_Event_GadgetDrop : a Drag & Drop operation was finished on a gadget
#PB_Event_RightClick : a right mouse button click has occurred on the window. This can be useful to display a popup menu
#PB_Event_LeftClick : a left mouse button click has occurred on the window
#PB_Event_LeftDoubleClick : a left mouse button double-click has occurred on the window
Code: Select all
Repeat
Event = WaitWindowEvent()
Select EventWindow()
Case MainWindow
MainWindow_Events(Event) ; This procedure name is always window name followed by '_Events'
EndSelect
Until Event = #PB_Event_CloseWindow ; Quit on any window close
Code: Select all
Procedure MainWindow_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
Case #MenuFileOpen
MenuFileOpenEvent(EventMenu())
Case #MenuFileExit
MenuFileExitEvent(EventMenu())
Case #Toolbar_0
Toolbar_0_Event(EventMenu())
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case ButtonOK
ButtonOKEvent(EventType())
Case ButtonCancel
ButtonCancelEvent(EventType())
Case ButtonQuit
ButtonQuitEvent(EventType())
Case ButtonReadIni
ButtonReadIniEvent(EventType())
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
Code: Select all
Procedure MainWindow_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_MoveWindow
...Your Code...
Case #PB_Event_SizeWindow
... Your Code ....
Case #PB_Event_Menu
Select EventMenu()
....Code: Select all
IncludeFile "MainForm.pbf" ; Include the first window definition
Enumeration FormMenu ; <- Same name of form file
#PopupMenu_1
#PopupMenu_2
EndEnumeration
; Create PopupMenu
CreatePopupMenu(1)
MenuItem(#PopupMenu_1, "Menu 1")
MenuItem(#PopupMenu_2, "Menu 2")
; The event procedures, as specified in the 'event procedure' property of each gadget
Procedure DoCanvasEvent(EventType)
Select EventType
Case #PB_EventType_RightClick
DisplayPopupMenu(1, WindowID(#MainWindow))
EndSelect
EndProcedure
Procedure DoMenuEvent(EventMenu)
Select EventMenu
Case #MenuItem_Exit
PostEvent(#PB_Event_CloseWindow, #MainWindow, 0)
EndSelect
EndProcedure
Procedure DoPopupMenuEvent(EventMenu)
Select EventMenu
Case #PopupMenu_1
Debug "Popup Menu 1"
Case #PopupMenu_2
Debug "Popup Menu 2"
EndSelect
EndProcedure
Procedure DoWindowEvent(Event, Window)
Select Window
Case #MainWindow
Select Event
Case #PB_Event_MaximizeWindow
Debug "Maximize"
;
Case #PB_Event_MinimizeWindow
Debug "Minimize"
;
Case #PB_Event_MoveWindow
Debug "Move"
;
EndSelect
EndSelect
EndProcedure
;- Open Main
OpenMainWindow() ; Open the first window. This procedure name is always 'Open' followed by the window name
If IsWindow(#MainWindow)
; The main event loop as usual, the only change is to call the automatically
; generated event procedure for each window.
Repeat
Event = WaitWindowEvent()
; Call Event Procedures from FormDesigner
Select EventWindow()
Case #MainWindow
If MainWindow_Events(Event) = #False ; This procedure name is always window name followed by '_Events'
Break
EndIf
EndSelect
; Call Own Extended Event Procedures
Select Event
Case #PB_Event_Menu
DoPopupMenuEvent(EventMenu())
EndSelect
ForEver
EndIf
Code: Select all
;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;
Enumeration FormWindow
#MainWindow
EndEnumeration
Enumeration FormGadget
#Canvas_Gad
EndEnumeration
Enumeration FormMenu
#MenuItem_Exit
EndEnumeration
Declare DoMenuEvent(Event)
Declare DoCanvasEvent(EventType)
Declare DoWindowEvent(Event, Window)
Procedure OpenMainWindow(x = 0, y = 0, width = 600, height = 400)
OpenWindow(#MainWindow, x, y, width, height, "", #PB_Window_SystemMenu)
CreateMenu(0, WindowID(#MainWindow))
MenuTitle("File")
MenuItem(#MenuItem_Exit, "Exit")
CanvasGadget(#Canvas_Gad, 10, 10, 580, 380)
EndProcedure
Procedure MainWindow_Events(event)
Select event
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
Case #MenuItem_Exit
DoMenuEvent(EventMenu())
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #Canvas_Gad
DoCanvasEvent(EventType())
EndSelect
Default
DoWindowEvent(event,#MainWindow)
EndSelect
ProcedureReturn #True
EndProcedure