Detecting a window move event
Detecting a window move event
I can't find anything about detecting when a window is being moved/resized?
Thank you...
Thank you...
Re: Detecting a window move event
You can find the related constants in WindowEvent() doc
The PB constants page lists all constants and where they can be located in the documentation.
The PB constants page lists all constants and where they can be located in the documentation.
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
Re: Detecting a window move event
Thank you...
Re: Detecting a window move event
Happy to help.
Re: Detecting a window move event
I'm new to PB and I am a bit lost as to where to put my window move code.
I have this code block at the bottom of my .pb file:
and I have this code in the bottom of my MainWindow.pbf file:
I don't understand the relationship of the pbf (the window form) file to the .pb (the procedures file).
Do I put the Case #PB_Event_MoveWindow line in the .pbf file and have it call my window move procedure in the .pb file?
I have this code block at the bottom of my .pb file:
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
Do I put the Case #PB_Event_MoveWindow line in the .pbf file and have it call my window move procedure in the .pb file?
Re: Detecting a window move event
There are two possibilities :
or better :
use BindEvent() and a single procedure for each event
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()
....use BindEvent() and a single procedure for each event
Re: Detecting a window move event
Thank you
Re: Detecting a window move event
Changing the file "MainWindow_Events" is not a good idea because it will be overwritten by the FormDesigner.
It is better to extend the MainFile.pb.
Update
- Added DoWindowEvent
MainFile.pb
MainForm.pbf
It is better to extend the MainFile.pb.
Update
- Added DoWindowEvent
MainFile.pb
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
Last edited by mk-soft on Sun Aug 27, 2023 12:24 pm, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Detecting a window move event
@rfresh737
If you then understand how Purebasic's event management works, you can also use my EventDesigner.
(RAD tool for the lazy writer)
see signature
If you then understand how Purebasic's event management works, you can also use my EventDesigner.
(RAD tool for the lazy writer)
see signature
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Detecting a window move event
I like to put window move events in a procedure linked to BindEvent() that way you get the events in real time as they happen.
BERESHEIT



