Microsoft Small Basic

Program Listing:
Embed this in your website
' Flickr Buttons
' Hyper Modularized Version
' MTG686-3

gw = 1250
gh = 750
initgap   = 30
heightgap = 40
imgmax = 5
tag = "Games"

GraphicsWindow.Width  = gw
GraphicsWindow.Height = gh
GraphicsWindow.Left = (Desktop.Width  - gw) / 2  ' Centralizes GraphicsWindow.
GraphicsWindow.Top  = (Desktop.Height - gh) / 2
GraphicsWindow.BackgroundColor = "Black"

LoadImages()      ' Load imgmax number of pictures.
CreateButtons()

img = 1            ' Starting from 1st picture. img is index for pic[] array.
DisplayImages()    ' Directly invoking it to display a picture aSaP.

Controls.ButtonClicked = OnButtonClicked

Loop:

If Button <> "" Then ' Awaits Button being modified by OnButtonClicked triggered event sub.
  Controls.ButtonClicked = HaltButtonEvent   ' Switches button event off!
  CheckButtons()
  DisplayImages()
  Button = ""
  Controls.ButtonClicked = OnButtonClicked   ' Reactivates it again!
EndIf

Program.Delay(100)  ' a brief delay for avoiding hammering CPU up w/ so many Ifs in a too short period of time!

Goto Loop

' --------------------------------------------------------------------------------------------------------------------------------------------------'
Sub OnButtonClicked

  Button= Controls.GetButtonCaption( Controls.LastClickedButton )
  Sound.PlayClick()

EndSub
' --------------------------------------------------------------------------------------------------------------------------------------------------'
Sub HaltButtonEvent

  ' A do-nothing sub for temporarily deactivate event triggers!

EndSub
' --------------------------------------------------------------------------------------------------------------------------------------------------'
Sub CheckButtons

  If Button = "Forward"  Then
    img = img + 1
  ElseIf Button = "Back" Then
    img = img - 1
  ElseIf Button = "Reload" Then
    LoadImages()
  ElseIf Button = "Quit" Then
    Sound.PlayChimeAndWait()
    Program.End()
  EndIf

EndSub
' --------------------------------------------------------------------------------------------------------------------------------------------------'
Sub DisplayImages

  If img > PicCount Then
    img = PicCount
  ElseIf img < 1    Then
    img = 1
  EndIf

  GraphicsWindow.DrawResizedImage(pic[img]  100,initgap  gw-140,gh-60)
  GraphicsWindow.Title = "Image #" + img

EndSub
' --------------------------------------------------------------------------------------------------------------------------------------------------'
Sub LoadImages

  For i = 1 To imgmax
    GraphicsWindow.Title = "Loading #" + i
    Sound.PlayChimes()
    pic[i] = ImageList.LoadImage( Flickr.GetRandomPicture(tag) )
  EndFor

  PicCount = Array.GetItemCount(pic)   ' Redundant to imgmax. Using just for example purposes.

EndSub
' --------------------------------------------------------------------------------------------------------------------------------------------------'
Sub CreateButtons

  GraphicsWindow.BrushColor = "Blue"
  Controls.AddButton("Forward"  10,initgap*1 + heightgap*0)
  Controls.AddButton("Back"     10,initgap*1 + heightgap*1)

  GraphicsWindow.BrushColor = "Green"
  Controls.AddButton("Reload"   10,initgap*2 + heightgap*2)

  GraphicsWindow.BrushColor = "Red"
  Controls.AddButton("Quit"     10,initgap*2 + heightgap*3)

EndSub
' --------------------------------------------------------------------------------------------------------------------------------------------------'
Copyright (c) Microsoft Corporation. All rights reserved.