Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Obtaining some properties for the Windows desktop using the GetWindowPlacement function
Quering a waveform-audio input device
Retrieving window and menu help context identifiers
Simple printer queue monitor: deletes, pauses, resumes print jobs for local printer
Accessing Windows Control Panel from VFP Application
Copying files as a transacted operation (Vista)
Drawing icons associated with the VFP main window
Enumerating ODBC Data Sources available on the local computer
How to get Special Folders paths
Retrieving configuration information for the specified server (Win98/Me)
Retrieving current settings for an ODBC connection
Retrieving Printer Device Context using PrintDlg function
Using FrameRgn for displaying system colors
Current keyboard type
Extracting the name and extension parts of a path string
Finding the path to the VFP executable running
Quering Audio Mixer Device
Time in milliseconds represented as string (e.g. 1 hour 24 min 36 sec)
Uploading file to the FTP server using InternetWriteFile
Using Font and Text functions
GDI+: Storing DLL icon resources in image files
Obtaining provider name for a specific type of network
Reading parameters of streams in AVI file
Retrieving the User Datagram Protocol (UDP) listener table
WAV file recorder

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
Before you begin:
This code is based on TWaveRecorder class defined in example Custom class for .WAV recording.


The recorder is able to record audio coming from playback devices like Wave, Microphone etc. Check active playback and recording devices and their volumes before running this code.


Also take a look at WAV file player.
 
LOCAL obj
obj = CREATEOBJECT("Tform")
obj.Show(1)
* end of main
 
DEFINE CLASS Tform As Form
#DEFINE ccTempWaveFile "temp$$$.wav"
#DEFINE ccCursor "csSound"
    rc=NULL
    state="IDLE"
    Width=500
    Height=270
    BorderStyle=2
    MaxButton=.F.
    MinButton=.F.
    Autocenter=.T.
    KeyPreview=.T.
    Caption="WAVE recorder"
 
    ADD OBJECT cmdRecord As CommandButton WITH;
    Left=20, Top=220, Width=80, Height=27, Caption="Record"
 
    ADD OBJECT cmdPause As CommandButton WITH;
    Left=100, Top=220, Width=60, Height=27, Caption="Pause"
 
    ADD OBJECT cmdReplay As CommandButton WITH;
    Left=180, Top=220, Width=60, Height=27, Caption="Play"
 
    ADD OBJECT cmdStop As CommandButton WITH;
    Left=260, Top=220, Width=60, Height=27, Caption="Stop"
 
    ADD OBJECT cmdClose As CommandButton WITH Cancel=.T.,;
    Left=400, Top=220, Width=80, Height=27, Caption="Close"
 
    ADD OBJECT progress0 As Shape WITH;
    Left=3, Top=195, Width=492, Height=12
 
    ADD OBJECT progress As Shape WITH Visible=.F., BorderStyle=0,;
    Left=4, Top=196, Width=490, Height=11, BackColor=Rgb(0,0,212)
 
    ADD OBJECT lst As OleControl WITH OleClass="MSComctlLib.ListViewCtrl",;
    Left=2, Width=494, Top=2, Height=190
 
    ADD OBJECT tm As Timer WITH Interval=0
 
PROCEDURE Init
    THIS.state="IDLE"
    THIS.rc = CREATEOBJECT("TWaveRecorder")
 
    DECLARE INTEGER sndPlaySound IN winmm;
        STRING lpszSound, INTEGER fuSound
 
    IF THIS.rc.errorno = 0
        THIS.cmdRecord.Enabled = .T.
    ENDIF
    IF USED(ccCursor)
        USE IN (ccCursor)
    ENDIF
 
PROCEDURE KeyPress(nKeyCode, nShiftAltCtrl)
    IF nKeyCode=27
        THIS.Release
    ENDIF
 
PROCEDURE state_ASSIGN(nState)
    DO CASE
    CASE m.nState="IDLE"
        THIS.cmdPause.Caption="Resume"
        THIS.EnableButtons(.T., .F., .T., .T.)
    CASE m.nState="RECORDING"
        THIS.cmdPause.Caption="Pause"
        THIS.EnableButtons(.T., .T., .F., .T.)
    CASE m.nState="PAUSED"
        THIS.cmdPause.Caption="Resume"
        THIS.EnableButtons(.F., .T., .F., .T.)
    ENDCASE
    THIS.state = m.nState
 
PROTECTED PROCEDURE EnableButtons(lRecord, lPause, lReplay, lStop)
    THIS.cmdRecord.Enabled=m.lRecord
    THIS.cmdPause.Enabled=m.lPause
    THIS.cmdReplay.Enabled=m.lReplay
    THIS.cmdStop.Enabled=m.lStop
 
PROCEDURE lst.Init
    WITH THIS
        .View=3
        .HideSelection=.F.
        .FullRowSelect=.T.
        .Gridlines=.T.
        .ColumnHeaders.Add(1,,"Saved at", 140)
        .ColumnHeaders.Add(2,,"Quality", 160)
        .ColumnHeaders.Add(3,,"Bytes", 80)
        .ColumnHeaders.Add(4,,"Seconds", 70)
    ENDWITH
 
PROCEDURE Destroy
    THIS.StopReplaying
    THIS.rc=NULL
 
PROCEDURE cmdRecord.Click
    ThisForm.StartRecording()
 
