home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / os2 / semaph / sem_init.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  6KB  |  106 lines

  1. /*static char *SCCSID = "@(#)sem_init.c    6.10 92/02/19";*/
  2. /*==============================================================*\
  3.  *  SEM_INIT.C - routines for initialization and exit processing*
  4.  *      (C) Copyright IBM Corporation 1992.                     *
  5.  *--------------------------------------------------------------*
  6.  *                                                              *
  7.  *  This module contains the code for application initialization*
  8.  *  as well as the code for exit list processing                *
  9.  *                                                              *
  10.  *--------------------------------------------------------------*
  11.  *                                                              *
  12.  *  This source file contains the following functions:          *
  13.  *                                                              *
  14.  *   Init() - initialization routines                           *
  15.  *   ExitProc(usTermCode) - exit list processing procedure      *
  16.  *                                                              *
  17. \*==============================================================*/
  18.  
  19. /*--------------------------------------------------------------*\
  20.  *  Include files, macros, defined constants, and externs       *
  21. \*--------------------------------------------------------------*/
  22. #include "semaph.h"
  23.  
  24. /****************************************************************\
  25.  *  Initialization routine                                      *
  26.  *--------------------------------------------------------------*
  27.  *                                                              *
  28.  *  Name:    Init()                                             *
  29.  *                                                              *
  30.  *  Purpose: Performs initialization functions required before  *
  31.  *           the main window can be created.                    *
  32.  *                                                              *
  33.  *  Usage:   Called once before the main window is created.     *
  34.  *                                                              *
  35.  *  Method:  - installs the routine ExitProc into the           *
  36.  *              DosExitList chain                               *
  37.  *           - registers all window classes                     *
  38.  *           - performs any command line processing             *
  39.  *                                                              *
  40.  *  Returns: TRUE - initialization is successful                *
  41.  *           FALSE - initialization failed                      *
  42.  *                                                              *
  43. \****************************************************************/
  44. BOOL Init(VOID)
  45. {
  46.     /* Add ExitProc to the exit list to handle the exit processing */
  47.     if(DosExitList(EXLST_ADD, ExitProc))
  48.     {
  49.         return FALSE;
  50.     }
  51.                        /* load application name from resource file */
  52.     if(!WinLoadString(hab, (HMODULE)0, IDS_APPNAME, MAXAPPNAMELEN, szAppName))
  53.         return FALSE;
  54.     if(!WinLoadString(hab, 0, IDS_UNTITLED, MESSAGELEN, szUntitled))
  55.         return FALSE;
  56.                           /* register the main client window class */
  57.     if(WinRegisterClass(hab,
  58.                         (PSZ)szAppName,
  59.                         (PFNWP)MainWndProc,
  60.                         CS_SIZEREDRAW | CS_SYNCPAINT | CS_CLIPCHILDREN,
  61.                         0) == 0)
  62.         return FALSE;
  63.  
  64.     return TRUE;
  65. }                                                         /* Init() */
  66.  
  67. /****************************************************************\
  68.  *  Exit list processing procedure                              *
  69.  *--------------------------------------------------------------*
  70.  *                                                              *
  71.  *  Name:    ExitProc(usTermCode)                               *
  72.  *                                                              *
  73.  *  Purpose: Cleans up certain resources when the application   *
  74.  *           terminates                                         *
  75.  *                                                              *
  76.  *  Usage:   Routine is called by DosExitList when the          *
  77.  *           application exits                                  *
  78.  *                                                              *
  79.  *  Method:  global resources, such as the main window and      *
  80.  *           message queue, are destroyed and any system        *
  81.  *           resources used are freed                           *
  82.  *                                                              *
  83.  *  Returns: Returns EXLST_EXIT to the DosExitList handler      *
  84.  *                                                              *
  85. \****************************************************************/
  86. VOID APIENTRY ExitProc(ULONG usTermCode)
  87.                                   /* code for the reason for termination */
  88. {
  89.    WinDestroyWindow(hwndMainFrame);
  90.    /*--------------------------------------------------*\
  91.     *      Any other system resources used             *
  92.     *      (e.g. memory or files) should be freed here *
  93.    \*--------------------------------------------------*/
  94.    WinDestroyMsgQueue(hmq);
  95.  
  96.    WinTerminate(hab);
  97.  
  98.    DosExitList(EXLST_EXIT, (PFNEXITLIST)0L);    /* termination complete */
  99.  
  100.    /* This routine currently doesn't use the usTermCode parameter so *\
  101.     *  it is referenced here to prevent an 'Unreferenced Parameter'  *
  102.    \*  warning at compile time                                       */
  103.  
  104.    return;
  105. }                                                          /* ExitProc() */
  106.