EVENT_WINDOWMOVE

BlitzMax Forums/BlitzMax Programming/EVENT_WINDOWMOVE

BenKo(Posted 2007) [#1]
Hi everyone

In the game I'm currently developing, I use the delta time technique to manage FPS/rendering. The problem is that when the user drags the window the program stops running code. When the user has already dragged the window and the program gets to execute code again, it gets a high value at delta time and I get undesired behaviour.

So, I need to detect when the user drags the window so I can reset my timers. After a lil' of research, I found that the EVENT_WINDOWMOVE and hooks could be the solution. But... EVENT_WINDOWMOVE is not recognized! Looking in these forums I found this thread discussing this issue http://www.blitzmax.com/Community/posts.php?topic=64713#722498 and I tried the sample code included, proving that WINDOWMOVE is not detected... but it's been a whole year! Still missing? What can I do to fix this?

Thanks in advance for your time and help :)

PS: I don't own MaxGUI, so I won't be able to use fixes that require this mod.


Grey Alien(Posted 2007) [#2]
My framework handles this. This code won't run on it's own (I've just pasted it in) but you get the idea:

Extern "win32"
    Function GetWindowRect%(hWnd%, lpRect: Byte Ptr)
End Extern

Type TRect
	Field L%, T%, R%, B%
End Type


			'Quickly check to see if the window has moved.
			'If it has, this is because the user has dragged it and so we should
			'reset the timing variables.
			Local Rect:TRect = ccWindowPositionHandle(Game.WindowHandle)
			?Win32
			If Game.WindowX <> Rect.L Or Game.WindowY <> Rect.T Then
				Init()
				Game.SetWindowCoords()
				Game.SetClientCoords()
			EndIf
			?


' -----------------------------------------------------------------------------
' ccWindowPositionHandle: Uses Windows API call to return a TRect containing a window's position
' -----------------------------------------------------------------------------
Function ccWindowPositionHandle:TRect(hWnd%)
	'Pass a handle to a window in.
	?Win32
	Local window:TRect= New TRect
	GetWindowRect(hWnd,window)
	Return window	
	?
End Function





BenKo(Posted 2007) [#3]
Thanks, but is there any cross-platform solution? I'm releasing my game for win, mac & linux :(


grable(Posted 2007) [#4]
It doesn't seem like EVENT_WINDOWMOVE is emitted from a Graphics window :/

Alternatively you could try hooking into the window procedure.
The added flip hook isn't really necessary and its prolly slow as WM_MOVE is emitted quite often when moving a window (even though MSDN says otherwise).

This is Windows only...


Grey Alien(Posted 2007) [#5]
I need a Mac solution too and I think I have it but it's different code that detects the Mac window position and see's if it has moved. Just gotta add it into my framework.


degac(Posted 2007) [#6]
Maybe I'm wrong, but with this code it is possibile to detect different 'status' (I think this is for BlitzMax without MaxGUI module - it needs BRL.Events...)

Graphics 640 , 480
Local status$="In window"
While Not AppTerminate()

	PollEvent()

	Select CurrentEvent.ID
	
		Case EVENT_APPSUSPEND , EVENT_MOUSELEAVE
			status="Out of window"
	
		Case EVENT_MOUSEENTER
			status = "In window"
			
		Case EVENT_APPRESUME
			

		Case EVENT_APPTERMINATE


	End Select

Cls
DrawText "Status: " + status , 0 , 0
Flip
Wend

Also - as BlitzMax standard - it should work on every platform
Byez


BenKo(Posted 2007) [#7]
degac, just add a

Case EVENT_WINDOWMOVE
    status = "Window moved"


to your select and you'll see what (not) happens :(


Schwang(Posted 2010) [#8]
Has anyone found a simple solution to this issue?


skidracer(Posted 2010) [#9]
A simple solution is to detect when a large (>200ms) amount of time has passed between updates and reset your timing code so as to avoid undesirable "catchup" behavior from any such pauses your app may face.


Grey Alien(Posted 2011) [#10]
It would also be useful to have a WINDOWMOVE event so that you know the new coords of the window so that you can make sure the mouse cursor slides in and out of the window properly. I did this in the end with the code I posted at the top, but it's a kludge.


matt!(Posted 2011) [#11]
Thanks for this, I wasn't aware of EVENT_MOUSELEAVE