home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / startapp.zip / INIT.C < prev    next >
Text File  |  1998-09-10  |  7KB  |  217 lines

  1. /**************************************************************************
  2.  *  File name  :  init.c
  3.  *
  4.  *  Description:  This module contains the code for application
  5.  *                initialization, as well as the code for exit list
  6.  *                processing
  7.  *
  8.  *                This source file contains the following functions:
  9.  *
  10.  *                Init()
  11.  *                InitMainWindow(hwnd, mp1, mp2)
  12.  *                ExitProc(usTermCode)
  13.  *
  14.  *  Concepts   :  initialization
  15.  *
  16.  *  API's      :  DosExitList
  17.  *                DosExit
  18.  *                WinLoadString
  19.  *                WinRegisterClass
  20.  *                WinIsWindow
  21.  *                WinDestroyWindow
  22.  *                WinDestroyMsgQueue
  23.  *                WinTerminate
  24.  *
  25.  *  Required
  26.  *    Files    :  OS2.H, STRING.H, MAIN.H, XTRN.H
  27.  *
  28.  *  (c) Copyright IBM Corp. 1991, 1998  All rights reserved.
  29.  *
  30.  *  These sample programs are owned by International Business Machines
  31.  *  Corporation or one of its subsidiaries ("IBM") and are copyrighted and
  32.  *  licensed, not sold.
  33.  *
  34.  *  You may copy, modify, and distribute these sample programs in any
  35.  *  form without payment to IBM, for any purpose including developing,
  36.  *  using, marketing or distributing programs that include or are
  37.  *  derivative works of the sample programs.
  38.  *
  39.  *  The sample programs are provided to you on an "AS IS" basis, without
  40.  *  warranty of any kind.  IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES,
  41.  *  EITHER EXPRESS OR IMPLIED, INCLUDING , BUT NOT LIMITED TO, THE IMPLIED
  42.  *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  43.  *  Some jurisdictions do not allow for the exclusion or limitation of
  44.  *  implied warranties, so the above limitations or exclusions may not
  45.  *  apply to you.  IBM shall not be liable for any damages you suffer
  46.  *  as a result of using, modifying or distributing the sample programs
  47.  *  or their derivatives.
  48.  *************************************************************************/
  49.  
  50. /*
  51.  *  Include files, macros, defined constants, and externs
  52.  */
  53.  
  54. #define  INCL_WINWINDOWMGR
  55. #define  INCL_WIN /* Or use INCL_WIN, INCL_PM, Also in COMMON section */
  56. #define  INCL_WINLISTBOXES
  57. #define  INCL_DOSPROCESS
  58.  
  59. #include <os2.h>
  60. #include <string.h>
  61. #include "main.h"
  62. #include "xtrn.h"
  63.  
  64. /*
  65.  *  Global variables
  66.  */
  67.  
  68.  
  69. /*
  70.  *  Entry point declarations
  71.  */
  72.  
  73. /**************************************************************************
  74.  *
  75.  *  Name       : Init()
  76.  *
  77.  *  Description:  Performs initialization functions required
  78.  *                before the main window can be created.
  79.  *
  80.  *  Concepts:     Called once before the main window is created.
  81.  *
  82.  *                - Installs the routine ExitProc into the
  83.  *                  DosExitList chain
  84.  *                - registers all window classes
  85.  *                - performs any command line processing
  86.  *
  87.  *  API's      :  DosExitList
  88.  *                DosExit
  89.  *                WinLoadString
  90.  *                WinRegisterClass
  91.  *
  92.  *  Parameters :  [none]
  93.  *
  94.  *  Return     :  TRUE = initialization is successful
  95.  *                FALSE = initialization failed
  96.  *
  97.  *************************************************************************/
  98. BOOL Init(VOID)
  99. {
  100.  
  101.    /* Add ExitProc to the exit list to handle the exit processing.  If
  102.     * there is an error, then terminate the process since there have
  103.     * not been any resources allocated yet.
  104.     */
  105.    if(DosExitList(EXLST_ADD, (PFNEXITLIST)ExitProc))
  106.    {
  107.       MessageBox(HWND_DESKTOP,
  108.                  IDMSG_CANNOTLOADEXITLIST,
  109.                  MB_OK | MB_ERROR,
  110.                  TRUE);
  111.       DosExit(EXIT_PROCESS, RETURN_ERROR);
  112.    }
  113.  
  114.    /* load application name from resource file */
  115.    if(!WinLoadString(hab, (HMODULE)0, IDS_APPNAME, MAXNAMEL, szAppName))
  116.       return FALSE;
  117.  
  118.    /* register the main client window class */
  119.    if(!WinRegisterClass(hab,
  120.                        (PSZ)szAppName,
  121.                        (PFNWP)MainWndProc,
  122.                        CS_SIZEREDRAW | CS_CLIPCHILDREN,
  123.                        0L))
  124.        return FALSE;
  125.  
  126.     /*
  127.      *      Add any command line processing here.
  128.      */
  129.  
  130.  
  131.    return TRUE;
  132. }  /* End of Init   */
  133.  
  134. /**************************************************************************
  135.  *
  136.  *  Name       : InitMainWindow(hwnd, mp1, mp2)
  137.  *
  138.  *  Description: Performs initialization functions required
  139.  *               when the main window is created.
  140.  *
  141.  *  Concepts:    Called once during the WM_CREATE processing when
  142.  *               the main window is created.
  143.  *
  144.  *  API's      : [none]
  145.  *
  146.  *  Parameters :  hwnd = window handle
  147.  *                mp1  = first message parameter
  148.  *                mp2  = second message parameter
  149.  *
  150.  *  Return     :  value to be returned from the WM_CREATE message:
  151.  *                TRUE =  window creation should stop
  152.  *                FALSE = window creation should continue
  153.  *
  154.  *************************************************************************/
  155. MRESULT InitMainWindow(HWND hwnd, MPARAM mp1, MPARAM mp2)
  156. {
  157.  
  158. /**
  159.     Reserved for potential future enhancements
  160. **/
  161.    return (MRESULT)FALSE;
  162.  
  163.    /* This routine currently doesn't use the hwnd, mp1, and mp2 parameters
  164.     *  so they are referenced here to prevent an 'Unreferenced Parameter'
  165.     *  warning at compile time.
  166.     */
  167.  
  168.    hwnd;
  169.    mp1;
  170.    mp2;
  171. }   /* End of InitMainWindow   */
  172. /**************************************************************************
  173.  *
  174.  *  Name       : ExitProc(usTermCode)
  175.  *
  176.  *  Description: Cleans up certain resources when the application
  177.  *               terminates.
  178.  *
  179.  *  Concepts:    Routine is called by DosExitList when the
  180.  *               application exits.
  181.  *
  182.  *               Global resources, such as the main window and
  183.  *               message queue, are destroyed and any system
  184.  *               resources used are freed.
  185.  *
  186.  *  API's      : WinIsWindow
  187.  *               WinDestroyWindow
  188.  *               WinDestroyMsgQueue
  189.  *               WinTerminate
  190.  *               DosExitList
  191.  *
  192.  *  Parameters :  usTermCode = termination code number
  193.  *
  194.  *  Return    :   Returns EXLST_EXIT to the DosExitList handler
  195.  *
  196.  *************************************************************************/
  197. VOID ExitProc(USHORT usTermCode)
  198. {
  199.     /* destroy the main window if it exists */
  200.    if(WinIsWindow(hab, hwndMainFrame))
  201.       WinDestroyWindow(hwndMainFrame);
  202.  
  203.    WinDestroyMsgQueue(hmq);
  204.  
  205.    WinTerminate(hab);
  206.  
  207.    DosExitList(EXLST_EXIT, (PFNEXITLIST)NULL);    /* termination complete */
  208.  
  209.     /* This routine currently doesn't use the usTermCode parameter so
  210.      *  it is referenced here to prevent an 'Unreferenced Parameter'
  211.      *  warning at compile time
  212.      */
  213.  
  214.    usTermCode;
  215. }   /* End of ExitProc    */
  216. /***************************  End of init.c  ***************************/
  217.