Annotation of mstools/samples/playsnd/init.c, revision 1.1

1.1     ! root        1: /*
        !             2:     init.c
        !             3: 
        !             4:     initialisation, termination and error handling code
        !             5: 
        !             6: */
        !             7: 
        !             8: #include <stdio.h>
        !             9: #include <windows.h>
        !            10: #include "PlaySnd.h"
        !            11: #include <stdarg.h>
        !            12: 
        !            13: 
        !            14: /***************************************************************************
        !            15: 
        !            16:     @doc INTERNAL
        !            17: 
        !            18:     @api BOOL | InitApp | Initialise the application.
        !            19: 
        !            20:     @rdesc The return value is TRUE if the application is successfully
        !            21:         initialised, otherwise it is FALSE.
        !            22: 
        !            23: ***************************************************************************/
        !            24: 
        !            25: BOOL InitApp()
        !            26: {
        !            27:     WNDCLASS wc;
        !            28: 
        !            29:     // set up our module handle for resource loading etc.
        !            30: 
        !            31:     ghModule = GetModuleHandle(NULL);
        !            32: 
        !            33:     // get the name of our app
        !            34:     WinEval(LoadString(ghModule, IDS_APPNAME, szAppName, sizeof(szAppName)));
        !            35: 
        !            36:     // load the profile info
        !            37:     bSync = GetProfileInt(szAppName, "bSync", 0);
        !            38:     bNoWait = GetProfileInt(szAppName, "bNoWait", 0);
        !            39:     bResourceID = GetProfileInt(szAppName, "bResourceID", 0);
        !            40: 
        !            41: #ifdef MEDIA_DEBUG
        !            42:     // If we are in DEBUG mode, get debug level for this module
        !            43:     dGetDebugLevel(szAppName);
        !            44:     dprintf("started (debug level %d)", __iDebugLevel);
        !            45: #endif
        !            46: 
        !            47:     // define the class of the main window
        !            48: 
        !            49:     wc.lpszClassName    = szAppName;
        !            50:     wc.style            = CS_HREDRAW | CS_VREDRAW;
        !            51:     wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
        !            52:     wc.hIcon            = LoadIcon(ghModule, MAKEINTRESOURCE(IDI_ICON));
        !            53:     wc.lpszMenuName     = MAKEINTRESOURCE(IDM_MENU); // "Menu";
        !            54:     wc.hbrBackground    = (HBRUSH)(COLOR_APPWORKSPACE+1);
        !            55:     wc.hInstance        = ghModule;
        !            56:     wc.lpfnWndProc      = (WNDPROC)MainWndProc;
        !            57:     wc.cbClsExtra       = 0;
        !            58:     wc.cbWndExtra       = 0;
        !            59: 
        !            60:     WinEval(RegisterClass(&wc));
        !            61: 
        !            62:     // create a window for the application
        !            63: 
        !            64:     ghwndMain = CreateWindow(szAppName,
        !            65:                         szAppName,
        !            66:                         WS_OVERLAPPEDWINDOW,
        !            67:                         GetSystemMetrics(SM_CXSCREEN) / 8,
        !            68:                         GetSystemMetrics(SM_CYSCREEN) / 4,
        !            69:                         GetSystemMetrics(SM_CXSCREEN) * 4 / 5,
        !            70:                         GetSystemMetrics(SM_CYSCREEN) / 3,
        !            71:                         (HWND)NULL,
        !            72:                         (HMENU)NULL,
        !            73:                         ghModule,
        !            74:                         (LPSTR)NULL
        !            75:                         );
        !            76: 
        !            77:     WinAssert(ghwndMain);
        !            78: 
        !            79: #ifdef MEDIA_DEBUG
        !            80:     dDbgSetDebugMenuLevel(__iDebugLevel);   // set debug menu state
        !            81: #endif
        !            82: 
        !            83:     ShowWindow(ghwndMain, SW_SHOWNORMAL);
        !            84:     UpdateWindow(ghwndMain); // paint it
        !            85: 
        !            86: 
        !            87:     return TRUE;
        !            88: }
        !            89: 
        !            90: /***************************************************************************
        !            91: 
        !            92:     @doc INTERNAL
        !            93: 
        !            94:     @api void | CreateApp | Initialise the application when WM_CREATE
        !            95:         message is received.
        !            96: 
        !            97:     @parm HWND | hWnd | Handle to the parent window.
        !            98: 
        !            99:     @rdesc There is no return value.
        !           100: 
        !           101: ***************************************************************************/
        !           102: 
        !           103: void CreateApp(HWND hWnd)
        !           104: {
        !           105:     hWnd;
        !           106: }
        !           107: 
        !           108: /***************************************************************************
        !           109: 
        !           110:     @doc INTERNAL
        !           111: 
        !           112:     @api void | TerminateApp | Terminate the application.
        !           113: 
        !           114:     @parm LPSTR | lpszFormat | A printf style format string
        !           115:     @parm ... | ... | Printf style args
        !           116: 
        !           117:     @rdesc There is no return value.
        !           118: 
        !           119: ***************************************************************************/
        !           120: 
        !           121: void TerminateApp()
        !           122: {
        !           123:     char buf[20];
        !           124: 
        !           125:     // save profile info
        !           126:     sprintf(buf, "%d", bSync);
        !           127:     WriteProfileString(szAppName, "bSync", buf);
        !           128:     sprintf(buf, "%d", bNoWait);
        !           129:     WriteProfileString(szAppName, "bNoWait", buf);
        !           130:     sprintf(buf, "%d", bResourceID);
        !           131:     WriteProfileString(szAppName, "bResourceID", buf);
        !           132: 
        !           133: 
        !           134:     dprintf("ending", szAppName);
        !           135:     dSaveDebugLevel(szAppName);
        !           136: }
        !           137: 
        !           138: /***************************************************************************
        !           139: 
        !           140:     @doc INTERNAL
        !           141: 
        !           142:     @api void | Error | Show an error message box.
        !           143: 
        !           144:     @rdesc There is no return value.
        !           145: 
        !           146: ***************************************************************************/
        !           147: 
        !           148: void Error(LPSTR lpszFormat, ...)
        !           149: {
        !           150:     int i;
        !           151:     char buf[256];
        !           152:     va_list va;
        !           153: 
        !           154:     va_start(va, lpszFormat);
        !           155:     i = vsprintf(buf, lpszFormat, va);
        !           156:     va_end(va);
        !           157: 
        !           158:     MessageBeep(MB_ICONEXCLAMATION);
        !           159:     MessageBox(ghwndMain, buf, szAppName, MB_OK | MB_ICONEXCLAMATION);
        !           160: }
        !           161: 
        !           162: 

unix.superglobalmegacorp.com

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