This program is a translation of TESTMCI.C -- MCI Command String Tester © Charles Petzold, 1998, described and analysed in Chapter 22 of the book Programming Windows, 5th Edition.
Back in the early days of Windows multimedia, the software development kit included a C program called MCITEST that allowed programmers to interactively type in MCI commands and learn how they worked. This program, at least in its C version, has apparently disappeared. So, I've recreated it as the TESTMCI. The user interface is based on the old MCITEST program but not the actual code, although I can't believe it was much different. (Petzold).
' ========================================================================================
' TESTMCI.BAS
' This program is a translation/adaptation of TESTMCI.C -- MCI Command String Tester
' © Charles Petzold, 1998, described and analysed in Chapter 22 of the book Programming
' Windows, 5th Edition.
' Back in the early days of Windows multimedia, the software development kit included a C
' program called MCITEST that allowed programmers to interactively type in MCI commands
' and learn how they worked. This program, at least in its C version, has apparently
' disappeared. So, I've recreated it as the TESTMCI. The user interface is based on the
' old MCITEST program but not the actual code, although I can't believe it was much
' different. (Petzold).
' ========================================================================================
#COMPILE EXE
#DIM ALL
#INCLUDE ONCE "windows.inc"
#RESOURCE RES, "testmci.res"
%ID_TIMER = 1
%IDC_MAIN_EDIT = 1000
%IDC_NOTIFY_MESSAGE = 1005
%IDC_NOTIFY_ID = 1006
%IDC_NOTIFY_SUCCESSFUL = 1007
%IDC_NOTIFY_SUPERSEDED = 1008
%IDC_NOTIFY_ABORTED = 1009
%IDC_NOTIFY_FAILURE = 1010
%IDC_SIGNAL_MESSAGE = 1011
%IDC_SIGNAL_ID = 1012
%IDC_SIGNAL_PARAM = 1013
%IDC_RETURN_STRING = 1014
%IDC_ERROR_STRING = 1015
%IDC_DEVICES = 1016
' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, _
BYVAL pszCmdLine AS WSTRINGZ PTR, BYVAL iCmdShow AS LONG) AS LONG
LOCAL szAppName AS ASCIIZ * 256
szAppName = "TestMci"
IF DialogBox(hInstance, szAppName, %NULL, CODEPTR(DlgProc)) = -1 THEN
MessageBox %NULL, "DialogBox failed", szAppName, %MB_ICONERROR
END IF
END FUNCTION
' ========================================================================================
' ========================================================================================
' Main dialog callback.
' ========================================================================================
FUNCTION DlgProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
STATIC hwndEdit AS DWORD
LOCAL iCharBeg AS LONG
LOCAL iCharEnd AS LONG
LOCAL iLineBeg AS LONG
LOCAL iLineEnd AS LONG
LOCAL iChar AS LONG
LOCAL iLine AS LONG
LOCAL iLength AS LONG
LOCAL mcierror AS LONG
LOCAL rc AS RECT
LOCAL szCommand AS ASCIIZ * 1024
LOCAL szReturn AS ASCIIZ * 1024
LOCAL szError AS ASCIIZ * 1024
LOCAL szBuffer AS ASCIIZ * 32
SELECT CASE uMsg
CASE %WM_INITDIALOG
' Center the window on screen
GetWindowRect hwnd, rc
SetWindowPos hwnd, %NULL, _
(GetSystemMetrics(%SM_CXSCREEN) - rc.nRight + rc.nLeft) / 2, _
(GetSystemMetrics(%SM_CYSCREEN) - rc.nBottom + rc.nTop) / 2, _
0, 0, %SWP_NOZORDER OR %SWP_NOSIZE
hwndEdit = GetDlgItem(hwnd, %IDC_MAIN_EDIT)
SetFocus hwndEdit
FUNCTION = %FALSE
EXIT FUNCTION
CASE %WM_COMMAND
SELECT CASE LO(WORD, wParam)
CASE %IDOK
' Find the line numbers corresponding to the selection
SendMessage hwndEdit, %EM_GETSEL, VARPTR(iCharBeg), VARPTR(iCharEnd)
iLineBeg = SendMessage(hwndEdit, %EM_LINEFROMCHAR, iCharBeg, 0)
iLineEnd = SendMessage(hwndEdit, %EM_LINEFROMCHAR, iCharEnd, 0)
' Loop through all the lines
FOR iLine = iLineBeg TO iLineEnd
' Get the line and terminate it; ignore if blank
szCommand = SPACE$(SIZEOF(szCommand))
iLength = SendMessage(hwndEdit, %EM_GETLINE, iLine, VARPTR(szCommand))
IF iLength = 0 THEN ITERATE FOR
szCommand = LEFT$(szCommand, iLength)
' Send the MCI command
mcierror = mciSendString (szCommand, szReturn, SIZEOF(szReturn), hwnd)
' Set the Return String field
SetDlgItemText hwnd, %IDC_RETURN_STRING, szReturn
' Set the Error String field (even if no error)
mciGetErrorString mcierror, szError, SIZEOF(szError)
SetDlgItemText hwnd, %IDC_ERROR_STRING, szError
NEXT
' Send the caret to the end of the last selected line
iChar = SendMessage(hwndEdit, %EM_LINEINDEX, iLineEnd, 0)
iChar = iChar + SendMessage(hwndEdit, %EM_LINELENGTH, iCharEnd, 0)
SendMessage hwndEdit, %EM_SETSEL, iChar, iChar
' Insert a carriage return/line feed combination
szBuffer = $CRLF
SendMessage hwndEdit, %EM_REPLACESEL, %FALSE, VARPTR(szBuffer)
SetFocus hwndEdit
FUNCTION = %TRUE
EXIT FUNCTION
CASE %IDCANCEL
EndDialog hwnd, 0
FUNCTION = %TRUE
EXIT FUNCTION
CASE %IDC_MAIN_EDIT
IF HI(WORD, wParam) = %EN_ERRSPACE THEN
MessageBox hwnd, "Error control out of space.", _
"TestMci", %MB_OK OR %MB_ICONINFORMATION
FUNCTION = %TRUE
EXIT FUNCTION
END IF
END SELECT
CASE %MM_MCINOTIFY
EnableWindow GetDlgItem(hwnd, %IDC_NOTIFY_MESSAGE), %TRUE
wsprintf szBuffer, "Device ID = %i", BYVAL lParam
SetDlgItemText hwnd, %IDC_NOTIFY_ID, szBuffer
EnableWindow GetDlgItem(hwnd, %IDC_NOTIFY_ID), %TRUE
EnableWindow GetDlgItem(hwnd, %IDC_NOTIFY_SUCCESSFUL), wParam AND %MCI_NOTIFY_SUCCESSFUL
EnableWindow GetDlgItem(hwnd, %IDC_NOTIFY_SUPERSEDED), wParam AND %MCI_NOTIFY_SUPERSEDED
EnableWindow GetDlgItem(hwnd, %IDC_NOTIFY_ABORTED), wParam AND %MCI_NOTIFY_ABORTED
EnableWindow GetDlgItem(hwnd, %IDC_NOTIFY_FAILURE), wParam AND %MCI_NOTIFY_FAILURE
SetTimer hwnd, %ID_TIMER, 5000, %NULL
FUNCTION = %TRUE
EXIT FUNCTION
CASE %WM_TIMER
KillTimer hwnd, %ID_TIMER
EnableWindow GetDlgItem(hwnd, %IDC_NOTIFY_MESSAGE), %FALSE
EnableWindow GetDlgItem(hwnd, %IDC_NOTIFY_ID), %FALSE
EnableWindow GetDlgItem(hwnd, %IDC_NOTIFY_SUCCESSFUL), %FALSE
EnableWindow GetDlgItem(hwnd, %IDC_NOTIFY_SUPERSEDED), %FALSE
EnableWindow GetDlgItem(hwnd, %IDC_NOTIFY_ABORTED), %FALSE
EnableWindow GetDlgItem(hwnd, %IDC_NOTIFY_FAILURE), %FALSE
FUNCTION = %TRUE
EXIT FUNCTION
CASE %WM_SYSCOMMAND
SELECT CASE LO(WORD, wParam)
CASE %SC_CLOSE
EndDialog hWnd, 0
FUNCTION = %TRUE
EXIT FUNCTION
END SELECT
END SELECT
END FUNCTION
' ========================================================================================
TESTMCI.RC
#define WS_MINIMIZEBOX 0x00020000L
#define WS_VISIBLE 0x10000000L
#define WS_CAPTION 0x00C00000L /* WS_BORDER | WS_DLGFRAME */
#define WS_SYSMENU 0x00080000L
#define ES_MULTILINE 0x0004L
#define ES_AUTOHSCROLL 0x0080L
#define WS_VSCROLL 0x00200000L
#define ES_AUTOVSCROLL 0x0040L
#define ES_READONLY 0x0800L
#define WS_TABSTOP 0x00010000L
#define WS_GROUP 0x00020000L
#define WS_DISABLED 0x08000000L
#define IDOK 1
#define IDCANCEL 2
#define IDC_MAIN_EDIT 1000
#define IDC_NOTIFY_MESSAGE 1005
#define IDC_NOTIFY_ID 1006
#define IDC_NOTIFY_SUCCESSFUL 1007
#define IDC_NOTIFY_SUPERSEDED 1008
#define IDC_NOTIFY_ABORTED 1009
#define IDC_NOTIFY_FAILURE 1010
#define IDC_SIGNAL_MESSAGE 1011
#define IDC_SIGNAL_ID 1012
#define IDC_SIGNAL_PARAM 1013
#define IDC_RETURN_STRING 1014
#define IDC_ERROR_STRING 1015
#define IDC_DEVICES 1016
#define IDC_STATIC -1
/////////////////////////////////////////////////////////////////////////////
// Dialog
TESTMCI DIALOG DISCARDABLE 0, 0, 270, 276
STYLE WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "MCI Tester"
FONT 8, "MS Sans Serif"
BEGIN
EDITTEXT IDC_MAIN_EDIT,8,8,254,100,ES_MULTILINE | ES_AUTOHSCROLL |
WS_VSCROLL
LTEXT "Return String:",IDC_STATIC,8,114,60,8
EDITTEXT IDC_RETURN_STRING,8,126,120,50,ES_MULTILINE |
ES_AUTOVSCROLL | ES_READONLY | WS_GROUP | NOT WS_TABSTOP
LTEXT "Error String:",IDC_STATIC,142,114,60,8
EDITTEXT IDC_ERROR_STRING,142,126,120,50,ES_MULTILINE |
ES_AUTOVSCROLL | ES_READONLY | NOT WS_TABSTOP
GROUPBOX "MM_MCINOTIFY Message",IDC_STATIC,9,186,254,58
LTEXT "",IDC_NOTIFY_ID,26,198,100,8
LTEXT "MCI_NOTIFY_SUCCESSFUL",IDC_NOTIFY_SUCCESSFUL,26,212,100,
8,WS_DISABLED
LTEXT "MCI_NOTIFY_SUPERSEDED",IDC_NOTIFY_SUPERSEDED,26,226,100,
8,WS_DISABLED
LTEXT "MCI_NOTIFY_ABORTED",IDC_NOTIFY_ABORTED,144,212,100,8,
WS_DISABLED
LTEXT "MCI_NOTIFY_FAILURE",IDC_NOTIFY_FAILURE,144,226,100,8,
WS_DISABLED
DEFPUSHBUTTON "OK",IDOK,57,255,50,14
PUSHBUTTON "Close",IDCANCEL,162,255,50,14
END