Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Quering a waveform-audio input device
Using Path functions from Shell Lightweight Utility APIs (shlapi.dll)
How to print FoxPro form -- II
Reading and setting the priority class values for the current process and thread
Reading entries from Event logs
Dragging files from Explorer window and dropping them on FoxPro control (requires VFP9)
How to convert a bitmap file to monochrome format (1 bpp)
How to copy the image of a form to the Clipboard using Bitmap API functions
How to display Windows On-Screen Keyboard
Memory usage info for current VFP session (WinNT only)
Retrieving the name of the default printer for the current user on the local computer (Win NT/XP)
Adding user-defined items to the Control Menu of VFP form (requires VFP9)
GDI+: Color Transparency
How to enumerate sessions and processes on a specified terminal server
How to print picture stored in enhanced-format metafile (*.emf)
How to start the screen saver and how to find whether the screen saver is active
Retrieveing general information about the driver and data source associated with an ODBC connection
Bitmap Class for Visual FoxPro application
Displaying the associated icons and descriptions for files and folders
Enumerating data formats currently available on the clipboard
How to control Adobe Reader 9.0 (SDI mode) from VFP application
Peer-to-peer LAN messenger built with Mailslot API functions
Sending email messages with Simple MAPI
Setting the volume label
Quering a waveform-audio input device