PROCEDURE cmdPause.Click
    ThisForm.PauseRecording
 
PROCEDURE cmdStop.Click
    ThisForm.OnStop
 
PROCEDURE OnStop
    DO CASE
    CASE THIS.state="PAUSED"
        ThisForm.StopRecording
    CASE THIS.state="RECORDING"
        ThisForm.StopRecording
    OTHERWISE
        ThisForm.StopReplaying
    ENDCASE
 
PROCEDURE cmdReplay.Click
    ThisForm.StartReplaying
 
PROCEDURE cmdClose.Click
    ThisForm.Release
 
PROCEDURE tm.Timer
    ThisForm.OnTimer
 
PROCEDURE StartRecording
    THIS.StopReplaying
    IF THIS.rc.StartRecording()
        THIS.progress.Width=0
        THIS.progress.Visible=.T.
        THIS.tm.Interval=10
        THIS.state="RECORDING"
    ENDIF
 
PROCEDURE PauseRecording
    IF THIS.state="PAUSED"
        THIS.rc.StartRecording(.T.)
        THIS.state="RECORDING"
    ELSE
        THIS.rc.StopRecording
        THIS.state="PAUSED"
    ENDIF
 
PROCEDURE StopRecording
    IF THIS.state <> "IDLE"
        THIS.tm.Interval = 0
        THIS.rc.StopRecording
        THIS.progress.Width = THIS.progress0.Width
        THIS.progress.Visible = .F.
        THIS.SaveRecord
        THIS.state="IDLE"
    ENDIF
 
PROCEDURE StopReplaying
    = sndPlaySound(NULL, 0)
    DELETE FILE (ccTempWaveFile)
    THIS.state="IDLE"
 
PROCEDURE StartReplaying
#DEFINE SND_ASYNC 1
#DEFINE SND_NODEFAULT 2
    THIS.StopReplaying
    IF VARTYPE(THIS.lst.SelectedItem) <> "O"
        RETURN
    ENDIF
 
    LOCAL nRecno
    nRecno = VAL(THIS.lst.SelectedItem.Tag)
 
    SELECT (ccCursor)
    IF BETW(nRecno, 1, RECCOUNT())
        GO nRecno
        IF STRTOFILE(wavedata, ccTempWaveFile) <> 0
            = sndPlaySound(ccTempWaveFile,;
                BITOR(SND_ASYNC, SND_NODEFAULT))
        ENDIF
    ENDIF
 
PROCEDURE SaveRecord
    IF Not THIS.rc.CreateWaveFile(ccTempWaveFile)
        = MESSAGEBOX(TRANSFORM(THIS.rc.errorno) + ". " +;
            THIS.rc.errormessage, 48, "File not saved!")
        RETURN .F.
    ENDIF
 
    LOCAL cBuffer, nBufsize
    cBuffer = FILETOSTR(ccTempWaveFile)
    nBufsize = LEN(m.cBuffer)
    DELETE FILE ccTempWaveFile
 
    IF NOT USED(ccCursor)
        CREATE CURSOR (ccCursor) (dt T, wavesize I,;
            playtime N(9,2), wavedata M)
    ENDIF
 
    SELECT (ccCursor)
    APPEND BLANK
    REPLACE dt WITH DATETIME(), wavesize WITH m.nBufsize,;
        playtime WITH m.nBufsize/THIS.rc.GetAvgBytesPerSecond(),;
        wavedata WITH m.cBuffer
 
    WITH THIS.lst.ListItems.Add(RECCOUNT(ccCursor),,;
            TTOC(DATETIME()))
        .Subitems(1) = THIS.rc.GetQuality()
        .Subitems(2) = LTRIM(STR(wavesize))
        .Subitems(3) = LTRIM(STR(playtime))
        .Tag = LTRIM(STR(RECCOUNT(ccCursor)))
        .Selected = .T.
    ENDWITH
    THIS.lst.SetFocus
 
PROCEDURE OnTimer
    LOCAL nDone
    WITH THIS.rc
        nDone = .GetPosition()
        DO CASE
        CASE THIS.state = "PAUSED"
        CASE .GetDeviceStatus() = 0
            THIS.StopRecording
        OTHERWISE
            THIS.progress.Width = INT(THIS.progress0.Width *;
                nDone / .GetDataSize())
        ENDCASE
    ENDWITH
 
ENDDEFINE
 
 
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
5317 bytes  
Created: 2003-09-16 14:06:58  
Modified: 2006-04-26 12:29:20  
Visits in 7 days: 53  
Listed functions:
sndPlaySound
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 (107.20.7.65)
4 sec.Example: 'Comparing dimensions of the VFP main window with _SCREEN properties'
7 sec.Example: 'Retrieving configuration information for the specified server (Win2000/XP)'
6.57 min.Function: 'GlobalFree'
6.62 min.Function: 'MessageBeep'
Function group: 'Error Handling'
33.12 min.Example: 'Retrieving Window Class information for the VFP window'
33.18 min.Function: 'SetKeyboardState'
52.5 min.Example: 'Obtaining names and positions for shortcuts located on the Windows Desktop'
52.55 min.Function: 'GetRgnBox'
Function group: 'Region'
52.6 min.Example: 'Creating a clipping region from the path selected into the device context of a form'
1.12 hrs.Example: 'How to check whether the system is 32-bit or 64-bit'
Google
Advertise here!