Example Programs

For some examples showing how to call APIs, examine the programs named CALL32?.BAS that are included with Liberty BASIC.

  'CALL32-4.BAS - Make some API calls to play wave files and
  'dynamically resize a window
  open "kernel32" for dll as #kernel
  open "user32" for dll as #user
  open "winmm" for dll as #mm
  open "Me" for window as #aWindow
  print str$(playMode)
  wavefile$ = "chimes.wav"
  playMode = 4
  calldll #mm, "sndPlaySoundA", _
    wavefile$ as ptr,_
    playMode as long,_
    result as long
  hndl = hwnd(#aWindow)
  for x = 50 to 350 step 5
    calldll #user, "MoveWindow", _
      hndl as ulong, _
      50 as long, _
      50 as long, _
      x as long, _
      x as long, _
      1 as long, _
      result as boolean
  next x
  input r$
  progname$ = "notepad.exe"
  code = _SW_SHOWNA
  notice str$(code)
  calldll #kernel, "WinExec", _
    progname$ as struct, _
    code as ushort, _
    result as ushort
  print result
  close #kernel
  wait
 

***********************************************

  'CALL32-5.BAS - make various API calls to play
  'wave files, track
  'the mouse position, and move a window around
  struct point, x as long, y as long
  open "kernel32" for dll as #kernel
  open "user32" for dll as #user
  open "Me" for window as #aWindow
  hndl = hwnd(#aWindow)
  for i = 1 to 500
    calldll #user, "GetCursorPos", _
      point as struct, _
      result as void
    x = point.x.struct
    y = point.y.struct
    calldll #user, "MoveWindow", _
      hndl as ulong, _
      x as long, _
      y as long, _
      100 as long, _
      100 as long, _
      1 as long, _
      result as boolean
  next x
  progname$ = "notepad.exe call32-5.bas"
  code = _SW_NORMAL
  notice str$(code)
  calldll #kernel, "WinExec", _
    progname$ as struct, _
    code as long, _
    result as long
  print result
  close #kernel
  wait