Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Enumerating data formats currently available on the clipboard
Custom GDI+ class
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Mapping and disconnecting network drives
Winsock: retrieving directory listing from an FTP server using passive data connection (FTP, port 21)
Winsock: sending email messages (SMTP, port 25)
How to display the Properties dialog box for a file (ShellExecuteEx)
Disk in drive A:
Detecting changes in connections to removable drives (VFP9)
Using Font and Text functions
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
How to download a file from the FTP server using FtpGetFile
How to play AVI file on the _screen
Using Video Capture: displaying on FoxPro form frames and previewing video obtained from a digital camera
Using EnumPrinters function to enumerate locally installed printers
Running MSDOS Shell as a child process with redirected input and output (smarter RUN command)
Creating irregularly shaped FoxPro form using transparency color key
Splash Screen for the VFP application
Subclassing CommandButton control to create BackColor property
Vertical Label control
Converting Unicode data from the Clipboard to a character string using a given code page
Enumerating network resources
Creating a console window for Visual FoxPro application
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: 46  
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.212.158)
3 sec.Example: 'Reading the structure of VFP main menu'
9 sec.Example: 'Copying picture of the active form to the Clipboard using Enhanced Metafile API functions'
2.19 hrs.Solution: 'LanguageBar ActiveX Control'
7.27 hrs.Example: 'How to check whether the system is 32-bit or 64-bit'
10.17 hrs.Example: 'How to copy the image of a form to the Clipboard using Bitmap API functions'
 Function: 'GetBestInterface'
10.98 hrs.Example: 'Yet another modal dialog: now HTML-based'
 Example: 'Drawing cursors for the classes defined by the system (preregistered): BUTTON, EDIT, LISTBOX etc.'
11.57 hrs.Example: 'Building a tree of subdirectories for a given path using FindFile functions'
Language: 'C#'
13.53 hrs.Function: 'EnumPorts'
Google
Advertise here!