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

constant
string1 = "Your Main Window",
string2 = "'tracking' window",
string3 = "'tracking' modal window",
string4 = "custom message box",
string5 = "untitled message box",
string6 = "OK !",
string7 = "a win32lib tutorial",
string8 = "~Wolf 11/24/99 .",

Win1    = create( Window, string1, 0, 0, 0, 370, 320, 0 ),
Button1 = create( PushButton, string2, Win1, 5, 5, 170, 25, 0 ),
Button2 = create( PushButton, string3, Win1, 5, 31, 170, 25, 0 ),
Button3 = create( PushButton, string4, Win1, 5, 57, 170, 25, 0 ),
Button4 = create( PushButton, string5, Win1, 5, 83, 170, 25, 0 ),
-- 'tracking' window
Win2    = create( Window, string2, 0, 0, 0, 338, 190, 0 ),
Button5 = create( PushButton, string6, Win2, 135, 130, 70, 25, 0 ),
Title1  = create( CText, string7, Win2, 1, 135, 130, 20, 0 ),
-- 'tracking' modal window
Win3    = create( Window, string3, Win1, 0, 0, 338, 190, {WS_CAPTION, WS_THICKFRAME} ),
Button6 = create( PushButton, string6, Win3, 135, 130, 70, 25, 0 ),
Title2  = create( CText, string8, Win3, 206, 135, 130, 20, 0 ),
-- custom message-box
Win4    = createEx( Window, string4, Win1, 0, 0, 338, 190, {WS_CAPTION}, WS_EX_DLGMODALFRAME ),
Button7 = create( PushButton, string6, Win4, 135, 130, 70, 25, 0 ),
Title3  = create( CText, string7, Win4, 1, 135, 130, 20, 0 ),
Title4  = create( CText, string8, Win4, 206, 135, 130, 20, 0 ),
Bitmap1 = create( Bitmap, "", Win4, 0, 0, 332, 126, 0 ),
-- untitled message-box
Win5    = create( Window, "", Win1, 0, 0, 338, 165, {WS_POPUP, WS_DLGFRAME} ),
Button8 = create( PushButton, string6, Win5, 135, 130, 70, 25, 0 ),
Title5  = create( CText, "your", Win5, 1, 135, 130, 20, 0 ),
Title6  = create( CText, "message", Win5, 206, 135, 130, 20, 0 ),
Bitmap2 = create( Bitmap, "", Win5, 0, 0, 332, 126, 0 )

setBitmap( Bitmap1,".\\Bin\\eu.bmp" )
setBitmap( Bitmap2,".\\Bin\\eu.bmp" )

atom rgbColor
 rgbColor = getSysColor(COLOR_BTNFACE)

 setWindowBackColor(Win1,rgb(255,0,255))
 setWindowBackColor(Win2,rgbColor)
 setWindowBackColor(Win3,rgb(255,255,0))
 setWindowBackColor(Win4,rgbColor)
 setWindowBackColor(Win5,rgbColor)

procedure center_win(atom win_id)
sequence loc
atom xsize,ysize,posx,posy
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 track_main( atom win_id,atom modal_win_id, atom xoffset, atom yoffset )
sequence loc,loc2
atom xsize,ysize,posx,posy,maxx,maxy,diff
loc=getRect(win_id)
loc2=getRect(modal_win_id)
xsize=loc2[3]-loc2[1]
ysize=loc2[4]-loc2[2]
posx=loc[1]+xoffset
maxx=floor((w32Func(xGetSystemMetrics,{SM_CXSCREEN})))
if posx > maxx-xsize then posx=maxx-xsize  end if
if posx < 0 then posx=0 end if
posy=loc[2]+yoffset
maxy=floor((w32Func(xGetSystemMetrics,{SM_CYSCREEN})))
diff=floor((w32Func(xGetSystemMetrics,{SM_CYSCREEN}))-
           (w32Func(xGetSystemMetrics,{SM_CYFULLSCREEN})))
if posy > maxy-ysize then posy=floor(maxy-(ysize+diff/2)-3)  end if
setRect(modal_win_id,posx,posy,xsize,ysize,1 )
end procedure

procedure show_tracking_win( integer self, integer event, sequence params )
	track_main(Win1,Win2,70,40)
	openWindow(Win2,Normal)
end procedure

procedure close_tracking_win( integer self, integer event, sequence params )
	closeWindow(Win2)
end procedure

procedure show_tracking_modal( integer self, integer event, sequence params )
	setRect(Win3,0,0,338,190,1 )
	track_main(Win1,Win3,70,40)
	openWindow(Win3,Modal)
end procedure

procedure close_tracking_modal( integer self, integer event, sequence params )
	closeWindow(Win3)
end procedure

procedure show_custom_message( integer self, integer event, sequence params )
	center_win(Win4)
	openWindow(Win4,Modal)
end procedure

procedure close_custom_message( integer self, integer event, sequence params )
	closeWindow(Win4)
end procedure

procedure show_untitled( integer self, integer event, sequence params )
	center_win(Win5)
	openWindow(Win5,Modal)
end procedure

procedure close_untitled( integer self, integer event, sequence params )
	closeWindow(Win5)
	if w32Func(xIsZoomed,{getHandle(Win1)}) = 0 then
		center_win(Win1)
	end if
end procedure

setHandler( Button1, w32HClick,  routine_id("show_tracking_win") )
setHandler( Button2, w32HClick,  routine_id("show_tracking_modal") )
setHandler( Button3, w32HClick,  routine_id("show_custom_message") )
setHandler( Button4, w32HClick,  routine_id("show_untitled") )
setHandler( Button5, w32HClick,  routine_id("close_tracking_win") )
setHandler( Button6, w32HClick,  routine_id("close_tracking_modal") )
setHandler( Button7, w32HClick,  routine_id("close_custom_message") )
setHandler( Button8, w32HClick,  routine_id("close_untitled") )

WinMain( Win1,Normal )
--end--
