--slow.exw--
without warning
include win32lib.ew

constant
CXFULL=w32Func(xGetSystemMetrics,{SM_CXSCREEN}),
CYFULL=w32Func(xGetSystemMetrics,{SM_CYSCREEN}),
Win1    = create(Window,"",0,0,0,CXFULL,CYFULL,{WS_POPUP,WS_DLGFRAME}),
Bitmap2 = create(Bitmap,"",Win1,0,0,64,64,0),
Mytimer1 = 1,
CX=CXFULL-64,
CY=CYFULL-64


setWindowBackColor(Win1,rgb(0,0,0))

atom posx,posy,xsize,ysize,xdir,ydir
xdir=1 ydir=1


procedure center_win(atom win_id)
sequence loc
loc=getRect(win_id)
xsize=loc[3]-loc[1]
ysize=loc[4]-loc[2]
posx=floor((w32Func(xGetSystemMetrics,{SM_CXFULLSCREEN})/2)-(xsize/2))
posy=floor((w32Func(xGetSystemMetrics,{SM_CYFULLSCREEN})/2)-(ysize/2))
setRect(win_id,posx,posy,xsize,ysize,1 )
end procedure

procedure start_up( integer self, integer event, sequence params )
setBitmap( Bitmap2, ".\\Bin\\ball.bmp" )
center_win(Bitmap2)
setTimer( Win1, Mytimer1, 5 )  -- 200 moves/sec. maximum, we wish !
end procedure

procedure next_pos( integer self, integer event, sequence params )
if posx < 1 or posx > CX then 
    xdir = -xdir 
end if
if posy < 1 or posy > CY then 
    ydir = -ydir 
end if
posx = posx + xdir
posy = posy - ydir
setRect(Bitmap2,posx,posy,xsize,ysize,1)
end procedure

procedure quit_all()
	closeWindow(Win1)
end procedure

--procedure bitmap_clicked(integer event, atom x, atom y, atom shift)
procedure bitmap_clicked( integer self, integer event, sequence params )
	sequence loc
	integer key = params[1]	-- may be it
	integer x = params[2]	-- maybe
	integer y = params[3]
	
	if key = LeftDown then
		loc = getRect(Bitmap2)
		if x > loc[1] and x < loc[3] then
			if y > loc[2] and y < loc[4] then
				quit_all()
			end if
		end if
	end if
	
end procedure

procedure blah( integer self, integer event, sequence params )
	quit_all()
end procedure

setHandler( Win1, w32HOpen, routine_id("start_up") )
setHandler( Win1, w32HTimer, routine_id("next_pos") )

setHandler( Win1, w32HKeyDown, routine_id("blah") )
--setHandler( Win2, w32HClick, routine_id("exit_prog") )
setHandler( Win1, w32HMouse, routine_id("bitmap_clicked") )
--onKeyPress[Win1] = routine_id("blah")

WinMain( Win1,Maximize )
--end--
