Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Scanning the hierarchy of child windows down from the main VFP window
Using an Event Object. Part B: running an application responding to events
Converting an integer value to a hexadecimal string
How to extract frames from AVI files
How to read email messages using Simple MAPI
Setting properties of the window: caption and user-defined value
Comparing file times
Customizing the frame of top-level form: removing the standard frame (VFP9, Vista)
Enumerating ODBC drivers available on the local computer
How to display advanced Task Dialog (Vista)
How to generate GUID values
Printing text on the client area of the main VFP window
Reading parameters of streams in AVI file
Retrieveing information about the active window (even if it is not owned by the calling process)
Retrieving graphic capabilities of default printer
Drawing icons associated with the VFP main window
Enumerating print processors and supporting data types installed on the specified server
How to run FoxPro application under different user name (impersonating user)
Testing Transparent Menu Class with top-level form (requires VFP9)
Winsock: retrieving the host information corresponding to a network address
Clipping mouse cursor area
How to hide your program from the Close Program dialog (Win9* only)
Retrieving information about the specified icon
Retrieving the names of all sections in an initialization file
Using Multimedia Command Strings to play MIDI files

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Versions:
click to open
Before you begin:
The mciSendString can be used to play various media files including MIDI files.

 
LOCAL oForm As Tform
oForm = CREATEOBJECT("Tform")
oForm.Show(1)
* end of main
 
DEFINE CLASS Tform As Form
    Width=400
    Height=100
    Caption="MIDI Player"
    Autocenter=.T.
    MinButton=.F.
    MaxButton=.F.
    BorderStyle=2
    player=NULL
    lastpath=""
 
    ADD OBJECT Label1 As Label WITH Left=12,;
        Top=18, Autosize=.T., Caption="File:"
 
    ADD OBJECT txtMidiFile As TextBox WITH Left=50,;
        Top=16, Width=310, Height=24
 
    ADD OBJECT cmdMidiFile As CommandButton WITH Left=360,;
        Top=16, Width=24, Height=24, Caption="..."
 
    ADD OBJECT cmdPlay As CommandButton WITH Left=50,;
        Top=50, Width=60, Height=27, Caption="Play"
 
    ADD OBJECT cmdStop As CommandButton WITH Left=110,;
        Top=50, Width=60, Height=27, Caption="Stop"
 
PROCEDURE Init
    THIS.player = CREATEOBJECT("MCIPlayer")
 
PROCEDURE cmdStop.Click
    ThisForm.player.CloseMidi
 
PROCEDURE cmdPlay.Click
    ThisForm.PlayMidiFile
 
PROCEDURE cmdMidiFile.Click
    ThisForm.SelectMidiFile
 
PROCEDURE SelectMidiFile
    LOCAL cCurrentPath, cResult
    cCurrentPath = SYS(5) + SYS(2003)
    IF EMPTY(THIS.lastpath)
        THIS.lastpath = GETENV("SystemRoot") + "\Media"
    ENDIF
 
    IF DIRECTORY(THIS.lastpath)
        SET DEFAULT TO (THIS.lastpath)
    ENDIF
    cResult = GETFILE("MID;MIDI;", "Select MIDI File:", "Open", 0)
    SET DEFAULT TO (cCurrentPath)
 
    IF NOT EMPTY(m.cResult)
        THIS.txtMidiFile.Value = m.cResult
    ENDIF
 
PROCEDURE PlayMidiFile
    LOCAL cFilename
    cFilename = ThisForm.txtMidiFile.Value
    ThisForm.player.PlayMidiFile(cFilename)
 
ENDDEFINE
 
DEFINE CLASS MCIPlayer As Session
PROTECTED MidiAlias
    MidiAlias="midi_"+SYS(2015)
 
PROCEDURE Init
    THIS.declare
 
PROCEDURE Destroy
    THIS.CloseMidi
 
PROCEDURE PlayMidiFile(cFilename)
    IF THIS.OpenMidi(cFilename)
        THIS.PlayMidi
    ENDIF
 
PROTECTED PROCEDURE OpenMidi(cFilename)
    IF NOT FILE(m.cFilename)
        RETURN .F.
    ENDIF
 
    THIS.CloseMidi
    LOCAL nResult
    nResult = mciSendString("open " + m.cFilename +;
        " type sequencer alias "+THIS.MidiAlias, "", 0,0)
 
    IF m.nResult <> 0
        LOCAL cErrMsg
        cErrMsg = THIS.GetErr(m.nResult)
        = MESSAGEBOX(m.cErrMsg, 48, "Failed to open MIDI file")
        RETURN .F.
    ENDIF
RETURN .T.
 
PROTECTED PROCEDURE PlayMidi
    LOCAL nResult
    nResult = mciSendString("play "+THIS.MidiAlias, "", 0,0)
 
    IF m.nResult <> 0
        LOCAL cErrMsg
        cErrMsg = THIS.GetErr(m.nResult)
        = MESSAGEBOX(m.cErrMsg, 48, "Failed to play MIDI file")
    ENDIF
 
PROCEDURE CloseMidi
    = mciSendString("stop "+THIS.MidiAlias, "", 0,0)
    = mciSendString("close "+THIS.MidiAlias, "", 0,0)
 
PROTECTED FUNCTION GetErr(lnError)
    LOCAL cBuffer
    cBuffer = REPLICATE(CHR(0), 250)
    = mciGetErrorString(lnError, @cBuffer, LEN(cBuffer))
RETURN SUBSTR(cBuffer, 1, AT(Chr(0),cBuffer)-1)
 
PROTECTED PROCEDURE declare
    DECLARE INTEGER mciSendString IN winmm;
        STRING lpszCommand, STRING @lpszReturnString,;
        INTEGER cchReturn, INTEGER hwndCallback
 
    DECLARE INTEGER mciGetErrorString IN winmm;
        INTEGER fdwError, STRING @lpszErrorText,;
        INTEGER cchErrorText
 
ENDDEFINE
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
3041 bytes  
Created: 2008-04-14 18:31:22  
Modified: 2008-04-14 18:35:06  
Visits in 7 days: 48  
Listed functions:
mciGetErrorString
mciSendString
Printer friendly API declarations
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com offers instant, free translations of text or web pages.
User Contributed Notes:
There are no notes on this subject.


Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

Privacy policy
Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (23.22.76.170)
5 hrs.Example: 'Class for sound recording'
 Example: 'Retrieving size of a remote file'
7.92 hrs.Gallery
Page 3
 
Function group: 'Remote Access Service (RAS)'
12.66 hrs.Example: 'Listing device drivers in the system: load addresses, names'
 Function: 'SQLDataSources'
Function group: 'ODBC API'
18.03 hrs.Example: 'Detecting changes in connections to removable drives (VFP9)'
18.49 hrs.Function: 'GetClipboardOwner'
 Function: 'JetCommitTransaction'
19.19 hrs.Example: 'How to play MIDI notes'
Google
Advertise here!