EVENT_WINDOWMOVE

BlitzMax Forums/BlitzMax Programming/EVENT_WINDOWMOVE

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.

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




Thanks, but is there any cross-platform solution? I'm releasing my game for win, mac & linux :(

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).
SuperStrict

Graphics( 640,480,0)

AddHook FlipHook, MyFlip
Global oldfunc:Int = SetWindowFunc( GetBlitzmaxWindow(), WindowFunc)

Repeat

	Flip
	
Until KeyHit(KEY_ESCAPE) Or AppTerminate()
End

Function SetWindowFunc:Int( hwnd:Int, newfunc:Int( hwnd:Int, msg:Int, wparam:Int, lparam:Int))
	Local oldfunc:Int = GetWindowLongW( hwnd, GWL_WNDPROC)
	SetWindowLongW( hwnd, GWL_WNDPROC, Int(Byte Ptr newfunc))
	Return oldfunc
EndFunction

Function GetBlitzmaxWindow:Int()
	Extern "Win32"
		Function FindWindowA:Int( classname$z, windowtitle$z)	
	EndExtern
	Local handle:Int = FindWindowA( "BLITZMAX_WINDOW_CLASS", AppTitle)				' MaxGUI
	If Not handle Then handle = FindWindowA( "BlitzMax GLGraphics", AppTitle)			' GLMax2D
	If Not handle Then handle = FindWindowA( "BBDX7Device Window Class", AppTitle)	' D3D7Max2D
	Return handle
EndFunction

Function WindowFunc:Int( hwnd:Int, msg:Int, wparam:Int, lparam:Int) "Win32"
	If msg = WM_MOVE Then Flip
	Return CallWindowProcW( Byte Ptr oldfunc, hwnd, msg, wparam, lparam)
EndFunction

Function MyFlip:Object( id:Int, data:Object, context:Object)
	Cls
	
	DrawText "Hello World!", Rand(640),Rand(480)	
EndFunction

This is Windows only...

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.

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

degac, just add a

Case EVENT_WINDOWMOVE
    status = "Window moved"


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