Annotation of mstools/samples/playit/playit.c, revision 1.1.1.1

1.1       root        1: #include <windows.h>
                      2: #include <string.h>
                      3: #include <stdio.h>
                      4: 
                      5: #if !defined(NT)
                      6:     #if defined (NOMM)
                      7:     // define 'NOMM' if you want to build this for a non-sound machine
                      8:         #define SND_SYNC    0
                      9:         #define SND_FILENAME    0
                     10:         #define SND_ALIAS       0
                     11:         BOOL APIENTRY PlaySound(LPSTR lpszName, HANDLE hModule, UINT flags)
                     12:         {
                     13:             MessageBox (GetFocus(), lpszName, "Beeeeeep", MB_OK);
                     14:             return TRUE;
                     15:         }
                     16:     #else
                     17:         #include <mmsystem.h>
                     18:         // Win32 has some extra flags that it is using...
                     19:         #define SND_FILENAME 0
                     20:         #define SND_ALIAS 0
                     21:     #endif
                     22:     // Here are some 'types' that Win32 uses that would be handy for Win16
                     23:     #define UINT    unsigned int
                     24:     #define INT     int
                     25:     #define APIENTRY    far pascal
                     26:     // The Win16 call is different from the Win32 one
                     27:     #define PlaySound(szFile, hMod, flags) sndPlaySound (szFile, flags)
                     28: #endif
                     29: #include <commdlg.h>
                     30: #include "playit.h"
                     31: 
                     32: char szAppName[] = "PlayIt";
                     33: 
                     34: HWND    hwndMain;
                     35: HWND    hwndChild;
                     36: HMENU   hmenuRes;
                     37: UINT    idMaxResource = IDM_RESOURCE;
                     38: WORD    TimerID     = 1;    /* number used for timer-id */
                     39: CHAR    szBuffer[200];    /* buffer for stringtable stuff */
                     40: 
                     41: long FAR PASCAL WndProc (HWND, UINT, UINT, LONG);
                     42: BOOL FAR PASCAL AboutDlgProc (HWND, UINT, UINT, LONG);
                     43: BOOL APIENTRY GetFileName(LPSTR);
                     44: BOOL FillResMenu (HMENU);
                     45: long FAR PASCAL ChildWndProc (HWND, UINT, UINT, LONG);
                     46: 
                     47: int APIENTRY WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
                     48:     HANDLE  hInstance, hPrevInstance;
                     49:     LPSTR   lpszCmdLine;
                     50:     int     nCmdShow;
                     51: {
                     52:     MSG     msg;
                     53:     WNDCLASS    wndclass;
                     54:     HMENU   hmenuApp;
                     55:         PSTR       szTooMany;
                     56:         CHAR       TempString[100];
                     57: 
                     58: #if defined (NT)
                     59:     nCmdShow = SW_SHOWNORMAL;
                     60:     hInstance = GetModuleHandle( NULL );
                     61: #endif
                     62: 
                     63:     if (!hPrevInstance) {
                     64:         wndclass.style      = CS_HREDRAW | CS_VREDRAW;
                     65:         wndclass.lpfnWndProc    = (WNDPROC) WndProc;
                     66:         wndclass.cbClsExtra     = 0;
                     67:         wndclass.cbWndExtra     = 0;
                     68:         wndclass.hInstance      = hInstance;
                     69:         wndclass.hIcon      = LoadIcon (hInstance, szAppName);
                     70:         wndclass.hCursor    = LoadCursor (NULL, IDC_ARROW);
                     71:         wndclass.hbrBackground  = (HBRUSH)(COLOR_APPWORKSPACE+1);
                     72:         wndclass.lpszMenuName   = szAppName;
                     73:         wndclass.lpszClassName  = szAppName;
                     74: 
                     75:         if (!RegisterClass (&wndclass)) {
                     76:             return FALSE;
                     77:         }
                     78:         wndclass.style      = CS_HREDRAW | CS_VREDRAW;
                     79:         wndclass.lpfnWndProc    = (WNDPROC) ChildWndProc;
                     80:         wndclass.cbClsExtra     = 0;
                     81:         wndclass.cbWndExtra     = 10;
                     82:         wndclass.hInstance      = hInstance;
                     83:         wndclass.hIcon      = LoadIcon (hInstance, szAppName);
                     84:         wndclass.hCursor    = LoadCursor (NULL, IDC_ARROW);
                     85:         wndclass.hbrBackground  = GetStockObject(WHITE_BRUSH);
                     86:         wndclass.lpszMenuName   = (HMENU) NULL;
                     87:         wndclass.lpszClassName  = "SoundChild";
                     88: 
                     89:         if (!RegisterClass (&wndclass)) {
                     90:             return FALSE;
                     91:         }
                     92: 
                     93: 
                     94: 
                     95:         }
                     96: 
                     97:     hwndMain = CreateWindow (szAppName, szAppName,
                     98:         WS_OVERLAPPEDWINDOW,
                     99:         CW_USEDEFAULT, 0, 300, 200,
                    100:         NULL, (HMENU) NULL, hInstance, NULL);
                    101: 
                    102:         /* create non-visible child window pop up*/
                    103:     hwndChild = CreateWindow ("SoundChild", "SoundChild",
                    104:         WS_CHILD | WS_CAPTION,
                    105:         CW_USEDEFAULT, 0, 200, 100,
                    106:         hwndMain, (HMENU)NULL, hInstance, NULL);
                    107: 
                    108: 
                    109:     if (!SetTimer(hwndChild, TimerID, (UINT) 5000, 0L))
                    110:         {
                    111:         /* Windows only supports 16 public timers */
                    112:         if(!(szTooMany = (PSTR)LocalAlloc(LPTR, 160))){
                    113:             strcpy(TempString, " Too Many Timers Allocated ");
                    114:             szTooMany = TempString;
                    115:         }
                    116:         else{
                    117:             LoadString(hInstance, IDS_TOOMANY, (LPSTR)szTooMany, 160);
                    118:         }
                    119:         MessageBox((HWND)NULL, (LPSTR)szTooMany, (LPSTR)szBuffer, MB_OK | MB_ICONHAND | MB_SYSTEMMODAL);
                    120:         return(FALSE);
                    121:     }
                    122:                                  
                    123:     hmenuApp = GetMenu (hwndMain);
                    124:     hmenuRes = CreatePopupMenu();
                    125:     if (FillResMenu(hmenuRes)) {
                    126:         if (InsertMenu (hmenuApp, GetMenuItemCount(hmenuApp)-1,
                    127:         MF_BYPOSITION | MF_POPUP, (UINT)hmenuRes, (LPSTR)"&Resources")) {
                    128:             DrawMenuBar (hwndMain);
                    129:         }
                    130:     }
                    131: 
                    132:     ShowWindow (hwndMain, nCmdShow);
                    133:     UpdateWindow (hwndMain);
                    134: 
                    135:     while (GetMessage (&msg, NULL, 0, 0)) {
                    136:         TranslateMessage (&msg);
                    137:         DispatchMessage (&msg);
                    138:     }
                    139:     return msg.wParam;
                    140: 
                    141:     lpszCmdLine; // Just to resolve reference
                    142: }
                    143: 
                    144: 
                    145: BOOL CenterWindow (HWND hwndChild, HWND hwndParent)
                    146: {
                    147:     RECT    rChild, rParent;
                    148:     int     wChild, hChild, wParent, hParent;
                    149:     int     wScreen, hScreen, xNew, yNew;
                    150:     HDC     hdc;
                    151: 
                    152:     GetWindowRect (hwndChild, &rChild);
                    153:     wChild = rChild.right - rChild.left;
                    154:     hChild = rChild.bottom - rChild.top;
                    155: 
                    156:     GetWindowRect (hwndParent, &rParent);
                    157:     wParent = rParent.right - rParent.left;
                    158:     hParent = rParent.bottom - rParent.top;
                    159: 
                    160:     hdc = GetDC (hwndChild);
                    161:     wScreen = GetDeviceCaps (hdc, HORZRES);
                    162:     hScreen = GetDeviceCaps (hdc, VERTRES);
                    163:     ReleaseDC (hwndChild, hdc);
                    164: 
                    165:     xNew = rParent.left + ((wParent - wChild) /2);
                    166:     if (xNew < 0) {
                    167:         xNew = 0;
                    168:     } else if ((xNew+wChild) > wScreen) {
                    169:         xNew = wScreen - wChild;
                    170:     }
                    171: 
                    172:     yNew = rParent.top  + ((hParent - hChild) /2);
                    173:     if (yNew < 0) {
                    174:         yNew = 0;
                    175:     } else if ((yNew+hChild) > hScreen) {
                    176:         yNew = hScreen - hChild;
                    177:     }
                    178: 
                    179:     return SetWindowPos (hwndChild, NULL, xNew, yNew, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
                    180: }
                    181: 
                    182: 
                    183: BOOL APIENTRY AboutDlgProc(HWND hwnd, UINT msg, UINT wParam, LONG lParam)
                    184: {
                    185:     INT wmId;
                    186: 
                    187:     switch (msg) {
                    188:         case WM_INITDIALOG:
                    189:             CenterWindow (hwnd, GetWindow (hwnd, GW_OWNER));
                    190:             return (TRUE);
                    191: 
                    192:         case WM_COMMAND:
                    193: #if defined (NT)
                    194:             wmId = LOWORD(wParam);
                    195: #elif defined (WIN16)
                    196:             wmId = wParam;
                    197: #endif
                    198:         switch (wmId) {
                    199:             case IDOK:
                    200:             case IDCANCEL:
                    201:                 EndDialog(hwnd, TRUE);
                    202:                 return (TRUE);
                    203:         }
                    204:         break;
                    205:     }
                    206:     return (FALSE);
                    207: 
                    208:     /* Just For Reference */
                    209:     lParam;
                    210: }
                    211: 
                    212: UINT BeepFlags (UINT wParam)
                    213: {
                    214:     UINT flags = MB_OK;
                    215: 
                    216:     switch (wParam) {
                    217:         case IDM_SYNC_ICONHAND:
                    218:         case IDM_SYNC_ICONQUESTION:
                    219:         case IDM_SYNC_ICONEXCLAMATION:
                    220:         case IDM_SYNC_ICONASTERISK:
                    221:             flags |= MB_TASKMODAL;
                    222:             break;
                    223:     }
                    224: 
                    225:     switch (wParam) {
                    226:         case IDM_ICONHAND:
                    227:         case IDM_SYNC_ICONHAND:
                    228:             flags |= MB_ICONHAND;
                    229:             break;
                    230: 
                    231:         case IDM_ICONQUESTION:
                    232:         case IDM_SYNC_ICONQUESTION:
                    233:             flags |= MB_ICONQUESTION;
                    234:             break;
                    235: 
                    236:         case IDM_ICONEXCLAMATION:
                    237:         case IDM_SYNC_ICONEXCLAMATION:
                    238:             flags |= MB_ICONEXCLAMATION;
                    239:             break;
                    240: 
                    241:         case IDM_ICONASTERISK:
                    242:         case IDM_SYNC_ICONASTERISK:
                    243:             flags |= MB_ICONASTERISK;
                    244:             break;
                    245: 
                    246:         default:
                    247:             break;
                    248:     }
                    249:     return flags;
                    250: }
                    251: 
                    252: 
                    253: 
                    254: long FAR PASCAL WndProc (hwnd, iMessage, wParam, lParam)
                    255:      HWND   hwnd;
                    256:      UINT   iMessage;
                    257:      UINT   wParam;
                    258:      LONG   lParam;
                    259: {
                    260: static char szSoundName[80];
                    261: static UINT sndFlags;
                    262:     HANDLE  hInst;
                    263:     FARPROC lpDlgProc;
                    264:     UINT    wmId, wmEvent;
                    265:     char    szBuf[25];
                    266:     char    szErr[25];
                    267:     UINT    flags;
                    268:     DWORD   err, i;
                    269: 
                    270: #if defined (WIN16)
                    271:     hInst = GetWindowWord (hwnd, GWW_HINSTANCE);
                    272: #elif defined (NT)
                    273:     hInst = GetModuleHandle (NULL);
                    274: #endif
                    275: 
                    276:     switch (iMessage) {
                    277:         case WM_CREATE:
                    278:             szSoundName[0] = (char)0;
                    279:             break;
                    280: 
                    281:         case WM_LBUTTONDOWN:
                    282:             if (lstrlen(szSoundName) > 0) {
                    283:                 PlaySound (szSoundName, hInst, sndFlags);
                    284:             }
                    285:             break;
                    286: 
                    287:         case WM_COMMAND:
                    288: #if defined (NT)
                    289:             wmId = LOWORD(wParam);
                    290:             wmEvent = HIWORD(wParam);
                    291: #elif defined (WIN16)
                    292:             wmId = wParam;
                    293:             wmEvent = HIWORD(lParam);
                    294: #endif
                    295: 
                    296:             switch (wmId) {
                    297:                 case IDM_OPEN:
                    298:                     if (GetFileName (szSoundName)) {
                    299:                         sndFlags = SND_ASYNC | SND_FILENAME;
                    300: 
                    301:                         /* SND_FILENAME doesn't seem to work, so...
                    302:                         WriteProfileString ("SOUNDS", "PLAYIT", szSoundName);
                    303:                         sndFlags = SND_ASYNC | SND_ALIAS;
                    304:                         strcpy (szSoundName, "PLAYIT");
                    305:                         */
                    306: 
                    307: 
                    308:                         sndFlags = SND_SYNC | SND_FILENAME;
                    309:                         // SND_FILENAME is currently having problems
                    310:                         // with path slashes... so lets switch in
                    311:                         // something that it can handle for now...
                    312:                         for (i=0; i<strlen(szSoundName); i++) {
                    313:                             if (szSoundName[i] == '\\')
                    314:                                 szSoundName[i] = '/';
                    315:                         }
                    316: 
                    317:                         if (!PlaySound(szSoundName, hInst, sndFlags)) {
                    318:                             err = GetLastError();
                    319:                             sprintf (szErr, "Error: %i [0x%x]", err, err);
                    320:                             MessageBox (GetFocus(), szErr, szSoundName, MB_OK);
                    321:                         }
                    322: 
                    323:                     }
                    324:                     break;
                    325: 
                    326:                 case IDM_ABOUT:
                    327:                     lpDlgProc = MakeProcInstance((FARPROC) AboutDlgProc, hInst);
                    328:                     DialogBox(hInst, "AboutBox", hwnd, (WNDPROC)lpDlgProc);
                    329:                     FreeProcInstance(lpDlgProc);
                    330:                     break;
                    331: 
                    332:                 case IDM_HELP_CONTENTS:
                    333:                     WinHelp (hwnd, "PlayIt.HLP", HELP_KEY, (DWORD)"CONTENTS");
                    334:                     break;
                    335:                 case IDM_HELP_INDEX:
                    336:                     WinHelp (hwnd, "PlayIt.HLP", HELP_KEY, (DWORD)"INDEX");
                    337:                     break;
                    338:                 case IDM_HELP_OVERVIEW:
                    339:                     WinHelp (hwnd, "PlayIt.HLP", HELP_KEY, (DWORD)"OVERVIEW");
                    340:                     break;
                    341:                 case IDM_HELP_GLOSSARY:
                    342:                     WinHelp (hwnd, "PlayIt.HLP", HELP_KEY, (DWORD)"GLOSSARY");
                    343:                     break;
                    344:                 case IDM_HELP_TUTORIAL:
                    345:                     WinHelp (hwnd, "PlayIt.HLP", HELP_KEY, (DWORD)"TUTORIAL");
                    346:                     break;
                    347:                 case IDM_HELP_DEMO:
                    348:                     WinHelp (hwnd, "PlayIt.HLP", HELP_KEY, (DWORD)"DEMO");
                    349:                     break;
                    350:                 case IDM_HELP_HELP:
                    351:                     WinHelp (hwnd, "PlayIt.HLP", HELP_KEY, (DWORD)"HELP");
                    352:                     break;
                    353: 
                    354: 
                    355:                 case IDM_EXIT:
                    356:                     DestroyWindow(hwnd);
                    357:                     break;
                    358: 
                    359: 
                    360:                 default:
                    361:                                                  if (wmId >= IDM_RESOURCE && wmId <= idMaxResource) {
                    362:                         if (hmenuRes) {
                    363:                             GetMenuString (hmenuRes, wmId, szSoundName, sizeof(szBuf),
                    364:                                 MF_BYCOMMAND);
                    365:                                                                          sndFlags = SND_SYNC | SND_ALIAS;
                    366:                                                                          switch(szSoundName[6]){
                    367:                                                                                 
                    368:                                                                                        case 'H':
                    369:                                                                                        case 'h':
                    370:                                                                         
                    371:                                                                                                SendMessage(hwndChild, WM_COMMAND, MAKELONG(IDM_ICONHAND, NULL), (LONG)szSoundName);    
                    372:                                                                                                SendMessage(hwndChild, WM_COMMAND, MAKELONG(IDM_UNHIDE, NULL), (LONG)szSoundName);
                    373:                                                                                                break;
                    374: 
                    375:                                                                                        case 'Q':
                    376:                                                                                        case 'q':
                    377: 
                    378:                                                                                                SendMessage(hwndChild, WM_COMMAND, MAKELONG(IDM_ICONQUESTION, NULL), (LONG)szSoundName);        
                    379:                                                                                                SendMessage(hwndChild, WM_COMMAND, MAKELONG(IDM_UNHIDE, NULL), (LONG) szSoundName);
                    380:                                                                                                break;
                    381: 
                    382:                                                                                        case 'E':
                    383:                                                                                        case 'e':
                    384: 
                    385:                                                                                                SendMessage(hwndChild, WM_COMMAND, MAKELONG(IDM_ICONEXCLAMATION, NULL), (LONG)szSoundName);     
                    386:                                                                                                SendMessage(hwndChild, WM_COMMAND, MAKELONG(IDM_UNHIDE, NULL), (LONG) szSoundName);
                    387:                                                                                                break;
                    388: 
                    389:                                                                                        case 'A':
                    390:                                                                                        case 'a':
                    391: 
                    392:                                                                                                SendMessage(hwndChild, WM_COMMAND, MAKELONG(IDM_ICONASTERISK, NULL), (LONG)szSoundName);        
                    393:                                                                                                SendMessage(hwndChild, WM_COMMAND, MAKELONG(IDM_UNHIDE, NULL), (LONG) szSoundName);
                    394:                                                                                                break;
                    395: 
                    396:                                                                                        default:  
                    397:                                                                                                SendMessage(hwndChild, WM_COMMAND, MAKELONG(IDM_SYSTEMDEFAULT, NULL), (LONG) szSoundName);      
                    398:                                                                                                SendMessage(hwndChild, WM_COMMAND, MAKELONG(IDM_UNHIDE, NULL), (LONG) szSoundName);
                    399:                                                                         }                                 
                    400:                             if (!PlaySound (szSoundName, hInst, sndFlags)) {
                    401:                                 //err = GetLastError ();
                    402:                                 //sprintf (szErr, "Error: %i [0x%x]", err, err);
                    403:                                 MessageBox (hwnd, "ERROR", "PlaySound() Called SYNC failed", MB_OK);
                    404:                             }
                    405:                                                                         SendMessage(hwndChild, WM_COMMAND, MAKELONG(IDM_HIDE, NULL), (LONG) szSoundName);     
                    406: 
                    407:                         }
                    408:                     }
                    409:                     break;
                    410: 
                    411:             }
                    412:             break;
                    413: 
                    414:         case WM_DESTROY:
                    415:             if (hwnd == hwndMain) {
                    416:                                         DestroyWindow(hwndChild);
                    417:                 PostQuitMessage (0);
                    418:             }
                    419:             break;
                    420: 
                    421:         default:
                    422:             return DefWindowProc (hwnd, iMessage, wParam, lParam);
                    423:     }
                    424:     return 0L;
                    425: 
                    426:     hInst; //Just to resolve reference
                    427:     flags; // ditto
                    428: }
                    429: 
                    430: #define ID_TEST 321
                    431: #define ID_FN   1152
                    432: #define ID_CANCEL IDCANCEL
                    433: 
                    434: BOOL FAR PASCAL PlaySoundFileHook (HWND hdlg, UINT msg, UINT wParam, LONG lParam)
                    435: {
                    436:     HWND hwndTest;
                    437:     HWND hwndCancel;
                    438:     char szTmp[256];
                    439:     UINT cy, i;
                    440:     RECT rect;
                    441:     HANDLE hInst;
                    442:     WORD wId;
                    443: 
                    444:     hInst = GetModuleHandle (NULL);
                    445: 
                    446:     switch (msg) {
                    447:         case WM_INITDIALOG:
                    448: 
                    449:             /* Determine proper placement of the 'TEST' button */
                    450:             hwndCancel = GetDlgItem (hdlg, ID_CANCEL);
                    451:             if (hwndCancel!=0) {
                    452:                 GetWindowRect (hwndCancel, &rect);
                    453:                 cy = rect.bottom - rect.top;
                    454:                 rect.top = rect.bottom + cy;
                    455:                 rect.bottom = rect.top +cy;
                    456:                 ScreenToClient (hdlg, (LPPOINT)&rect.left);
                    457:                 ScreenToClient (hdlg, (LPPOINT)&rect.right);
                    458: 
                    459:                 hwndTest = CreateWindow ("BUTTON", "&Test",
                    460:                     BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | WS_TABSTOP,
                    461:                     rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
                    462:                     hdlg, (HMENU)ID_TEST, hInst, 0L);
                    463:                 if (hwndTest==0) {
                    464:                     MessageBox (GetFocus(), "No Test Button", "Open", MB_OK);
                    465:                 } else {
                    466:                     ShowWindow (hwndTest, SW_SHOW);
                    467:                 }
                    468: 
                    469:             } else {
                    470:                 MessageBox (GetFocus(), "Unable to find cancel button", "OpenFile", MB_OK);
                    471:             }
                    472: 
                    473:             break;
                    474: 
                    475:         case WM_COMMAND:
                    476:             wId = LOWORD(wParam);
                    477:             switch (wId) {
                    478:                 case ID_TEST:
                    479:                     /* The 'Viewer >>' button was pressed. */
                    480:                     GetWindowText (GetDlgItem(hdlg, ID_FN), szTmp, sizeof(szTmp));
                    481:                     for (i=0; i<(UINT)strlen(szTmp); i++) {
                    482:                         if (szTmp[i] == '\\')
                    483:                             szTmp[i] = '/';
                    484:                     }
                    485: 
                    486:                     PlaySound(szTmp, NULL, SND_ASYNC | SND_FILENAME );
                    487: 
                    488:             }
                    489:         break;
                    490:     }
                    491:     return (FALSE);
                    492: 
                    493:     lParam; // Just to reference it
                    494: }
                    495: 
                    496: 
                    497: 
                    498: BOOL APIENTRY GetFileName(LPSTR lpstr)
                    499: {
                    500:     OPENFILENAME ofn;
                    501:     char szFilterSpec [128] =               /* file type filters */
                    502:          "Sound Files(*.WAV)\0*.WAV\0";
                    503: 
                    504: #define MAXFILENAME 256
                    505:     char szFileName[MAXFILENAME];
                    506:     char szFileTitle[MAXFILENAME];
                    507: 
                    508:     lstrcpy(szFileName, "");   /* these need be NULL*/
                    509:     lstrcpy(szFileTitle, "");
                    510: 
                    511:     /* fill in non-variant fields of OPENFILENAME struct. */
                    512:     ofn.lStructSize     = sizeof(OPENFILENAME);
                    513:     ofn.hwndOwner       = GetFocus();
                    514:     ofn.lpstrFilter     = szFilterSpec;
                    515:     ofn.lpstrCustomFilter   = NULL;
                    516:     ofn.nMaxCustFilter  = 0;
                    517:     ofn.nFilterIndex    = 0;
                    518:     ofn.lpstrFile       = szFileName;
                    519:     ofn.nMaxFile        = MAXFILENAME;
                    520:     ofn.lpstrInitialDir = "..\\WAV";
                    521:     ofn.lpstrFileTitle  = szFileTitle;
                    522:     ofn.nMaxFileTitle   = MAXFILENAME;
                    523:     ofn.lpstrTitle      = "Open Sound File";
                    524:     ofn.lpstrDefExt     = "WAV";
                    525:     ofn.Flags           = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY
                    526:                           | OFN_PATHMUSTEXIST | OFN_ENABLEHOOK;
                    527:     ofn.lpfnHook        = (LPOFNHOOKPROC) PlaySoundFileHook;
                    528: 
                    529:     /* Use standard open dialog */
                    530:     if (!GetOpenFileName ((LPOPENFILENAME)&ofn)){
                    531:         *lpstr = NULL;
                    532:         return FALSE;
                    533:     }
                    534: 
                    535:     lstrcpy(lpstr, ofn.lpstrFile);
                    536:     return TRUE;
                    537: 
                    538: }
                    539: 
                    540: 
                    541: #define BUFSIZE 1024
                    542: 
                    543: BOOL FillResMenu (HMENU hMenu)
                    544: {
                    545:     HANDLE hBuf;
                    546:     LPSTR lpBuf, lpString;
                    547:     UINT cnt, idMenu;
                    548:         CHAR   tempstring[30];
                    549: 
                    550:     hBuf = GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT, BUFSIZE);
                    551:         if(!hBuf){
                    552:                 return(FALSE);
                    553:         }
                    554:     lpBuf = GlobalLock (hBuf);
                    555: 
                    556:     cnt = GetProfileString ("sounds", NULL, "", lpBuf, BUFSIZE);
                    557:     idMenu = IDM_RESOURCE;
                    558:     if (cnt>0) {
                    559:         lpString = lpBuf;
                    560:         while (*lpString) {
                    561:                                strcpy(tempstring, lpString);   /* this code is a hack for a user bug*/
                    562:                                strcat(tempstring, " ");
                    563:             AppendMenu (hMenu, MF_STRING, idMenu++, tempstring);
                    564:             lpString += lstrlen(lpString) +1;
                    565:         }
                    566:     }
                    567:     idMaxResource = idMenu-1;
                    568: 
                    569:     GlobalUnlock (hBuf);
                    570:     GlobalFree (hBuf);
                    571: 
                    572:     return (idMaxResource > IDM_RESOURCE);
                    573: }
                    574: 
                    575: 
                    576: long FAR PASCAL ChildWndProc (hwnd, iMessage, wParam, lParam)
                    577:      HWND   hwnd;
                    578:      UINT   iMessage;
                    579:      UINT   wParam;
                    580:      LONG   lParam;
                    581: {
                    582: 
                    583: 
                    584: 
                    585:         WORD wmId;
                    586:         WORD wmEvent;
                    587:         HDC    hDc;
                    588:         HICON hIcon;
                    589:         PAINTSTRUCT ps;
                    590:         static BOOL bWindowDone;
                    591:         static BOOL bHideWindow;
                    592:         
                    593:     switch (iMessage) {
                    594: 
                    595:                  case WM_PAINT:
                    596:                          hDc = BeginPaint(hwnd, &ps);
                    597:                          if((hIcon = (HICON) GetWindowLong(hwnd, 0))){
                    598:                                        DrawIcon(ps.hdc, 80, 20, hIcon);
                    599:                          }
                    600:                          EndPaint(hwnd, &ps);
                    601:                          bWindowDone = TRUE;
                    602:                          break;
                    603: 
                    604: 
                    605:                  case WM_TIMER:
                    606:                          /* timer set, because USER coalesces the UNHIDEHIDE, such that
                    607:                             window never showed.  This way, I never issue SW_HIDE, until, the window
                    608:                                  has been shown*/
                    609:                                  
                    610:                          if(bHideWindow == TRUE && bWindowDone == TRUE){
                    611:                                  bWindowDone = FALSE;
                    612:                                  bHideWindow = FALSE;
                    613:                                  SetWindowLong(hwnd, 0, 0);
                    614:                                  ShowWindow(hwnd, SW_HIDE); 
                    615:                          }
                    616:                          break;
                    617:                          
                    618:         case WM_COMMAND:
                    619: #if defined (NT)
                    620:             wmId = LOWORD(wParam);
                    621:             wmEvent = HIWORD(wParam);
                    622: #elif defined (WIN16)
                    623:             wmId = wParam;
                    624:             wmEvent = HIWORD(lParam);
                    625: #endif
                    626: 
                    627:             switch (wmId) {
                    628:                                        case IDM_ICONHAND:
                    629:                                                SetWindowText(hwnd, (LPSTR) lParam);
                    630:                                                hIcon = LoadIcon(NULL, IDI_HAND);
                    631:                                                SetWindowLong(hwnd, 0, (LONG) hIcon);
                    632:                                                break;
                    633:                                                
                    634:                                        case IDM_ICONQUESTION:
                    635:                                                SetWindowText(hwnd, (LPSTR) lParam);
                    636:                                                hIcon = LoadIcon(NULL, IDI_QUESTION);
                    637:                                                SetWindowLong(hwnd, 0, (LONG) hIcon);
                    638:                                                break;
                    639:                                                
                    640:                                        case IDM_ICONEXCLAMATION:
                    641:                                                SetWindowText(hwnd, (LPSTR) lParam);
                    642:                                                hIcon = LoadIcon(NULL, IDI_EXCLAMATION);
                    643:                                                SetWindowLong(hwnd, 0, (LONG) hIcon);
                    644:                                                break;
                    645:                                                
                    646:                                        case IDM_ICONASTERISK:   
                    647:                                                SetWindowText(hwnd, (LPSTR) lParam);
                    648:                                                hIcon = LoadIcon(NULL, IDI_ASTERISK);
                    649:                                                SetWindowLong(hwnd, 0, (LONG) hIcon);
                    650:                                                break;
                    651: 
                    652:                                        case IDM_SYSTEMDEFAULT:         /* for System Default*/
                    653:                                                SetWindowText(hwnd, (LPSTR) lParam);
                    654:                                                SetWindowLong(hwnd, 0, 0);
                    655:                                                break;    /* NO ICON*/
                    656:                                                
                    657:                                        case IDM_HIDE:
                    658:                                                bHideWindow = TRUE;
                    659:                                                break;
                    660: 
                    661:                                        case IDM_UNHIDE:
                    662:                                                ShowWindow(hwnd, SW_SHOW);
                    663:                                                break;
                    664:                                                
                    665:             }
                    666:                                break;
                    667: 
                    668:         default:
                    669:             return DefWindowProc (hwnd, iMessage, wParam, lParam);
                    670:     }
                    671:     return 0L;
                    672: 
                    673: 
                    674: }
                    675: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.