    $ filename "Lyrics.exe"
     
    'uses rtl32
    'uses rtl64
     
    uses WinUtil
    'uses console
    indexbase 1
     
    % DS_MODALFRAME=128
    % GCLP_HBRBACKGROUND= -10
    % COLOR_3DFACE=15
     
    extern lib "winmm.dll"
    ! mciSendString "mciSendStringA"    '4
    end extern
     
    declare sub loadlyrics()
     
    redim bstring lyrics[30]
    sys lbl[5]
     
    loadlyrics()
     
    sys hInstance=inst
    MainWindow 400,220, DS_MODALFRAME OR WS_POPUP OR WS_CAPTION OR WS_SYSMENU
     
     
    function WndProc(sys hwnd, uMsg, wParam, lParam) as sys callback
    int unit, x
     
        select uMsg
            case WM_CREATE
                static string temp=space 256
                SetWindowText(hwnd, "Tom Lehrer - Who's next")
                'Adjust color of MainWindow
                SetClassLongPtr(hwnd,GCLP_HBRBACKGROUND, GetSysColorBrush(COLOR_3DFACE))
                char cts="static"
                int sty=WS_CHILDWINDOW | WS_VISIBLE            
                lbl[1]=CreateWindowEx(0,cts,"",sty, 20, 30,360,25, hwnd,0,hinstance,0)
                lbl[2]=CreateWindowEx(0,cts,"",sty, 20, 55,360,25, hwnd,0,hinstance,0)
                lbl[3]=CreateWindowEx(0,cts,"",sty, 20, 80,360,25, hwnd,0,hinstance,0)
                lbl[4]=CreateWindowEx(0,cts,"",sty, 20,105,360,25, hwnd,0,hinstance,0)
                lbl[5]=CreateWindowEx(0,cts,"",sty, 20,130,360,25, hwnd,0,hinstance,0)
           
                mciSendString("open whonext.mid type sequencer alias whonext", 0, 0, 0)
                mciSendString("status whonext length", temp, 256,0)
                unit=val(temp)
                if unit=0 then
                  mbox "Cannot open whonext.mid. Sorry!"
                  SendMessage(hwnd, WM_CLOSE,0,0)
                end if  
                if unit !=759 then
                  mbox "Wrong midi file. Sorry!"
                  SendMessage(hwnd, WM_CLOSE,0,0)
                end if  
     
                mciSendString("play whonext", 0, 0, 0)
     
                SetTimer(hwnd,1000,10,0)
    /*
            'check the position
            case WM_LBUTTONDOWN
                mciSendString("status whonext position", temp, 256,0)
                unit=val(temp)
                printl unit
    */
            case WM_TIMER
                '
                static int m, n, cn, nn

                subroutine Clear
                  if n<>cn
                    for x=1 to 5 : SetWindowText(lbl[x])="" : next
                    cn=n
                  endif            
                end subroutine
                '
                mciSendString("status whonext position", temp, 256,0)
                unit=val(temp)
                select unit
                case >= 725 : m=4 : n=30 : KillTimer(hwnd)
                case >= 705 : m=3 : n=29
                case >= 692 : m=2 : n=28
                case >= 682 : m=1 : n=27 : gosub clear   '6'
                case >= 660 : m=4 : n=26
                case >= 636 : m=3 : n=25
                case >= 617 : m=2 : n=24
                case >= 596 : m=1 : n=23 : gosub clear   '5'
                case >= 572 : m=5 : n=22
                case >= 532 : m=4 : n=21
                case >= 510 : m=3 : n=20
                case >= 489 : m=2 : n=19
                case >= 461 : m=1 : n=18 : gosub clear  '4b'
                case >= 422 : m=2 : n=17
                case >= 379 : m=1 : n=16 : gosub clear  '4a'
                case >= 355 : m=5 : n=15
                case >= 336 : m=4 : n=14
                case >= 312 : m=3 : n=13
                case >= 291 : m=2 : n=12
                case >= 265 : m=1 : n=11 : gosub clear  '3'
                case >= 245 : m=5 : n=10
                case >= 228 : m=4 : n=9 
                case >= 205 : m=3 : n=8
                case >= 185 : m=2 : n=7
                case >= 165 : m=1 : n=6  : gosub clear  '2'
                case >= 141 : m=5 : n=5
                case >= 121 : m=4 : n=4
                case >= 98  : m=3 : n=3 
                case >= 80  : m=2 : n=2
                case >= 59  : m=1 : n=1   '1'
                end select
                '
                if n<>nn
                  SetWindowText(lbl[m],lyrics[n])
                  nn=n
                endif
                '                          
            case WM_CLOSE
                'Close whonext.mid file and sequencer device
                mciSendString("close whonext", 0, 0, 0)
                KillTimer(hwnd)
                DestroyWindow(hwnd)
            
            case WM_DESTROY
                del lyrics
                PostQuitMessage(0)
            
            case else
                return DefWindowProc(hwnd, uMsg, wParam, lParam)
                
        end select
        
        return 0
    end function
     
    'Tom Lehrer - Who's next (1965)
    sub loadlyrics()
    lyrics={
    "First we got the bomb, and that was good,",
    "'Cause we love peace and motherhood.",
    "Then Russia got the bomb, but that's okay,",
    "'Cause the balance of power's maintained that way.",
    "Who's next?",
     
    "Then France got the bomb, but don't you grieve,",
    "'Cause they're on our side (I believe).",
    "China got the bomb, but have no fears,",
    "'Cause they can't wipe us out for a least five years.",
    "Who's next?",
     
    "Japan will have its own device,",
    "Transistorized at half the price.",
    "South Africa wants two, that's right:",
    "One for the black and one for the white.",
    "Who's next?",
     
    "Egypt's gonna get one too,",
    "Just to use on you-know-who.",
    "So Israel's getting tense,",
    "Wants one in self defense.",
    "The Lord's our shepherd says the psalm,",
    "But just in case, we better get a bomb.",
    "Who's next?",
     
    "Luxembourg is next to go,",
    "And (who knows?) maybe Monaco.",
    "We'll try to stay serene and calm",
    "When Alabama gets the bomb.",
    "Who's next?",
    "Who's next?",
    "Who's next?",
    "Who's next??"
    }
    'countof 30
    end sub
     