without warning
include win32lib.ew

atom map, jk, myrect
integer x1, x2, y1, y2
sequence loc2

constant
MyWin = create(Window,"..fancy that '2'!",0,0,0,325,448,0),

-- untitled message-box
Win2    = create(Window,"",MyWin,0,0,334,290,{WS_POPUP,WS_DLGFRAME}),
Bitmap1 = create(Bitmap,"",Win2,2,51,322,120,0),
about1 = "This ABOUT  box demo has a 'mouse-trap',\n" &
          "and a 'fingered' web-link 'hot spot' in the bitmap.",
about2 = "This program was written in the\n" &
          "EUPHORIA programming language,\n" &
          "available at http://www.rapideuphoria.com,\n" &
          "using win32lib by David Cuny.",
Title1 = create(CText,about1,Win2,2,10,322,40,0),
Title2 = create(CText,about2,Win2,2,175,322,80,0),
myhint = create(CText,"Go to rapideuphoria.com",
    Bitmap1,0,0,170,18,or_all({WS_CHILD,ES_CENTER,WS_BORDER})),
Button1 = create(PushButton,"OK",Win2,128,255,70,25,0),
MenuHlp = create(Menu,"&Help",MyWin,0,0,0,0,0),
HlpAbout= create(MenuItem,"&About",MenuHlp,0,0,0,0,0),

--to play MIDI
  mciSendString = registerw32Function(winmm,"mciSendStringA",{C_INT,C_INT,C_INT,
                           C_INT}, C_INT),

--to move the mouse cursor to the about box.
zSetCursorPos = registerw32Function(user32,"SetCursorPos",{C_INT,C_INT},C_INT),
--to confine the mouse cursor to the about box.
zClipCursor = registerw32Function(user32,"ClipCursor",{C_POINTER},C_INT),
--a custom cursor for the 'web-link'
myPointer = createMousePointer( 5, 1, {
"    xxx          ",
"   x...x         ",
"   x...x         ",
"   x...x         ",
"   x...x         ",
"   x...x         ",
"   x...xxx       ",
"   x...x..xxx    ",
"   x...x..x..xxx ",
" xxx...x..x..x..x",
"x..x...x..x..x..x",
"x..x...x..x..x..x",
"x..x...x..x.....x",
"x...............x",
"x...............x",
"x..............x ",
" x............x  ",
"  x...........x  ",
"   x..........x  ",
"   x..........x  ",
"   x..........x  ",
"   xxxxxxxxxxxx  ",
"   xxxxxxxxxxxx  "} )

setWindowBackColor(MyWin,rgb(127,127,255))
setWindowBackColor(Win2,rgb(0,127,127))
setWindowBackColor(Title1,rgb(0,127,127))
setWindowBackColor(Title2,rgb(0,127,127))
setWindowBackColor(myhint,rgb(255,255,255))

-- MIDI play routines, from midi.ew by Brent Hugh. 
procedure MciSendString(sequence String, integer a, integer b, integer c)
integer result
atom outMsg
   outMsg=acquire_mem(0,String)
   result = w32Func(mciSendString, {outMsg, a, b, c})
end procedure

procedure PlayMidiFile(sequence MidiFile)
sequence outMsg
   --load the file  "A_Song" is the handle of the loaded song
   outMsg="open " & MidiFile & " type sequencer alias A_Song "
   MciSendString (outMsg, 0, 0, 0)
   --play the loaded file
   outMsg="play A_Song"
   MciSendString (outMsg, 0, 0, 0)
end procedure

procedure CloseMidi()
--need to close the device to re-use it !.
sequence outMsg
outMsg="close A_Song"
   MciSendString (outMsg, 0, 0, 0)
end procedure
-- end of midi code.


-- took these out of center-win,
-- to be re-used to control the mouse 'extents' in about().
atom xsize,ysize,posx,posy

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 about(atom self, atom event, sequence params)
   setVisible(myhint,0)
   openWindow(Win2,Modal)
   PlayMidiFile(".\\Bin\\roary2.mid")
   -- allocate the structure that will control the mouse 'extents',
   -- using the about box location.
   myrect=acquire_mem(0,16)
   poke4(myrect,posx)  -- top,
   poke4(myrect+4,posy)  --left.
   poke4(myrect+8,posx+xsize)  --bottom,
   poke4(myrect+12,posy+ysize)  --right.
   -- center the mouse in the about box.
   jk = w32Func(zSetCursorPos,{posx+xsize/2,posy+ysize/2})
   -- confine the mouse to this area.
   jk = w32Func(zClipCursor,{myrect})
end procedure

procedure start_up(atom self, atom event, sequence params)
   map=loadBitmapFromFile( ".\\Bin\\eu.bmp" )
   setBitmap( Bitmap1, map )
   center_win(Win2)
   loc2=getRect(Bitmap1)
   x1=loc2[1]+70
   x2=loc2[3]-80
   y1=loc2[2]+17
   y2=loc2[4]+10
end procedure

procedure close1(atom self, atom event, sequence params)
-- we MUST release the mouse-trap !
   jk=w32Func(zClipCursor,{NULL})
   closeWindow(Win2)
   CloseMidi()
end procedure

procedure on_bitmap(atom self, atom event, sequence params)  --(integer event, atom x, atom y, atom shift)
integer mouse_event = params[1]
atom x = params[2]
atom y = params[3]

if x > x1 and x < x2 and y > y1 and y < y2 then
   -- change the mouse pointer to the 'hand' defined by myPointer.
   setMousePointer( Win2, myPointer )
   if mouse_event = MouseMove then
      setRect(myhint,x-85,y-67,170,20,1 )
      setVisible(myhint,1)
   end if
   if mouse_event=LeftDown then
     setVisible(myhint,0)
     close1(self, event, params)
     CloseMidi()
     shellExecute("open","http://www.rapideuphoria.com",Modal)
   end if
else
   setVisible(myhint,0)
   -- change back to standard mouse pointer.
   setMousePointer( Win2, NULL )
end if
end procedure

procedure kill_prog( integer self, integer event, sequence params )
   CloseMidi()
end procedure

setHandler( MyWin, w32HOpen,  routine_id("start_up") )
setHandler( HlpAbout, w32HClick,  routine_id("about") )
setHandler( Button1, w32HClick,  routine_id("close1") )
setHandler( Win2, w32HMouse,  routine_id("on_bitmap") )
setHandler( MyWin, w32HDestroy, routine_id( "kill_prog" ) )
setHandler( MyWin, w32HClose,  routine_id("kill_prog") )


WinMain(MyWin, Normal)
--end--
