|
|
1.1 root 1: /* mcitest.c - WinMain(), main dialog box and support code for MCITest.
2: *
3: * MCITest is a Windows with Multimedia sample application illustrating
4: * the use of the Media Control Interface (MCI). MCITest puts up a dialog
5: * box allowing you to enter and execute MCI string commands.
6: *
7: * (C) Copyright Microsoft Corp. 1991, 1992. All rights reserved.
8: *
9: * You have a royalty-free right to use, modify, reproduce and
10: * distribute the Sample Files (and/or any modified version) in
11: * any way you find useful, provided that you agree that
12: * Microsoft has no warranty obligations or liability for any
13: * Sample Application Files which are modified.
14: */
15:
16: /*----------------------------------------------------------------------------*\
17: | mcitest.c - A testbed for MCI |
18: | |
19: | |
20: | History: |
21: | 01/01/88 toddla Created |
22: | 03/01/90 davidle Modified quick app into MCI testbed |
23: | 09/17/90 t-mikemc Added Notification box with 3 notification types |
24: | 11/02/90 w-dougb Commented & formatted the code to look pretty |
25: | 05/29/91 NigelT ported to Win32
26: | 02/05/92 SteveDav Merged latest Win 3.1 stuff
27: | |
28: \*----------------------------------------------------------------------------*/
29:
30: /*----------------------------------------------------------------------------*\
31: | |
32: | i n c l u d e f i l e s |
33: | |
34: \*----------------------------------------------------------------------------*/
35:
36: #include <stdio.h>
1.1.1.2 ! root 37: #include <stdlib.h>
1.1 root 38: #include <string.h>
39: #include <windows.h>
40: #include "mcitest.h"
41: #include "mcimain.h"
42: #include "edit.h"
1.1.1.2 ! root 43: #include "commdlg.h"
1.1 root 44:
45:
46: /*----------------------------------------------------------------------------*\
47: | |
48: | c o n s t a n t a n d m a c r o d e f i n i t i o n s |
49: | |
50: \*----------------------------------------------------------------------------*/
51:
52: #define BUFFER_LENGTH 256
53: #define SLASH(c) ((c) == '/' || (c) == '\\')
54:
55:
56: /*----------------------------------------------------------------------------*\
57: | |
58: | g l o b a l v a r i a b l e s |
59: | |
60: \*----------------------------------------------------------------------------*/
61: #ifndef STATICDT
62: #if DBG
1.1.1.2 ! root 63: #define STATICDT
1.1 root 64: #else
1.1.1.2 ! root 65: #define STATICDT static
1.1 root 66: #endif
67: #endif
68:
69: STATICDT int nLastNumberOfDevices = 0;
70: STATICDT HANDLE hAccTable;
71: STATICDT HANDLE hInstApp;
72: HWND hwndMainDlg = 0;
73: STATICDT HWND hwndEdit = 0;
74: STATICDT HWND hwndDevices = 0;
1.1.1.2 ! root 75: STATICDT TCHAR aszMciFile[BUFFER_LENGTH] = TEXT("");
! 76: STATICDT TCHAR aszBuffer[BUFFER_LENGTH];
! 77: STATICDT TCHAR aszExt[] = TEXT("*.mci");
! 78: TCHAR aszAppName[] = TEXT("MCITest");
! 79: STATICDT TCHAR aszMainTextFormat[] = TEXT("%s - %s");
! 80: STATICDT TCHAR aszDeviceTextFormat[] = TEXT("Open MCI Devices(count=%d)");
! 81: STATICDT TCHAR aszNULL[] = TEXT("");
! 82: STATICDT TCHAR aszTRUE[] = TEXT("TRUE");
! 83: STATICDT TCHAR aszFALSE[] = TEXT("FALSE");
! 84: STATICDT TCHAR aszEOL[] = TEXT("\r\n");
! 85: STATICDT TCHAR aszOpenFileTitle[] = TEXT("Open MCITest File");
! 86: STATICDT TCHAR aszSaveFileTitle[] = TEXT("Save MCITest File");
! 87: STATICDT TCHAR aszSaveFileControl[] = TEXT("Save File &Name");
! 88: STATICDT TCHAR aszProfileSection[] = TEXT("extensions");
! 89: STATICDT TCHAR aszProfileKey[] = TEXT("mcs");
! 90: STATICDT TCHAR aszProfileSetting[] = TEXT("mcitest.exe ^.mcs");
! 91: STATICDT TCHAR aszMciTester[] = TEXT("MciTester");
1.1 root 92:
93: /*----------------------------------------------------------------------------*\
94: | |
95: | f u n c t i o n d e f i n i t i o n s |
96: | |
97: \*----------------------------------------------------------------------------*/
98:
99: BOOL mcitester(HWND hwnd, UINT Msg, LONG wParam, LONG lParam);
1.1.1.2 ! root 100: PTSTR FileName(PTSTR szPath);
1.1 root 101: STATICFN void update_device_list(void);
1.1.1.2 ! root 102: DWORD sendstring(HWND hwndDlg, PTSTR strBuffer);
1.1 root 103: void execute( HWND hwndDlg, BOOL fStep);
1.1.1.2 ! root 104: void OpenMciFile( HWND hwndDlg, LPTSTR szFile);
1.1 root 105: BOOL AppInit(int argc, char *argv[]);
106: BOOL ErrDlgFunc( HWND hwndDlg, UINT Msg, LONG w, LONG l );
107: void create_device_list(void);
108: STATICFN BOOL devices(HWND hwndDlg, UINT Msg, LONG wParam, LONG lParam);
1.1.1.2 ! root 109: STATICFN void ProcessInternalCommand(HWND hDlg, LPTSTR aszBuffer);
1.1 root 110:
111: /*----------------------------------------------------------------------------*\
112: | AboutDlgProc( hwndDlg, Message, wParam, lParam ) |
113: | |
114: | Description: |
115: | This function handles messages belonging to the "About" dialog box. |
116: | The only message that it looks for is WM_COMMAND, indicating the user |
117: | has pressed the "OK" button. When this happens, it takes down |
118: | the dialog box. |
119: | |
120: | Arguments: |
121: | hwndDlg window handle of the about dialog window |
122: | Message message number |
123: | wParam message-dependent parameter |
124: | lParam message-dependent parameter |
125: | |
126: | Returns: |
127: | TRUE if the message has been processed, else FALSE |
128: | |
129: \*----------------------------------------------------------------------------*/
130:
131: BOOL AboutDlgProc(
132: HWND hwndDlg,
133: UINT Msg,
134: LONG wParam,
135: LONG lParam)
136: {
1.1.1.2 ! root 137: dprintf4((TEXT("AboutDlgProc")));
1.1 root 138: switch (Msg) {
139: case WM_COMMAND:
140:
141: if (LOWORD(wParam) == IDOK) {
142: EndDialog(hwndDlg,TRUE);
143: }
144: break;
145:
146: case WM_INITDIALOG:
147: return TRUE;
148:
149: }
150:
151: return FALSE;
152: }
153:
154: /*----------------------------------------------------------------------------*\
155: | FileName(szPath) |
156: | |
157: | Description: |
158: | This function takes the full path\filename string specified in <szPath>|
159: | and returns a pointer to the first character of the filename in the |
160: | same string. |
161: | |
162: | Arguments: |
163: | szPath pointer to the full path\filename string |
164: | |
165: | Returns: |
166: | a pointer to the first character of the filename in the same string |
167: | |
168: \*----------------------------------------------------------------------------*/
169:
1.1.1.2 ! root 170: PTSTR FileName(
! 171: PTSTR szPath)
1.1 root 172: {
1.1.1.2 ! root 173: PTSTR szCurrent; /* temporary pointer to the string */
1.1 root 174:
175: /* Scan to the end of the string */
176:
177: for (szCurrent = szPath; *szCurrent; szCurrent++)
178: {} ;
179:
180: /*
181: * Now start scanning back towards the beginning of the string until
182: * a slash (\) character, colon, or start of the string is encountered.
183: */
184:
185: for (; szCurrent >= szPath
1.1.1.2 ! root 186: && !SLASH(*szCurrent)
! 187: && *szCurrent != ':'
! 188: ; szCurrent--)
1.1 root 189: {} ;
190:
1.1.1.2 ! root 191: /* This should be done by calling a Win 32 function, e.g. GetFullPathName
! 192: */
1.1 root 193:
194: /* Now pointing to the char before the first char in the filename.
195: */
196: return ++szCurrent;
197: }
198:
199: /*----------------------------------------------------------------------------*\
200: | OpenMciFile( hwndDlg, szFile ) |
201: | |
202: | Description: |
203: | This function opens the MCI file specified by <szFile> and updates the |
204: | main window caption to display this file name along with the app name. |
205: | |
206: | Arguments: |
207: | hwndDlg window handle of the main dialog window |
208: | szFile pointer to the string containing the filename to be |
209: | opened |
210: | Returns: |
211: | void |
212: | |
213: \*----------------------------------------------------------------------------*/
214:
215: void OpenMciFile(
216: HWND hwndDlg,
1.1.1.2 ! root 217: LPTSTR lszFile)
1.1 root 218: {
1.1.1.2 ! root 219: dprintf2((TEXT("OpenMciFile: %s"), lszFile));
1.1 root 220:
221: if (EditOpenFile(hwndEdit, lszFile)) {
222:
223: strcpy(aszMciFile, lszFile);
1.1.1.2 ! root 224: wsprintf(aszBuffer, aszMainTextFormat, (LPTSTR)aszAppName,
! 225: (LPTSTR)FileName(aszMciFile));
! 226: dprintf3((TEXT("Set caption: %s"), aszBuffer));
1.1 root 227: SetWindowText(hwndDlg, aszBuffer);
228: }
229: }
230:
231: /*----------------------------------------------------------------------------*\
232: | get_number_of_devices() |
233: | |
234: | Description: |
235: | This function sends a command to MCI querying it as to how many |
236: | are currently open in the system. It returns the value provided by MCI.|
237: | |
238: | Arguments: |
239: | none |
240: | |
241: | Returns: |
242: | The number of MCI devices currently open, or 0 if an error occurred. |
243: | |
244: \*----------------------------------------------------------------------------*/
245:
246: int get_number_of_devices(
247: void)
248: {
249: MCI_SYSINFO_PARMS sysinfo; /* Parameter structure used for getting
250: information about the MCI devices in
251: the system */
252: DWORD dwDevices; /* count of open devices */
253:
254: /*
255: * Set things up so that MCI puts the number of open devices directly
256: * into <dwDevices>.
257: */
258:
1.1.1.2 ! root 259: sysinfo.lpstrReturn = (LPTSTR)(LPDWORD)&dwDevices;
1.1 root 260: sysinfo.dwRetSize = sizeof(dwDevices);
261:
262: /*
263: * Send MCI a command querying all devices in the system to see if they
264: * are open. If the command was successful, return the number provided by
265: * MCI. Otherwise, return 0.
266: *
267: */
268:
269: if (mciSendCommand (MCI_ALL_DEVICE_ID,
270: MCI_SYSINFO,
271: (MCI_SYSINFO_OPEN | MCI_SYSINFO_QUANTITY),
272: (DWORD)(LPMCI_SYSINFO_PARMS)&sysinfo) != 0)
273: return 0;
274: else
275: return (int)dwDevices;
276: }
277:
278:
279: /*----------------------------------------------------------------------------*\
280: | update_device_list() |
281: | |
282: | Description: |
283: | This function updates the list of devices displayed in the Devices |
284: | dialog. |
285: | |
286: | Arguments: |
287: | none |
288: | |
289: | Returns: |
290: | void |
291: | |
292: \*----------------------------------------------------------------------------*/
293:
294: STATICFN void update_device_list(
295: void)
296: {
1.1.1.2 ! root 297: TCHAR aszBuf[BUFFER_LENGTH]; /* string used for several things */
1.1 root 298: MCI_SYSINFO_PARMS sysinfo; /* Parameter structure used for getting
299: information about the devices in the
300: system */
301: HWND hwndList; /* handle to the Devices listbox window */
302: int nDevices;
303: int nCurrentDevice;
304:
305: /* If the Devices dialog is not present, then return */
306:
307: if (hwndDevices == 0) {
308: return;
309: }
310:
311: /* Find out how many devices are currently open in the system */
312:
313: nDevices = get_number_of_devices();
314:
315: /* Update the dialog caption appropriately */
316:
1.1.1.2 ! root 317: wsprintf(aszBuf, aszDeviceTextFormat, nDevices);
! 318: SetWindowText(hwndDevices, aszBuf);
1.1 root 319:
320: /* Get a handle to the dialog's listbox, and prepare it for updating */
321:
322: hwndList = GetDlgItem (hwndDevices, ID_DEVICE_LIST);
323: SendMessage (hwndList, LB_RESETCONTENT, 0, 0L);
324:
1.1.1.2 ! root 325: if (nDevices) {
! 326: SendMessage (hwndList, WM_SETREDRAW, FALSE, 0L);
! 327: }
1.1 root 328:
329: /*
330: * Get the name of each open device in the system, one device at a time.
331: * Add each device's name to the listbox.
332: */
333:
334: for (nCurrentDevice = 1; nCurrentDevice <= nDevices; ++nCurrentDevice) {
335:
336: sysinfo.dwNumber = nCurrentDevice;
1.1.1.2 ! root 337: sysinfo.lpstrReturn = (LPTSTR)&aszBuf;
1.1 root 338: sysinfo.dwRetSize = sizeof(aszBuf);
339:
340: /* If an error is encountered, skip to the next device.
341: */
342: if (mciSendCommand(MCI_ALL_DEVICE_ID, MCI_SYSINFO,
343: MCI_SYSINFO_OPEN | MCI_SYSINFO_NAME,
344: (DWORD)(LPMCI_SYSINFO_PARMS)&sysinfo) != 0) {
345: continue;
1.1.1.2 ! root 346: }
1.1 root 347:
348: /* Redraw the list when all device names have been added.
349: */
350: if (nCurrentDevice == nDevices) {
1.1.1.2 ! root 351: /* About to add the last device - allow redrawing */
1.1 root 352: SendMessage(hwndList, WM_SETREDRAW, TRUE, 0L);
1.1.1.2 ! root 353: }
1.1 root 354:
355: /* Add the device name to the listbox.
356: */
1.1.1.2 ! root 357: SendMessage(hwndList, LB_ADDSTRING, 0, (LONG)(LPTSTR)aszBuf);
1.1 root 358: }
359:
360: /* Remember the number of open devices we found this time */
361:
362: nLastNumberOfDevices = nDevices;
363: }
364:
365: /*----------------------------------------------------------------------------*\
366: | sendstring( hwndDlg, strBuffer ) |
367: | |
368: | Description: |
369: | This function sends the string command specified in <strBuffer> to MCI |
370: | via the MCI string interface. Any message returned by MCI is displayed |
371: | in the 'MCI output' box. Any error which may have occurred is displayed|
372: | in the 'Error' box'. |
373: | |
374: | Arguments: |
375: | hwndDlg window handle of the main dialog window |
376: | strBuffer pointer to the string containing the string command to |
377: | be executed |
378: | Returns: |
379: | void |
380: | |
381: \*----------------------------------------------------------------------------*/
382:
383: DWORD sendstring(
384: HWND hwndDlg,
1.1.1.2 ! root 385: PTSTR strBuffer)
1.1 root 386: {
1.1.1.2 ! root 387: TCHAR aszReturn[BUFFER_LENGTH]; /* string containing the message
1.1 root 388: returned by MCI */
389: DWORD dwErr; /* variable containing the return
390: code from the MCI command */
1.1.1.2 ! root 391: dprintf2((TEXT("sendstring: %s"), strBuffer));
1.1 root 392:
393: /* Uncheck the notification buttons */
394:
395: CheckDlgButton (hwndDlg, ID_NOT_SUCCESS, FALSE);
396: CheckDlgButton (hwndDlg, ID_NOT_SUPER, FALSE);
397: CheckDlgButton (hwndDlg, ID_NOT_ABORT, FALSE);
398: CheckDlgButton (hwndDlg, ID_NOT_FAIL, FALSE);
399:
400: /* Send the string command to MCI */
401:
402: dwErr = mciSendString(strBuffer, aszReturn, sizeof(aszReturn), hwndDlg);
403:
404: /* Put the text message returned by MCI into the 'MCI Output' box */
405:
406: SetDlgItemText (hwndDlg, ID_OUTPUT, aszReturn);
407:
408: /*
409: * Decode the error # returned by MCI, and display the string in the
410: * 'Error' box.
411: */
412:
413: mciGetErrorString(dwErr, strBuffer, BUFFER_LENGTH);
414: SetDlgItemText(hwndDlg, ID_ERRORCODE, strBuffer);
415:
416: /* Update the internal list of currently open devices */
417:
418: update_device_list();
419: return dwErr;
420: }
421:
422:
423: /*----------------------------------------------------------------------------*\
424: | ErrDlgFunc( hwndDlg, Msg, wParam, lParam ) |
425: | |
426: | Description: |
427: | This function is the callback function for the dialog box which |
428: | occurs during the execution of a error in a loop of MCITEST commands |
429: | It displays Abort, Continue and Ignore buttons |
430: | |
431: | Arguments: |
432: | hwndDlg window handle of the error message dialog window |
433: | Msg message number |
434: | wParam message-dependent parameter |
435: | lParam message-dependent parameter |
436: | |
437: | Returns: |
438: | normal message passing return values |
439: | |
440: \*----------------------------------------------------------------------------*/
441:
442:
443: BOOL ErrDlgFunc(
444: HWND hwndDlg,
445: UINT Msg,
446: LONG wParam,
447: LONG lParam)
448: {
1.1.1.2 ! root 449: dprintf4((TEXT("ErrDlgFunc")));
1.1 root 450: switch( Msg ) {
1.1.1.2 ! root 451: case WM_INITDIALOG:
! 452: return TRUE;
! 453:
! 454:
! 455: case WM_COMMAND:
! 456: switch( LOWORD(wParam) ) { // button pushed
! 457: case IDABORT:
! 458: case IDOK:
! 459: case IDIGNORE:
! 460: EndDialog( hwndDlg, LOWORD(wParam) ); // return button ID
! 461: break;
! 462: }
! 463: break;
1.1 root 464: }
465: return( FALSE );
466: }
467:
468: /*----------------------------------------------------------------------------*\
469: | execute( hwndDlg, fStep ) |
470: | |
471: | Description: |
472: | This function executes the MCI command which is currently selected in |
473: | the edit box. If <fStep> is true, then only this one line will be |
474: | executed. Otherwise, every line from the currently selected line to |
475: | the last line in the edit box will be executed sequentially. |
476: | |
477: | Arguments: |
478: | hwndDlg window handle of the main dialog window |
479: | fSingleStep flag indicating whether or not to work in 'single step'|
480: | mode |
481: | Returns: |
482: | void |
483: | |
484: \*----------------------------------------------------------------------------*/
485:
486: void execute(
487: HWND hwndDlg,
488: BOOL fSingleStep)
489: {
490: int iLine; /* line # of the command currently being executed
491: in the edit box */
492: int n=0; /* counter variable */
493: int runcount = 1;
494: int count;
495: int iLineStart;
496: BOOL fIgnoreErrors = FALSE;
497:
498: runcount = GetDlgItemInt(hwndDlg, ID_RUNCOUNT, NULL, TRUE);
499:
500: /*
501: * Go through this loop for every line in the edit box from the currently
502: * selected line to the last line, or a single line if in single step mode
503: */
504:
505: iLineStart = EditGetCurLine(hwndEdit);
1.1.1.2 ! root 506: dprintf2((TEXT("Called to execute %d lines from line %d"), runcount, iLineStart));
1.1 root 507:
508: for (count = runcount; count-- > 0; )
509: {
510: for (iLine = iLineStart;
511: EditGetLine(hwndEdit, iLine, aszBuffer, sizeof(aszBuffer));
512: iLine++ ) {
513:
514: /* If we hit a comment line or a blank line, skip to the next line */
515:
516: if (*aszBuffer == ';' || *aszBuffer == 0) {
517: continue;
1.1.1.2 ! root 518: }
! 519:
! 520: if (*aszBuffer == '!' ) { // Internal command
! 521: ProcessInternalCommand(hwndDlg, aszBuffer+1);
! 522: continue;
! 523: }
1.1 root 524:
525: /* Select the line that is about to be processed */
526:
527: EditSelectLine(hwndEdit,iLine);
528:
529: /*
530: * If we're in 'single step' mode and we've already processed one
531: * line, then break out of the loop (and exit the routine).
532: */
533:
534: if (fSingleStep && ++n == 2) {
535: break;
536: }
537:
538: /*
539: * Send the command on the current line to MCI via the string
540: * interface.
541: */
542:
543: if (sendstring(hwndDlg, aszBuffer) != 0
544: && !fIgnoreErrors
545: && runcount > 1
546: && !fSingleStep) {
547:
548: int nRet;
549:
550: nRet = DialogBox(hInstApp, MAKEINTRESOURCE(IDD_ERRORDLG),
551: hwndDlg, (DLGPROC)ErrDlgFunc);
552:
553: if (nRet == IDABORT) { goto exit_fn; }
554: if (nRet == IDIGNORE) { fIgnoreErrors = TRUE; }
555:
556: }
557: }
558: SetDlgItemInt (hwndDlg, ID_RUNCOUNT, count, TRUE);
559: if (fSingleStep) { break; }
560: }
561: exit_fn:;
562: SetDlgItemInt (hwndDlg, ID_RUNCOUNT, runcount, TRUE);
563: }
564:
565:
566: /*----------------------------------------------------------------------------*\
567: | devices( hwndDlg, uMessage, wParam, lParam ) |
568: | |
569: | Description: |
570: | This function handles messages belonging to the "List of open devices" |
571: | dialog box. The only message that it looks for is WM_COMMAND, |
572: | indicating the user has pressed the "OK" button. When this happens, |
573: | it takes down the dialog box. |
574: | |
575: | Arguments: |
576: | hwndDlg window handle of the Devices dialog window |
577: | uMessage message number |
578: | wParam message-dependent parameter |
579: | lParam message-dependent parameter |
580: | |
581: | Returns: |
582: | TRUE if the message has been processed, else FALSE |
583: | |
584: \*----------------------------------------------------------------------------*/
585:
586: STATICFN BOOL devices(
587: HWND hwndDlg,
588: UINT Msg,
589: LONG wParam,
590: LONG lParam)
591: {
592: switch (Msg) {
593:
594: case WM_COMMAND:
595:
1.1.1.2 ! root 596: dprintf4((TEXT("Devices -- WM_COMMAND")));
1.1 root 597: switch (LOWORD(wParam)) {
598:
599: case ID_END_DEVICE_LIST:
600:
601: hwndDevices = 0;
602: EndDialog(hwndDlg,TRUE);
603:
604: break;
605: }
606:
607: break;
608: }
609:
610: return FALSE;
611: }
612:
613:
614:
615: /*----------------------------------------------------------------------------*\
616: | create_device_list() |
617: | |
618: | Description: |
619: | This function creates the Devices dialog box and updates the list of |
620: | open devices displayed in it. |
621: | |
622: | Arguments: |
623: | none |
624: | |
625: | Returns: |
626: | void |
627: | |
628: \*----------------------------------------------------------------------------*/
629:
630: void create_device_list(
631: void)
632: {
633: /* Create the Devices dialog box */
634:
635: hwndDevices = CreateDialog(hInstApp, MAKEINTRESOURCE(IDD_DEVICES),
636: hwndMainDlg, (DLGPROC)devices);
637:
638: if (hwndDevices == NULL) {
1.1.1.2 ! root 639: dprintf1((TEXT("NULL hwndDevices")));
1.1 root 640: return;
641: }
642:
643: /* Update the information displayed in the listbox */
644:
645: update_device_list();
646: }
647:
648:
649: /*----------------------------------------------------------------------------*\
650: | mcitester( hwndDlg, Msg, wParam, lParam ) |
651: | |
652: | Description: |
653: | This function is the main message handler for MCI test. It handles |
654: | messages from the pushbuttons, radio buttons, edit controls, menu |
655: | system, etc. When it receives a WM_EXIT message, this routine tears |
656: | everything down and exits. |
657: | |
658: | Arguments: |
659: | hwndDlg window handle of the main dialog window |
660: | Msg message number |
661: | wParam message-dependent parameter |
662: | lParam message-dependent parameter |
663: | |
664: | Returns: |
665: | TRUE if the message has been processed, else FALSE |
666: | |
667: \*----------------------------------------------------------------------------*/
668:
669: BOOL mcitester(
670: HWND hwndDlg,
671: UINT Msg,
672: LONG wParam,
1.1.1.2 ! root 673: LONG lParam)
1.1 root 674: {
675: DWORD dw; /* return value from various messages */
676: UINT EnableOrNot; /* is something currently selected? */
677: UINT wID; /* the type of notification required */
678: int i;
679:
680: #if DBG
681: if (Msg != WM_MOUSEMOVE && Msg != WM_NCHITTEST && Msg != WM_NCMOUSEMOVE
1.1.1.2 ! root 682: && (Msg < WM_CTLCOLORMSGBOX || Msg > WM_CTLCOLORSTATIC)
! 683: && Msg != WM_SETCURSOR) {
! 684: dprintf4((TEXT("hWnd: %08XH, Msg: %08XH, wParam: %08XH, lParam: %08XH"), hwndDlg, Msg, wParam, lParam ));
1.1 root 685: }
686: #endif
687: switch (Msg) {
688:
1.1.1.2 ! root 689: case WM_CLOSE:
! 690: DestroyWindow( hwndDlg );
! 691: break;
! 692:
1.1 root 693: case WM_COMMAND:
694:
1.1.1.2 ! root 695: dprintf3((TEXT("WM_COMMAND, wParam: %08XH, lParam: %08XH"), wParam, lParam));
1.1 root 696: switch (LOWORD(wParam)) {
697:
698: case IDOK:
699:
700: /*
701: * When the OK button gets pressed, insert a CR LF into
702: * the edit control. and execute the current line.
703: *
704: */
705:
706: SetFocus(hwndEdit);
1.1.1.2 ! root 707: i = EditGetCurLine(hwndEdit);
1.1 root 708:
709: execute(hwndDlg, TRUE);
710:
711: EditSetCurLine(hwndEdit, i);
712:
713: SendMessage(hwndEdit, WM_KEYDOWN, VK_END, 0L);
714: SendMessage(hwndEdit, WM_KEYUP, VK_END, 0L);
1.1.1.2 ! root 715: SendMessage(hwndEdit, EM_REPLACESEL, 0,(LONG)(LPTSTR)aszEOL);
1.1 root 716:
717: break;
718:
719: case ID_GO:
720:
721: /*
722: * When the GO! button gets pressed, execute every line
723: * in the edit box starting with the first one.
724: *
725: */
726:
727: EditSetCurLine(hwndEdit, 0);
728: execute(hwndDlg, FALSE);
729:
730: break;
731:
732: case ID_STEP:
733:
734: /*
735: * When the STEP button gets pressed, execute the currently
736: * selected line in the edit box.
737: */
738:
739: execute(hwndDlg, TRUE);
740:
741: break;
742:
743: case MENU_EXIT:
744: case ID_EXIT:
745:
746: /*
747: * If the user indicates that he/she wishes to exit the
748: * application, then end the main dialog and post a WM_QUIT
749: * message.
750: *
751: */
1.1.1.2 ! root 752: DestroyWindow( hwndDlg );
! 753: break;
1.1 root 754:
1.1.1.2 ! root 755: case IDCANCEL:
! 756: /* Ctrl+break will result in
! 757: 1. If there is an MCI command running, then breaking it (good)
! 758: 2. If there is NOT an MCI command running then the dialog manager will send
! 759: someone an IDCANCEL, and if we have the focus, we don't want to exit
! 760: by surprise. This means that to actually exit you'll have to do
! 761: Alt+F4 or else File manu and Exit to send (WM_COMMAND, ID_EXIT)
! 762: */
1.1 root 763: break;
764:
765: case MENU_ABOUT:
766:
767: /* Show the 'About...' box */
768:
769: DialogBox(hInstApp, MAKEINTRESOURCE(IDD_ABOUTBOX), hwndDlg, (DLGPROC)AboutDlgProc);
770: break;
771:
772: case WM_CLEAR:
773: case WM_CUT:
774: case WM_COPY:
775: case WM_PASTE:
776: case WM_UNDO:
777:
778: /* Pass whatever edit message we receive to the edit box */
779: // BUGBUG This might well be bogus
1.1.1.2 ! root 780: dprintf3((TEXT("sending edit Msg to edit control")));
1.1 root 781: SendMessage(hwndEdit, LOWORD(wParam), 0, 0);
782:
783: break;
784:
785: case MENU_OPEN:
786:
787: /* Open a 'File Open' dialog */
788: #ifdef WIN16
789:
790: f = OpenFileDialog(hwndDlg, aszOpenFileTitle, aszExt,
791: DLGOPEN_MUSTEXIST | OF_EXIST | OF_READ, NULL,
792: aszBuffer, sizeof(aszBuffer));
793:
794: /* If the user selected a valid file, then open it */
795:
796: if ((int)f >= 0)
1.1.1.2 ! root 797: OpenMciFile(hwndDlg, aszBuffer);
1.1 root 798: #else
799:
800: strcpy(aszBuffer, aszExt);
1.1.1.2 ! root 801: i = DlgOpen(hInstApp, hwndDlg, aszBuffer, sizeof(aszBuffer),
! 802: OFN_FILEMUSTEXIST);
1.1 root 803:
804: /* If the user selected a valid file, then open it */
805:
806: if (i == 1)
807: OpenMciFile(hwndDlg, aszBuffer);
808: #endif
809:
810: break;
811:
812: case MENU_SAVE:
813:
814: /*
815: * If a filename exists, then save the contents of the edit
816: * box under that filename.
817: *
818: */
819:
820: if (*aszMciFile) {
821:
822: EditSaveFile(hwndEdit, aszMciFile);
823: break;
824: }
825:
826: break;
827:
828: case MENU_SAVEAS:
829:
830: /*
831: */
832:
833: #ifdef WIN16
834: *aszBuffer = (char)0;
835: f = OpenFileDialog(hwndDlg, aszSaveFileTitle, aszExt,
836: DLGOPEN_SAVE | OF_EXIST, aszSaveFileControl, aszBuffer,
837: sizeof(aszBuffer));
838:
839: /* If the user didn't hit Cancel, then he must have set a
840: * filename, so save the contents of the edit box under
841: * that filename.
842: */
843: if (f != DLGOPEN_CANCEL) {
844:
845: EditSaveFile(hwndEdit, aszBuffer);
846: }
847:
848: #else
849: strcpy(aszBuffer, aszExt);
1.1.1.2 ! root 850: i = DlgOpen(hInstApp, hwndDlg, aszBuffer, sizeof(aszBuffer) ,
! 851: OFN_PATHMUSTEXIST | OFN_NOREADONLYRETURN | OFN_OVERWRITEPROMPT);
1.1 root 852:
853: /*
854: * If the user didn't hit Cancel, then he must have set a
855: * filename, so save the contents of the edit box under
856: * that filename.
857: *
858: */
859:
1.1.1.2 ! root 860: if (i == 1) {
1.1 root 861:
862: EditSaveFile(hwndEdit, aszBuffer);
863: }
864: #endif
865: break;
866:
867: case MENU_DEVICES:
868:
869: /*
870: * If the Devices dialog box doesn't already exist, then
871: * create and display it.
872: *
873: */
874:
875: if (hwndDevices == 0) {
876: create_device_list();
877: }
878:
879: break;
880:
881: #if DBG
882: case IDM_DEBUG0:
883: case IDM_DEBUG1:
884: case IDM_DEBUG2:
885: case IDM_DEBUG3:
886: case IDM_DEBUG4:
887: dDbgSetDebugMenuLevel(wParam - IDM_DEBUG0);
888: break;
889: #endif
1.1.1.2 ! root 890: default: /* no-op */
! 891: break;
1.1 root 892: }
893: break; // end of WM_COMMAND case
894:
895: case WM_INITDIALOG:
896:
897: /* Do general initialization stuff */
898:
899: hwndEdit = GetDlgItem(hwndDlg,ID_INPUT);
900:
1.1.1.2 ! root 901: dprintf3((TEXT("WM_INITDIALOG: hwndEdit = %08xH"), hwndEdit));
1.1 root 902:
903: SetMenu(hwndDlg, LoadMenu(hInstApp, MAKEINTRESOURCE(IDM_MCITEST)));
904:
905: SetClassLong (hwndDlg, GCL_HICON,
906: (DWORD)LoadIcon (hInstApp, MAKEINTRESOURCE(IDI_MCITEST)));
907:
908: CheckDlgButton (hwndDlg, ID_NOT_SUCCESS, FALSE);
909: CheckDlgButton (hwndDlg, ID_NOT_SUPER, FALSE);
910: CheckDlgButton (hwndDlg, ID_NOT_ABORT, FALSE);
911: CheckDlgButton (hwndDlg, ID_NOT_FAIL, FALSE);
912: SetDlgItemInt (hwndDlg, ID_RUNCOUNT, 1, TRUE);
913:
914: #if DBG
1.1.1.2 ! root 915: // Check the initial debug level
! 916: {
! 917: HANDLE hMenu;
! 918: hMenu = GetMenu(hwndDlg);
! 919: CheckMenuItem(hMenu, (UINT)(__iDebugLevel + IDM_DEBUG0), MF_CHECKED);
! 920: }
1.1 root 921: #endif
922:
923: hAccTable = LoadAccelerators(hInstApp, MAKEINTRESOURCE(IDA_MCITEST));
1.1.1.2 ! root 924: dprintf4((TEXT("INIT_DIALOG: hwndEdit = %08XH, Haccel = %08XH"), hwndEdit, hAccTable));
1.1 root 925: return TRUE;
926:
927: case WM_DESTROY:
928:
929: /* End the dialog and send a WM_QUIT message */
930:
1.1.1.2 ! root 931: dprintf2((TEXT("dialog ending")));
1.1 root 932: dSaveDebugLevel(aszAppName);
933: PostQuitMessage (0);
934: hwndMainDlg = 0;
935: break;
936:
937: case MM_MCINOTIFY:
938:
939: /*
940: * Check the radio button corresponding to the notification
941: * received.
942: *
943: */
944:
1.1.1.2 ! root 945: dprintf3((TEXT("MM_MCINOTIFY, wParam: %08XH"), wParam));
1.1 root 946: wID = 0;
947: switch (wParam) {
1.1.1.2 ! root 948: case MCI_NOTIFY_SUCCESSFUL:
1.1 root 949:
950: wID = ID_NOT_SUCCESS;
951: break;
952:
953: case MCI_NOTIFY_SUPERSEDED:
954:
955: wID = ID_NOT_SUPER;
956: break;
957:
958: case MCI_NOTIFY_ABORTED:
959:
960: wID = ID_NOT_ABORT;
961: break;
962:
963: case MCI_NOTIFY_FAILURE:
964:
965: wID = ID_NOT_FAIL;
966: break;
967:
968: default:
969: break;
970: }
971:
972: if (wID) {
973:
974: CheckDlgButton (hwndDlg, wID, TRUE);
975: SetFocus (GetDlgItem(hwndDlg, ID_INPUT));
976: }
977:
978: break;
979:
980: case WM_INITMENUPOPUP: /* wParam is menu handle */
981:
1.1.1.2 ! root 982: dprintf3((TEXT("WM_INITMENUPOPUP")));
1.1 root 983:
984: /* Enable the 'Save' option if a valid filename exists */
985:
986: EnableMenuItem((HMENU)wParam, (UINT)MENU_SAVE,
987: (UINT)(*aszMciFile ? MF_ENABLED : MF_GRAYED));
988:
989: /* Find out if something is currently selected in the edit box */
990:
991: dw = SendMessage(hwndEdit,EM_GETSEL,0,0L);
992: EnableOrNot = (UINT)((HIWORD(dw) != LOWORD(dw) ? MF_ENABLED : MF_GRAYED));
993:
994: /* Enable / disable the Edit menu options appropriately */
995:
996: EnableMenuItem ((HMENU)wParam, (UINT)WM_UNDO ,
997: (UINT)(SendMessage(hwndEdit,EM_CANUNDO,0,0L) ? MF_ENABLED : MF_GRAYED));
998: EnableMenuItem ((HMENU)wParam, WM_CUT , EnableOrNot);
999: EnableMenuItem ((HMENU)wParam, WM_COPY , EnableOrNot);
1000: EnableMenuItem ((HMENU)wParam, WM_PASTE,
1001: (UINT)(IsClipboardFormatAvailable(CF_TEXT) ? MF_ENABLED : MF_GRAYED));
1002: EnableMenuItem ((HMENU)wParam, WM_CLEAR, EnableOrNot);
1003:
1004: return 0L;
1005: }
1006:
1007: return 0;
1008: }
1009:
1010:
1011: /*----------------------------------------------------------------------------*\
1012: | AppInit( hInst, hPrev, sw, szCmdLine) |
1013: | |
1014: | Description: |
1015: | This is called when the application is first loaded into memory. It |
1016: | performs all initialization that doesn't need to be done once per |
1017: | instance. |
1018: | |
1019: | Arguments: |
1020: | hInstance instance handle of current instance |
1021: | hPrev instance handle of previous instance |
1022: | sw not really used at all |
1023: | szCmdLine string containing the command line arguments |
1024: | |
1025: | Returns: |
1026: | TRUE if successful, FALSE if not |
1027: | |
1028: \*----------------------------------------------------------------------------*/
1029:
1030: BOOL AppInit(
1031: int argc,
1032: char *argv[])
1033: {
1034: /* Put up the main dialog box */
1035:
1.1.1.2 ! root 1036: hInstApp = GetModuleHandle(NULL);
! 1037: dprintf1((TEXT("MCITEST starting... module handle is %xH"), hInstApp));
1.1 root 1038:
1039: if (NULL ==
1040: (hwndMainDlg = CreateDialog (hInstApp,
1.1.1.2 ! root 1041: MAKEINTRESOURCE(IDD_MCITEST),
! 1042: NULL, (DLGPROC)mcitester)
1.1 root 1043: )) {
1044:
1.1.1.2 ! root 1045: DWORD n;
! 1046:
! 1047: n = GetLastError();
! 1048: dprintf1((TEXT("NULL hwndMainDLG, last error is %d"), n));
! 1049: DebugBreak();
1.1 root 1050:
1051: return(FALSE);
1052: }
1053:
1054: /* Fix up WIN.INI if this is the first time we are run... */
1055:
1056: if (!GetProfileString(aszProfileSection, aszProfileKey, aszNULL, aszBuffer, sizeof(aszBuffer)))
1057: WriteProfileString(aszProfileSection, aszProfileKey, aszProfileSetting);
1058:
1059: /*
1060: * If a command line argument was specified, assume it to be a filename
1061: * and open that file.
1062: *
1063: */
1064:
1.1.1.2 ! root 1065: if (argc > 1 && *argv[1]) {
! 1066: #ifdef UNICODE
! 1067: LPTSTR lpCommandLine = GetCommandLine();
! 1068:
! 1069: // Skip over the command name to get to the argument string
! 1070: while (*lpCommandLine && *lpCommandLine++ != TEXT(' ')) {
! 1071: }
! 1072:
! 1073: OpenMciFile(hwndMainDlg, lpCommandLine);
! 1074: #else
1.1 root 1075: OpenMciFile(hwndMainDlg, argv[1]);
1.1.1.2 ! root 1076: #endif
! 1077: }
1.1 root 1078:
1079: return TRUE;
1080: }
1081:
1082:
1083: /*----------------------------------------------------------------------------*\
1084: | WinMain( hInst, hPrev, lpszCmdLine, sw ) |
1085: | |
1086: | Description: |
1087: | The main procedure for the app. After initializing, it just goes |
1088: | into a message-processing loop until it gets a WM_QUIT message |
1089: | (meaning the app was closed). |
1090: | |
1091: | Arguments: |
1092: | hInst instance handle of this instance of the app |
1093: | hPrev instance handle of previous instance, NULL if first |
1094: | szCmdLine null-terminated command line string |
1095: | sw specifies how the window is to be initially displayed |
1096: | |
1097: | Returns: |
1098: | The exit code as specified in the WM_QUIT message. |
1099: | |
1100: \*----------------------------------------------------------------------------*/
1101:
1102: int _CRTAPI1 main(
1103: int argc,
1104: char *argv[],
1105: char *envp[])
1106: {
1107: MSG Msg; /* Windows message structure */
1108:
1109: // If we are in DEBUG mode, get debug level for this module
1110: dGetDebugLevel(aszAppName);
1111: #if DBG
1.1.1.2 ! root 1112: dprintf1((TEXT("started (debug level %d)"), __iDebugLevel));
1.1 root 1113: #endif
1114:
1115: /* Call the initialization procedure */
1116:
1117: if (!AppInit(argc, argv)) {
1118: return FALSE;
1119: }
1120:
1121:
1122: /* Poll the event queue for messages */
1123:
1124: while (GetMessage(&Msg, NULL, 0, 0)) {
1125:
1126: /*
1127: * If the Devices dialog is showing and the number of open devices has
1128: * changed since we last checked, then update the list of open devices.
1129: */
1130:
1131: if (hwndDevices != 0 && get_number_of_devices() != nLastNumberOfDevices) {
1132: update_device_list();
1133: }
1134:
1135: /* Main message processing */
1136:
1137: if (!hwndMainDlg || !IsDialogMessage(hwndMainDlg, &Msg)) {
1138: TranslateMessage(&Msg);
1139: DispatchMessage(&Msg);
1.1.1.2 ! root 1140:
1.1 root 1141: // IsDialogMessage may enter with hwndMainDlg != NULL and exit with
1142: // hwndMainDlg == NULL after processing the message
1143: }
1144: else if (hwndMainDlg) {
1145: TranslateAccelerator (hwndMainDlg, hAccTable, &Msg);
1146: }
1147: }
1148:
1149: return Msg.wParam;
1150: }
1.1.1.2 ! root 1151:
! 1152:
! 1153: STATICDT TCHAR ms[] = TEXT("milliseconds");
! 1154: STATICDT TCHAR sc[] = TEXT("seconds");
! 1155: STATICDT TCHAR hr[] = TEXT("hours");
! 1156: STATICDT TCHAR mn[] = TEXT("minutes");
! 1157:
! 1158: STATICFN void ProcessInternalCommand(HWND hDlg, LPTSTR aszBuffer)
! 1159: {
! 1160: LPTSTR pch = aszBuffer;
! 1161: TCHAR msg[80];
! 1162:
! 1163: if( (0 == (strnicmp(aszBuffer, TEXT("SLEEP"),5)))
! 1164: || (0 == (strnicmp(aszBuffer, TEXT("PAUSE"),5)))) {
! 1165:
! 1166: UINT factor = 1;
! 1167: UINT number;
! 1168: LPTSTR delay;
! 1169: LPTSTR pch1;
! 1170: pch += 5; // length SLEEP/PAUSE
! 1171: while (*pch && *pch == TEXT(' ') ) {
! 1172: pch++;
! 1173: }
! 1174:
! 1175: if (!*pch) {
! 1176: SetDlgItemText (hDlg, ID_OUTPUT, TEXT("No parameter provided for Sleep command"));
! 1177: return;
! 1178: }
! 1179:
! 1180: #ifdef UNICODE
! 1181: wsprintf(msg "%hs", pch); // Convert string to ascii
! 1182: number = atoi( msg );
! 1183: #else
! 1184: number = atoi( pch );
! 1185: #endif
! 1186:
! 1187: if (0 == number) {
! 1188: SetDlgItemText (hDlg, ID_OUTPUT, TEXT("Parameter is not a number"));
! 1189: return;
! 1190: }
! 1191:
! 1192:
! 1193: // pch addresses the number
! 1194: // Now see if there are any other parameters
! 1195: // First, skip to the end of the number
! 1196:
! 1197: pch1 = pch+1;
! 1198: while (*pch1 && *pch1 != TEXT(' ') ) {
! 1199: pch1++;
! 1200: }
! 1201:
! 1202: if (*pch1) {
! 1203: *pch1++ = TEXT('\0');
! 1204:
! 1205: // There is another parameter. Accept s/S for seconds,
! 1206: // h/M for hours
! 1207: // m/M for minutes
! 1208: // Default is milliseconds
! 1209: while (*pch1 && *pch1 == TEXT(' ') ) {
! 1210: pch1++;
! 1211: }
! 1212: }
! 1213:
! 1214: switch (*pch1) {
! 1215: case TEXT('s'):
! 1216: case TEXT('S'):
! 1217: delay = sc;
! 1218: factor = 1000;
! 1219: break;
! 1220: case TEXT('m'):
! 1221: case TEXT('M'):
! 1222: delay = mn;
! 1223: factor = 1000*60;
! 1224: break;
! 1225: case TEXT('h'):
! 1226: case TEXT('H'):
! 1227: delay = hr;
! 1228: factor = 1000*60*60;
! 1229: break;
! 1230: case TEXT('\0'):
! 1231: default:
! 1232: delay = ms;
! 1233: factor = 1;
! 1234: break;
! 1235: }
! 1236:
! 1237: wsprintf(msg, TEXT("Sleeping for %d %s"), number, delay);
! 1238: SetDlgItemText (hDlg, ID_OUTPUT, msg);
! 1239: Sleep(number*factor);
! 1240:
! 1241: } else if (0 == (strnicmp(aszBuffer, TEXT("CD"),2))) {
! 1242: BOOL fResult;
! 1243: pch += 2; // length CD
! 1244: while (*pch && *pch == TEXT(' ') ) {
! 1245: pch++;
! 1246: }
! 1247: fResult = SetCurrentDirectory(pch);
! 1248: if (!fResult) {
! 1249: UINT errorcode;
! 1250: errorcode = GetLastError();
! 1251: wsprintf(msg,
! 1252: TEXT("Set current directory to >%s< failed, error code==%d"),
! 1253: pch, errorcode);
! 1254: } else
! 1255: wsprintf(msg,
! 1256: TEXT("Set current directory to >%s<"), pch);
! 1257: SetDlgItemText (hDlg, ID_OUTPUT, msg);
! 1258:
! 1259: } else {
! 1260: SetDlgItemText (hDlg, ID_OUTPUT, TEXT("Unrecognised internal command"));
! 1261: }
! 1262: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.