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

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

unix.superglobalmegacorp.com

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