User rating: 10/10 (1 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 retrieves the capabilities of an available waveform-audio input device in WAVEINCAPS structure.

#DEFINE WAVE_FORMAT_1M08  0x00000001
#DEFINE WAVE_FORMAT_1M16  0x00000004
#DEFINE WAVE_FORMAT_1S08  0x00000002
#DEFINE WAVE_FORMAT_1S16  0x00000008
#DEFINE WAVE_FORMAT_2M08  0x00000010
#DEFINE WAVE_FORMAT_2M16  0x00000040
#DEFINE WAVE_FORMAT_2S08  0x00000020
#DEFINE WAVE_FORMAT_2S16  0x00000080
#DEFINE WAVE_FORMAT_4M08  0x00000100
#DEFINE WAVE_FORMAT_4M16  0x00000400
#DEFINE WAVE_FORMAT_4S08  0x00000200
#DEFINE WAVE_FORMAT_4S16  0x00000800

DO decl

PRIVATE lnDevCount
lnDevCount = waveInGetNumDevs()

IF lnDevCount <> 0
    DO QueringDevice
*    DO OpenAndClose
* end of main

*|typedef struct { 
*|    WORD  wFormatTag;       0:2
*|    WORD  nChannels;        2:2
*|    DWORD nSamplesPerSec;   4:4
*|    DWORD nAvgBytesPerSec;  8:4
*|    WORD  nBlockAlign;     12:2
*|    WORD  wBitsPerSample;  14:2
*|    WORD  cbSize;          16:2
*|} WAVEFORMATEX; total 18 bytes

    LOCAL lnDeviceID, hDevice, lcBuf, lnResult, lnDevice
    STORE 0 TO lnDeviceID, hDevice

    * format of waveform-audio data
    LOCAL nChannels, nSamplesPerSec, wBitsPerSample,;
        nAvgBytesPerSec, nBlockAlign

    nChannels = 1
    nSamplesPerSec = 8000
    wBitsPerSample = 8
    nBlockAlign = nChannels * wBitsPerSample/8
    nAvgBytesPerSec = nSamplesPerSec * nBlockAlign

    * assembling data into WAVEFORMATEX structure
    lcBuf = num2word(WAVE_FORMAT_PCM) +;
        num2word(nChannels) + num2dword(nSamplesPerSec) +;
        num2dword(nAvgBytesPerSec) + num2word(nBlockAlign) +;
        num2word(wBitsPerSample) + num2word(0)

    lnResult = waveInOpen(@hDevice, lnDeviceID, @lcBuf, 0,0,0)
        ? "Error opening device: ", lnResult
        ? GetWaveError(lnResult)

    = MessageB("Device handle: " +;
        LTRIM(STR(hDevice)) + Chr(13)+Chr(13) +;
        "Use this handle to identify the device    " + Chr(13) +;
        "when calling other waveform-audio input functions.   ",;
        64, " Waveform-audio input device")

    = waveInReset(hDevice)
    = waveInClose(hDevice)

PROCEDURE QueringDevice
*|typedef struct { 
*|    WORD      wMid;                  0:2
*|    WORD      wPid;                  2:2
*|    MMVERSION vDriverVersion;        4:4
*|    TCHAR     szPname[MAXPNAMELEN];  8:32
*|    DWORD     dwFormats;            40:4
*|    WORD      wChannels;            44:2
*|    WORD      wReserved1;           46:2


    * quering first available device
    LOCAL lcBuf, lnResult, lcName, lnCount
    lcBuf = Repli(Chr(0), 128)
    lnResult = waveInGetDevCaps(0, @lcBuf, Len(lcBuf))

        ? "Error:", lnResult  && MMSYSERR_ value

    CREATE CURSOR cs (pname C(30), pvalue C(50))

    = AddParam("Number of devices", LTRIM(STR(lnDevCount)))
    = AddParam("Manufacturer ID:", LTRIM(STR(buf2word(SUBSTR(lcBuf, 1,2)))))
    = AddParam("Product ID:", LTRIM(STR(buf2word(SUBSTR(lcBuf, 3,2)))))
    = AddParam("Version number:", LTRIM(STR(buf2dword(SUBSTR(lcBuf, 5,4)))))

    lcName = SUBSTR(lcBuf, 9, MAXPNAMELEN)
    lcName = SUBSTR(lcName, 1, AT(Chr(0),lcName)-1)
    = AddParam("Product name:", lcName)

    = AddParam("Mono(1) or Stereo(2):", LTRIM(STR(buf2word(SUBSTR(lcBuf, 45,2)))))

    * a combination of WAVE_FORMAT_ constants
    nFormats = buf2dword(SUBSTR(lcBuf, 41,4))
    = AddParam("Supported formats:", LTRIM(STR(nFormats)))

    = TestFmt(nFormats, "WAVE_FORMAT_1M08", WAVE_FORMAT_1M08)
    = TestFmt(nFormats, "WAVE_FORMAT_1M16", WAVE_FORMAT_1M16)
    = TestFmt(nFormats, "WAVE_FORMAT_1S08", WAVE_FORMAT_1S08)
    = TestFmt(nFormats, "WAVE_FORMAT_1S16", WAVE_FORMAT_1S16)
    = TestFmt(nFormats, "WAVE_FORMAT_2M08", WAVE_FORMAT_2M08)
    = TestFmt(nFormats, "WAVE_FORMAT_2M16", WAVE_FORMAT_2M16)
    = TestFmt(nFormats, "WAVE_FORMAT_2S08", WAVE_FORMAT_2S08)
    = TestFmt(nFormats, "WAVE_FORMAT_2S16", WAVE_FORMAT_2S16)
    = TestFmt(nFormats, "WAVE_FORMAT_4M08", WAVE_FORMAT_4M08)
    = TestFmt(nFormats, "WAVE_FORMAT_4M16", WAVE_FORMAT_4M16)
    = TestFmt(nFormats, "WAVE_FORMAT_4S08", WAVE_FORMAT_4S08)
    = TestFmt(nFormats, "WAVE_FORMAT_4S16", WAVE_FORMAT_4S16)

    GO TOP

FUNCTION GetWaveError(lnError)
    LOCAL lcBuf
    lcBuf = Repli(Chr(0), 250)
    = waveInGetErrorText(lnError, @lcBuf, Len(lcBuf))
RETURN STRTRAN(lcBuf, Chr(0),"")

PROCEDURE AddParam(cName, cValue)
    INSERT INTO cs VALUES (cName, cValue)

FUNCTION TestFmt(nFormats, cFmtName, nFormat)
    = AddParam(cFmtName, Iif(BitAnd(nFormats, nFormat)=nFormat, "1",""))

    DECLARE INTEGER waveInGetNumDevs IN winmm
    DECLARE INTEGER waveInGetDevCaps IN winmm;
        INTEGER uDeviceID, STRING @pwic, LONG cbwic      

    DECLARE INTEGER waveInOpen IN winmm;
        INTEGER @phwi, INTEGER uDeviceID, STRING @pwfx,;
        INTEGER dwCallback, INTEGER dwCallbackInstance,;
        LONG fdwOpen

    DECLARE INTEGER waveInGetErrorText IN winmm;
        INTEGER mmrError, STRING @pszText, LONG cchText

    DECLARE INTEGER waveInReset IN winmm INTEGER hwi
    DECLARE INTEGER waveInClose IN winmm INTEGER hwi

FUNCTION  buf2dword (lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
    BitLShift(Asc(SUBSTR(lcBuffer, 2,1)),  8) +;
    BitLShift(Asc(SUBSTR(lcBuffer, 3,1)), 16) +;
    BitLShift(Asc(SUBSTR(lcBuffer, 4,1)), 24)

FUNCTION buf2word (lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
       Asc(SUBSTR(lcBuffer, 2,1)) * 256

FUNCTION  num2dword (lnValue)
#DEFINE m0       256
#DEFINE m1     65536
#DEFINE m2  16777216
    LOCAL b0, b1, b2, b3
    b3 = Int(lnValue/m2)
    b2 = Int((lnValue - b3*m2)/m1)
    b1 = Int((lnValue - b3*m2 - b2*m1)/m0)
    b0 = Mod(lnValue, m0)
RETURN Chr(b0)+Chr(b1)+Chr(b2)+Chr(b3)

FUNCTION num2word (lnValue)
RETURN Chr(MOD(m.lnValue,256)) + CHR(INT(m.lnValue/256))

User rating: 10/10 (1 votes)
Rate this code sample:
  • ~
5909 bytes  
Created: 2003-01-08 10:42:27  
Modified: 2009-01-03 15:26:33  
Visits in 7 days: 123  
Listed functions:
Printer friendly API declarations
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian offers instant, free translations of text or web pages.
User Contributed Notes:
There are no notes on this subject.

Copyright 2001-2017 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.6.38), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (
11 sec.Examples
22 sec.Function: 'midiOutShortMsg'
Function group: 'Windows Multimedia'
36 sec.
51 sec.Function: 'FindNextVolumeMountPoint'
Function group: 'File System'
1.08 min.Articles
1.33 min.Function: 'CeRemoveDirectory'
Function group: 'Remote Application Programming (RAPI)'
1.58 min.Function: 'FlashWindow'
Function group: 'Error Handling'
1.8 min.Banners
2 min.Function: 'SetWindowLong'
2.2 min.Function: 'FtpSetCurrentDirectory'
Advertise here!