Annotation of os232sdk/toolkt20/c/samples/template/init.c, revision 1.1.1.1

1.1       root        1: /*==============================================================*\
                      2:  *  Init.c - routines for initialization and exit processing
                      3:  *      Created 1989, 1990 Microsoft Corp.
                      4:  *--------------------------------------------------------------
                      5:  *
                      6:  *  This module contains the code for application initialization
                      7:  *  as well as the code for exit list processing
                      8:  *
                      9:  *--------------------------------------------------------------
                     10:  *
                     11:  *  This source file contains the following functions:
                     12:  *
                     13:  *      Init() - initialization routines
                     14:  *      InitMainWindow(hwnd, mp1, mp2)
                     15:  *      ExitProc(usTermCode) - exit list processing procedure
                     16:  *
                     17: \*==============================================================*/
                     18: 
                     19: /*--------------------------------------------------------------*\
                     20:  *  Include files, macros, defined constants, and externs
                     21: \*--------------------------------------------------------------*/
                     22: 
                     23: #define  INCL_WINWINDOWMGR
                     24: #define  INCL_DOSPROCESS
                     25: 
                     26: #include <os2.h>
                     27: #include <string.h>
                     28: #include "main.h"
                     29: #include "xtrn.h"
                     30: 
                     31: /*--------------------------------------------------------------*\
                     32:  *  Global variables
                     33: \*--------------------------------------------------------------*/
                     34: 
                     35: 
                     36: /*--------------------------------------------------------------*\
                     37:  *  Entry point declarations
                     38: \*--------------------------------------------------------------*/
                     39: 
                     40: /****************************************************************\
                     41:  *  Initialization routine
                     42:  *--------------------------------------------------------------
                     43:  *
                     44:  *  Name:   Init()
                     45:  *
                     46:  *  Purpose: Performs initialization functions required
                     47:  *              before the main window can be created.
                     48:  *
                     49:  *  Usage:  Called once before the main window is created.
                     50:  *
                     51:  *  Method:
                     52:  *          - installs the routine ExitProc into the
                     53:  *              DosExitList chain
                     54:  *          - registers all window classes
                     55:  *          - performs any command line processing
                     56:  *
                     57:  *  Returns:
                     58:  *          TRUE - initialization is successful
                     59:  *          FALSE - initialization failed
                     60: \****************************************************************/
                     61: BOOL Init(VOID)
                     62: {
                     63: 
                     64:     /* Add ExitProc to the exit list to handle the exit processing.  If
                     65:      * there is an error, then terminate the process since there have
                     66:      * not been any resources allocated yet
                     67:      */
                     68:     if(DosExitList(EXLST_ADD, (PFNEXITLIST)ExitProc))  {
                     69:         MessageBox(HWND_DESKTOP,
                     70:                    IDMSG_CANNOTLOADEXITLIST,
                     71:                    MB_OK | MB_ERROR,
                     72:                    TRUE);
                     73:         DosExit(EXIT_PROCESS, RETURN_ERROR);
                     74:     }
                     75: 
                     76:     /* initialize the print dialog structures */
                     77:     InitPrintingDialogs();
                     78: 
                     79:     /* load application name from resource file */
                     80:     if(!WinLoadString(hab, NULL, IDS_APPNAME, MAXNAMEL, szAppName))
                     81:         return FALSE;
                     82: 
                     83:     /* load "untitled" string */
                     84:     if(!WinLoadString(hab, NULL, IDS_UNTITLED, MESSAGELEN, szUntitled))
                     85:         return FALSE;
                     86: 
                     87:     /* register the main client window class */
                     88:     if(!WinRegisterClass(hab,
                     89:                         (PSZ)szAppName,
                     90:                         (PFNWP)MainWndProc,
                     91:                         CS_SIZEREDRAW | CS_CLIPCHILDREN,
                     92:                         0))  {
                     93:         return FALSE;
                     94:     }
                     95: 
                     96:     /* If you wish to create a thread for background processing, define
                     97:      *  the BACKGROUND_THREAD constant
                     98:      *  the routine commented out here.  The routines for the background
                     99:      *  thread are in the thrd.c file.
                    100:      */
                    101: 
                    102: #ifdef BACKGROUND_THREAD
                    103:     /* see main.h for comment on using a background thread */
                    104: 
                    105:     if(!CreateBackgroundThread())
                    106:         return FALSE;
                    107: 
                    108: #endif
                    109: 
                    110:     /*--------------------------------------------------*\
                    111:      *      Add any command line processing here
                    112:     \*--------------------------------------------------*/
                    113: 
                    114: 
                    115:     return TRUE;
                    116: 
                    117: }  /* Init() */
                    118: 
                    119: /****************************************************************\
                    120:  *  Initialization routine
                    121:  *--------------------------------------------------------------
                    122:  *
                    123:  *  Name:   InitMainWindow(hwnd, mp1, mp2)
                    124:  *
                    125:  *  Purpose: Performs initialization functions required
                    126:  *              when the main window is created.
                    127:  *
                    128:  *  Usage:  Called once during the WM_CREATE processing when
                    129:  *          the main window is created.
                    130:  *
                    131:  *  Method:
                    132:  *
                    133:  *  Returns: value to be returned from the WM_CREATE message:
                    134:  *          TRUE - window creation should stop
                    135:  *          FALSE - window creation should continue
                    136: \****************************************************************/
                    137: MRESULT InitMainWindow(hwnd, mp1, mp2)
                    138: HWND hwnd;      /* handle to the main client window */
                    139: MPARAM mp1;     /* first parameter of WM_CREATE message */
                    140: MPARAM mp2;     /* second parameter of WM_CREATE message */
                    141: {
                    142: 
                    143:     UpdateTitleText(((PCREATESTRUCT)PVOIDFROMMP(mp2))->hwndParent);
                    144: 
                    145:     /* return FALSE to continue window creation, TRUE to abort it */
                    146:     return (MRESULT)FALSE;
                    147: 
                    148: 
                    149: 
                    150:     /* This routine currently doesn't use the hwnd, mp1, and mp2 parameters *\
                    151:      *  so they are referenced here to prevent an 'Unreferenced Parameter'
                    152:     \*  warning at compile time                                             */
                    153: 
                    154:     hwnd;
                    155:     mp1;
                    156:     mp2;
                    157: 
                    158: 
                    159: }   /* InitMainWindow() */
                    160: 
                    161: 
                    162: /****************************************************************\
                    163:  *  Exit list processing procedure
                    164:  *--------------------------------------------------------------
                    165:  *
                    166:  *  Name:   ExitProc(usTermCode)
                    167:  *
                    168:  *  Purpose: Cleans up certain resources when the application
                    169:  *              terminates
                    170:  *
                    171:  *  Usage:  Routine is called by DosExitList when the
                    172:  *          application exits
                    173:  *
                    174:  *  Method: global resources, such as the main window and
                    175:  *          message queue, are destroyed and any system
                    176:  *          resources used are freed
                    177:  *
                    178:  *  Returns:  Returns EXLST_EXIT to the DosExitList handler
                    179:  *
                    180: \****************************************************************/
                    181: 
                    182: VOID PASCAL ExitProc(usTermCode)
                    183: USHORT usTermCode;      /* code for the reason for termination */
                    184: {
                    185: 
                    186:     /* destroy the main window if it exists */
                    187:     if(WinIsWindow(hab, hwndMainFrame))  {
                    188:         WinDestroyWindow(hwndMainFrame);
                    189:     }
                    190: 
                    191:     /*--------------------------------------------------*\
                    192:      *      Any other system resources used
                    193:      *      (e.g. memory or files) should be freed here
                    194:     \*--------------------------------------------------*/
                    195: 
                    196: 
                    197:     WinDestroyMsgQueue(hmq);
                    198: 
                    199:     WinTerminate(hab);
                    200: 
                    201:     DosExitList(EXLST_EXIT, 0L);    /* termination complete */
                    202: 
                    203: 
                    204: 
                    205:     /* This routine currently doesn't use the usTermCode parameter so *\
                    206:      *  it is referenced here to prevent an 'Unreferenced Parameter'
                    207:     \*  warning at compile time                                       */
                    208: 
                    209:     usTermCode;
                    210: 
                    211: }   /* ExitProc() */

unix.superglobalmegacorp.com

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