home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
mmtest.zip
/
MMTEST.C
< prev
next >
Wrap
Text File
|
1994-04-22
|
9KB
|
247 lines
// mmtest.cpp -- test program for multimedia
// Copyright (C) 1994 Joel Barnum, Descriptor Systems
//
// Compuserve: 70047,442
// Internet: jbarnum@ins.infonet.net
// This program attempts to load the MMPM/2 DLL and
// if successful, run-time links to a couple of APIs.
// If not successful, then multimedia services are
// not available.
//
// To test the program, compile and link it with
// the provided makefile. Copy a WAV file to the
// current directory and name it TEST.WAV. Then run
// the program and choose Play from the Sound menu.
// Note: the program should also ensure that there
// is a wave audio device installed, but I haven't
// yet figured out how to do that!
#define INCL_WIN
#define INCL_GPI
#define INCL_DOS
#include <os2.h>
#include <os2me.h>
#include <string.h>
#include <stdlib.h>
#include "mmtest.h"
// global variables
// define pointers to APIs that we'll call
ULONG (* APIENTRY pmciSendString) (PSZ pszCommandBuf,
PSZ pszReturnString,
USHORT wReturnLength,
HWND hwndCallBack,
USHORT usUserParm );
ULONG (* APIENTRY pmciGetErrorString)(ULONG ulError,
PSZ pszBuffer,
USHORT usLength);
HAB hab;
// Internal function prototypes
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg
, MPARAM mp1, MPARAM mp2 );
void error ( ULONG dwError, int nLine );
int main ( int argc, char *argv[] )
{
HMQ hmq; // Message queue handle
HWND hwndFrame; // Frame window handle
HWND hwndClient; // Client window handle
QMSG qmsg; // Message from queue
ULONG flCreate; // Window creation flags
BOOL fSuccess; // return from API
hab = WinInitialize ( 0 );
hmq = WinCreateMsgQueue ( hab, 0 );
fSuccess = WinRegisterClass ( hab, "mmtest"
, MyWindowProc, 0, 0 );
flCreate = FCF_SYSMENU | FCF_SIZEBORDER | FCF_TITLEBAR |
FCF_MINMAX | FCF_SHELLPOSITION | FCF_TASKLIST |
FCF_ICON | FCF_MENU;
hwndFrame = WinCreateStdWindow ( HWND_DESKTOP, WS_VISIBLE
, &flCreate, "mmtest"
, "Test MMPM/2", 0L, 0, IDF_MAIN
, &hwndClient );
while ( WinGetMsg ( hab, &qmsg, NULLHANDLE, 0, 0 ) )
WinDispatchMsg ( hab, &qmsg );
fSuccess = WinDestroyWindow ( hwndFrame );
fSuccess = WinDestroyMsgQueue ( hmq );
fSuccess = WinTerminate ( hab );
return 0;
}
//************************************************************
MRESULT EXPENTRY MyWindowProc ( HWND hwnd, ULONG msg
, MPARAM mp1, MPARAM mp2 )
{
switch( msg )
{
case WM_CREATE:
{
APIRET rc;
HWND hwndMenu;
CHAR ach[255]; // for DosLoadModule
HMODULE hmodMMPM; // multimedia PM DLL
// attempt to load the MMPM DLL
rc = DosLoadModule ( ach, sizeof ( ach )
, "MDM", &hmodMMPM );
if ( rc != 0 )
{
WinMessageBox ( HWND_DESKTOP
, hwnd
, "Multimedia PM not installed.\n"
"No sound will be played"
, "Warning"
, 0
, MB_OK | MB_WARNING | MB_MOVEABLE );
// disable menu item
hwndMenu = WinWindowFromID (
WinQueryWindow ( hwnd, QW_PARENT ), FID_MENU );
WinEnableMenuItem ( hwndMenu, IDM_PLAY, FALSE );
}
else
{
// find MMPM API address
rc = DosQueryProcAddr ( hmodMMPM, 0, "mciSendString"
, (PFN *)&pmciSendString );
if ( rc != 0 )
{
WinMessageBox ( HWND_DESKTOP
, hwnd
, "Unable to query proc addr.\n"
"No sound will be played"
, "Warning"
, 0
, MB_OK | MB_WARNING | MB_MOVEABLE );
// disable menu item
hwndMenu = WinWindowFromID (
WinQueryWindow ( hwnd, QW_PARENT ), FID_MENU );
WinEnableMenuItem ( hwndMenu, IDM_PLAY, FALSE );
}
// find MMPM API address
rc = DosQueryProcAddr ( hmodMMPM, 0, "mciGetErrorString"
, (PFN *)&pmciGetErrorString );
if ( rc != 0 )
{
WinMessageBox ( HWND_DESKTOP
, hwnd
, "Unable to query proc addr.\n"
"No sound will be played"
, "Warning"
, 0
, MB_OK | MB_WARNING | MB_MOVEABLE );
// disable menu item
hwndMenu = WinWindowFromID (
WinQueryWindow ( hwnd, QW_PARENT ), FID_MENU );
WinEnableMenuItem ( hwndMenu, IDM_PLAY, FALSE );
}
}
}
return 0;
case WM_COMMAND:
switch ( SHORT1FROMMP (mp1) )
{
ULONG dwError; // return from API
case IDM_PLAY:
// open the TEST.WAV file
dwError = pmciSendString (
"open test.wav alias test shareable wait"
, NULL
, 0
, 0
, 0 );
if ( dwError != 0 )
error ( dwError, __LINE__ - 2 );
// play it
dwError = pmciSendString (
"play test from 1 notify", NULL, 0, hwnd, 0 );
if ( dwError != 0 )
error ( dwError, __LINE__ - 2 );
break;
}
return 0L;
case MM_MCINOTIFY:
// MMPM notifies us when the play is finished or
// if there was an error
if ( SHORT1FROMMP (mp1) == MCI_NOTIFY_SUCCESSFUL )
{
ULONG dwError;
dwError = pmciSendString (
"close test wait", NULL, 0, 0, 0 );
if ( dwError != 0 )
error ( dwError, __LINE__ - 2 );
else
WinMessageBox ( HWND_DESKTOP, hwnd, "All done"
, "Info", 0, MB_OK | MB_MOVEABLE );
}
else
{
char sz[255]; // temp string
switch ( SHORT1FROMMP ( mp1 ) )
{
case MCI_NOTIFY_ABORTED:
strcpy ( sz, "MCI_NOTIFY_ABORTED" );
break;
default:
strcpy ( sz, "Unkown error" );
break;
}
WinMessageBox ( HWND_DESKTOP, hwnd, sz, "Info", 0, MB_OK );
}
return 0L;
case WM_CLOSE:
WinPostMsg ( hwnd, WM_QUIT, 0L, 0L );
return (MRESULT)NULL;
case WM_PAINT:
{
HPS hps = WinBeginPaint ( hwnd, NULLHANDLE, NULL );
GpiErase ( hps );
WinEndPaint ( hps );
}
return (MRESULT)NULL;
default:
return WinDefWindowProc ( hwnd, msg, mp1, mp2 );
}
}
//******************************************************************
void error ( ULONG dwError, int nLine )
{
char szErr[255]; // error string
char szTitle[255]; // title string
char sz2[25]; // temp string
pmciGetErrorString ( dwError, szErr, sizeof (szErr) );
strcpy ( szTitle, "Error in line " );
_itoa ( nLine, sz2, 10 );
strcat ( szTitle, sz2 );
WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP, szErr, szTitle, 0, MB_OK );
}