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