home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / STYLE.ZIP / STY_INIT.C < prev    next >
C/C++ Source or Header  |  1992-03-30  |  8KB  |  225 lines

  1. /*************************************************************************
  2. *
  3. *  File Name   : STY_INIT.C
  4. *
  5. *  Description : This module contains the code for application
  6. *                initialization as well as the code for exit list
  7. *                processing
  8. *
  9. *  Concepts    : Application initialization and Exit list processing
  10. *
  11. *  API's       : DosExit
  12. *                DosExitList
  13. *                WinCreateWindow
  14. *                WinDestroyMsgQueue
  15. *                WinDistroyWindow
  16. *                WinIsWindow
  17. *                WinLoadString
  18. *                WinQueryWindowRect
  19. *                WinRegisterClass
  20. *                WinTerminate
  21. *
  22. *  Copyright (C) 1992 IBM Corporation
  23. *
  24. *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  25. *      sample code created by IBM Corporation. This sample code is not
  26. *      part of any standard or IBM product and is provided to you solely
  27. *      for  the purpose of assisting you in the development of your
  28. *      applications.  The code is provided "AS IS", without
  29. *      warranty of any kind.  IBM shall not be liable for any damages
  30. *      arising out of your use of the sample code, even if they have been
  31. *      advised of the possibility of such damages.                                                    *
  32. *
  33. ************************************************************************/
  34.  
  35. /*  Include files, macros, defined constants, and externs               */
  36.  
  37. #define  INCL_WINWINDOWMGR
  38. #define  INCL_WINMLE
  39. #define  INCL_DOSPROCESS
  40.  
  41. #include <os2.h>
  42. #include <string.h>
  43. #include "sty_main.h"
  44. #include "sty_xtrn.h"
  45. #include "sty_dlg.h"
  46.  
  47. #define RETURN_ERROR        1               /* error return in DosExit  */
  48.  
  49. /*  Global variables                                                    */
  50.  
  51. HWND hwndMLE;
  52. extern LONG lClrForeground;                         /* color for window text */
  53. extern LONG lClrBackground;                          /* color for background */
  54. extern LONG lClrDefaultForeground;                  /* color for window text */
  55. extern LONG lClrDefaultBackground;                   /* color for background */
  56.  
  57. /*********************************************************************
  58.  *  Name: Init
  59.  *
  60.  *  Description : Performs initialization functions required
  61.  *                before the main window can be created.
  62.  *
  63.  *  Concepts :  Window class registration and addition of exit
  64.  *              procedure to Exit list.
  65.  *
  66.  *  API's : DosExit
  67.  *          DosExitList
  68.  *          WinLoadString
  69.  *          WinRegisterClass
  70.  *
  71.  *  Parameters :  None
  72.  *
  73.  *  Returns: TRUE  - initialization is successful
  74.  *           FALSE - initialization failed
  75.  *
  76.  ****************************************************************/
  77. BOOL Init(VOID)
  78. {
  79.     /* Add ExitProc to the exit list to handle the exit processing.  If
  80.      * there is an error, then terminate the process since there have
  81.      * not been any resources allocated yet
  82.      */
  83.     if(DosExitList(EXLST_ADD, (PFNEXITLIST)ExitProc))  {
  84.         MessageBox(HWND_DESKTOP,
  85.                    IDMSG_CANNOTLOADEXITLIST,
  86.                    MB_OK | MB_ERROR,
  87.                    TRUE);
  88.         DosExit(EXIT_PROCESS, RETURN_ERROR);
  89.     }
  90.  
  91.     /* load application name from resource file */
  92.     if(!WinLoadString(hab, (HMODULE)0, IDS_APPNAME, MAXNAMEL, szAppName))
  93.         return FALSE;
  94.  
  95.     /* load "untitled" string */
  96.     if(!WinLoadString(hab, (HMODULE)0, IDS_UNTITLED, MESSAGELEN, szUntitled))
  97.         return FALSE;
  98.  
  99.     /* register the main client window class */
  100.     if(!WinRegisterClass(hab,
  101.                         (PSZ)szAppName,
  102.                         (PFNWP)MainWndProc,
  103.                         CS_SIZEREDRAW | CS_CLIPCHILDREN,
  104.                         0))  {
  105.         return FALSE;
  106.     }
  107.  
  108.     /*
  109.      * Add any command line processing here
  110.      */
  111.     return TRUE;
  112. }               /* End of Init()          */
  113.  
  114. /*********************************************************************
  115.  *  Name: InitMainWindow
  116.  *
  117.  *  Description : Performs initialization functions required
  118.  *                when the main window can be created.
  119.  *
  120.  *  Concepts : Performs initialization functions required
  121.  *             when the main window is created.  Called once
  122.  *             during the WM_CREATE processing when the main
  123.  *             window is created.
  124.  *
  125.  *
  126.  *  API's : WinQueryWindowRect
  127.  *          WinCreateWindow
  128.  *
  129.  *  Parameters : hwnd - client window handle
  130.  *               mp1 - First message parameter
  131.  *               mp2 - Second message parameter
  132.  *
  133.  *  Returns: TRUE  - initialization failed
  134.  *           FALSE - initialization is successful
  135.  *
  136.  ****************************************************************/
  137. MRESULT InitMainWindow(HWND hwnd, MPARAM mp1, MPARAM mp2)
  138. {
  139.     RECTL rcl;
  140.  
  141.     UpdateTitleText(((PCREATESTRUCT)PVOIDFROMMP(mp2))->hwndParent);
  142.  
  143.     WinQueryWindowRect(hwnd, (PRECTL)&rcl);
  144.  
  145.     /* create MLE window the same size as the client */
  146.  
  147.     hwndMLE = WinCreateWindow(hwnd, WC_MLE, (PSZ)NULL,
  148.                               MLS_HSCROLL | MLS_VSCROLL | WS_VISIBLE,
  149.                               (SHORT)rcl.xLeft, (SHORT)rcl.yBottom,
  150.                               (SHORT)rcl.xRight, (SHORT)rcl.yTop,
  151.                               hwnd, HWND_TOP, ID_MLE, NULL, NULL);
  152.     if(!hwndMLE)
  153.         return (MRESULT)TRUE;
  154.  
  155.     /*
  156.      * Set default colors
  157.      */
  158.  
  159.     WinSendMsg(hwndMLE, MLM_SETTEXTCOLOR, MPFROMLONG(lClrDefaultForeground),
  160.                                                                         NULL);
  161.     WinSendMsg(hwndMLE, MLM_SETBACKCOLOR, MPFROMLONG(lClrDefaultBackground),
  162.                                                                         NULL);
  163.     WinSendMsg(hwndMLE, MLM_RESETUNDO, NULL, NULL);
  164.  
  165.     /* return FALSE to continue window creation, TRUE to abort it */
  166.     return (MRESULT)FALSE;
  167.  
  168.     /*
  169.      *  This routine currently doesn't use the mp1 and mp2 parameters so
  170.      *  it is referenced here to prevent an 'Unreferenced Parameter'
  171.      *  warning at compile time
  172.      */
  173.     mp1;
  174.     mp2;
  175. }        /* End of InitMainWindow() */
  176.  
  177. /*********************************************************************
  178.  *  Name:  ExitProc
  179.  *
  180.  *  Description : Cleans up certain resources when the
  181.  *                application terminates
  182.  *
  183.  *  Concepts : Global resources, such as the main window an
  184.  *             message queue, are destroyed and any system
  185.  *             resources used are freed
  186.  *
  187.  *  API's : WinIsWindow
  188.  *          WinDestroyWindow
  189.  *          WinDestroyMsgQueue
  190.  *          WinTerminate
  191.  *          DosExitList
  192.  *
  193.  *  Parameters : USHORT -  termination code
  194.  *
  195.  *  Returns:  Returns EXLST_EXIT to the DosExitList handler
  196.  *
  197.  ****************************************************************/
  198. VOID APIENTRY ExitProc(USHORT usTermCode)
  199. {
  200.  /* destroy the main window if it exists                       */
  201.     if(WinIsWindow(hab, hwndMainFrame))
  202.         WinDestroyWindow(hwndMainFrame);
  203.  
  204.     /*
  205.      *      Any other system resources used
  206.      *      (e.g. memory or files) should be freed here
  207.      */
  208.  
  209.     WinDestroyMsgQueue(hmq);
  210.  
  211.     WinTerminate(hab);
  212.  
  213.     /*
  214.      * Termination complete
  215.      */
  216.     DosExitList(EXLST_EXIT, (PFNEXITLIST)ExitProc);
  217.  
  218.     /*
  219.      * This routine currently doesn't use the usTermCode parameter so
  220.      *  it is referenced here to prevent an 'Unreferenced Parameter'
  221.      *  warning at compile time
  222.      */
  223.     usTermCode;
  224. }                                  /*     End of ExitProc()           */
  225.