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