Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Adding and deleting Scheduled Tasks using NetScheduleJob API functions
Custom GDI+ class
Converting Unicode data from the Clipboard to a character string using a given code page
Winsock: sending email messages (SMTP, port 25)
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Enumerating data formats currently available on the clipboard
Custom FTP Class for Visual FoxPro application
Detecting changes in connections to removable drives (VFP9)
How to download a file from the FTP server using FtpGetFile
How to activate Windows Calculator
Splash Screen for the VFP application
Custom HttpRequest class (WinINet)
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
Mapping and disconnecting network drives
Establishing connection using the SQLDriverConnect
Using Font and Text functions
Custom HttpRequest class (WinHTTP)
How to convert a bitmap file to monochrome format (1 bpp)
Displaying bitmap using the AlphaBlend function
Using EnumPrinters function to enumerate locally installed printers
Using WM_COPYDATA for interprocess communication (VFP9)
How to make a VFP form fading out when released (GDI+ version)
How to play AVI file on the _screen
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: 45  
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 (23.22.212.158)
4.5 hrs.Example: 'GDI+: Color Transparency'
8.93 hrs.Example: 'Minimizing all running applications'
9.18 hrs.Example: 'Establishing connection using the SQLDriverConnect'
9.54 hrs.Example: 'Creating a mailslot'
 Example: 'Using InternetGoOnline function'
14.28 hrs.Function: 'PeekMessage'
 Example: 'How to Start a Process as Another User (NT/XP/2K)'
17.74 hrs.Example: 'Obtaining names and positions for shortcuts located on the Windows Desktop'
18.79 hrs.Example: 'Using Font and Text functions'
 Function: 'PathBuildRoot'
Function group: 'Shell Lightweight Utility APIs -- Path Functions'
Google
Advertise here!