home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / gpiimage.zip / IMG_INIT.C < prev    next >
C/C++ Source or Header  |  1998-04-20  |  10KB  |  316 lines

  1. /**************************************************************************
  2.  *  File name  :  img_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.  *                Functions contained here:
  8.  *
  9.  *                Init()
  10.  *                InitMainWindow()
  11.  *                InitClientArea(hwnd)
  12.  *                InitGlobalVars()
  13.  *
  14.  *  Concepts   :  initialization, subclassing
  15.  *
  16.  *  API's      :  DosExitList
  17.  *                DosExit
  18.  *                WinRegisterClass
  19.  *                WinLoadString
  20.  *                WinCreateStdWindow
  21.  *                WinWindowFromID
  22.  *                WinSetParent
  23.  *                WinSendMsg
  24.  *                WinSubclassWindow
  25.  *                WinOpenWindowDC
  26.  *                GpiCreatePS
  27.  *                GpiSetColor
  28.  *                GpiSetBackColor
  29.  *                GpiSetBackMix
  30.  *                WinQuerySysValue
  31.  *                WinQuerySysPointer
  32.  *
  33.  *  Required
  34.  *    Files    :  OS2.H, IMG_MAIN.H, IMG_XTRN.H
  35.  *
  36.  *  Copyright (C) 1991 IBM Corporation
  37.  *
  38.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  39.  *      sample code created by IBM Corporation. This sample code is not
  40.  *      part of any standard or IBM product and is provided to you solely
  41.  *      for  the purpose of assisting you in the development of your
  42.  *      applications.  The code is provided "AS IS", without
  43.  *      warranty of any kind.  IBM shall not be liable for any damages
  44.  *      arising out of your use of the sample code, even if they have been
  45.  *      advised of the possibility of such damages.                                                    *
  46.  *************************************************************************/
  47. /*
  48.  *  Include files, macros, defined constants, and externs
  49.  */
  50. #define INCL_DOSPROCESS
  51. #define INCL_DOSERRORS
  52. #define INCL_WINWINDOWMGR
  53. #define INCL_WINFRAMEMGR
  54. #define INCL_WINSYS
  55. #define INCL_WINPOINTERS
  56. #define INCL_WINSTDFILE
  57. #define INCL_GPIPRIMITIVES
  58.  
  59. #include <os2.h>
  60.  
  61. #include "img_main.h"
  62. #include "img_xtrn.h"
  63.  
  64. /*
  65.  *  Entry point declarations
  66.  */
  67. BOOL InitMainWindow(VOID);
  68. BOOL InitGlobalVars(VOID);
  69. BOOL InitClientArea(HWND hwnd);
  70.  
  71. /*
  72.  *  static variables
  73.  */
  74. CHAR szAppName[CCHAPPNAME];                /* application title */
  75. #define RETURN_ERROR        1        /* error return in DosExit */
  76.  
  77. /**************************************************************************
  78.  *
  79.  *  Name       : Init()
  80.  *
  81.  *  Description: Performs initialization functions.
  82.  *
  83.  *  Concepts   : Called once before the main window is created.
  84.  *               - register all window classes
  85.  *               - setup main application window
  86.  *               - set global variables
  87.  *
  88.  *  API's      :  DosExitList
  89.  *                DosExit
  90.  *                WinRegisterClass
  91.  *                WinLoadString
  92.  *
  93.  *  Parameters :  [none]
  94.  *
  95.  *  Return     :  NO_ERROR  - initiaization is successful
  96.  *                String_ID - initialization failed
  97.  *
  98.  *************************************************************************/
  99. #ifdef PORT_16
  100. USHORT Init(VOID)
  101. #endif
  102. #ifdef PORT_32
  103. ULONG Init(VOID)
  104. #endif
  105. {
  106.     /* Add ExitProc to the exit list to handle the exit processing.  If
  107.      * there is an error, then terminate the process since there have
  108.      * not been any resources allocated yet
  109.      */
  110.    if (DosExitList(EXLST_ADD, (PFNEXITLIST)ExitProc))
  111.    {
  112.        MessageBox(HWND_DESKTOP,
  113.                   IDMSG_CANNOTLOADEXITLIST, 0,
  114.                   MB_OK | MB_ERROR,
  115.                   TRUE);
  116.        DosExit(EXIT_PROCESS, RETURN_ERROR);
  117.    }
  118.  
  119.    /* load application name from resource file */
  120.    if(0==WinLoadString(vhab, (HMODULE)NULL, IDS_APPNAME, CCHAPPNAME, szAppName))
  121.        return IDMSG_CANNOTLOADSTRING;
  122.  
  123.    /* register the main client window class */
  124.    if (!WinRegisterClass(vhab,
  125.                 szAppName,
  126.                 (PFNWP)MainWndProc,
  127.                 0L,
  128.                 0))
  129.        return IDMSG_INITFAILED;
  130.  
  131.    /*
  132.     * create main application window & detach scrollbars
  133.     */
  134.    if (!InitMainWindow())
  135.        return IDMSG_MAINWINCREATEFAILED;
  136.  
  137.    /*
  138.     * set up globals used for sizing & system pointers
  139.     */
  140.    if (!InitGlobalVars())
  141.       return IDMSG_INITFAILED;
  142.  
  143.    /*
  144.     * this function prepares the application for loading images
  145.     */
  146.    InitClientArea(vhwndClient);
  147.  
  148.    /*
  149.     * initialize help mechanism
  150.     */
  151. #ifdef HELP_MANAGER_ENABLED
  152.    HelpInit();
  153. #endif
  154.  
  155.    return NO_ERROR;
  156. }  /* End of Init */
  157.  
  158. /**************************************************************************
  159.  *
  160.  *  Name       : InitMainWindow()
  161.  *
  162.  *  Description: Creates the application window and puts it into
  163.  *               its initial state.
  164.  *
  165.  *  Concepts   : Called once by the Init() routine
  166.  *               - create main application window
  167.  *               - detach scrollbars from window
  168.  *               - subclass frame window procedure
  169.  *
  170.  *  API's      :  WinCreateStdWindow
  171.  *                WinWindowFromID
  172.  *                WinSetParent
  173.  *                WinSendMsg
  174.  *                WinRegisterClass
  175.  *                WinSubclassWindow
  176.  *
  177.  *  Parameters :  [none]
  178.  *
  179.  *  Return     :  TRUE - window successfully created
  180.  *                FALSE - window creation failed
  181.  *
  182.  *************************************************************************/
  183. BOOL InitMainWindow(VOID)
  184. {
  185.    ULONG ctlData = FCF_STANDARD | FCF_VERTSCROLL | FCF_HORZSCROLL;
  186.  
  187.    /*
  188.     * Create a window with standard controls.
  189.     */
  190.    vhwndFrame = WinCreateStdWindow(
  191.                          HWND_DESKTOP,
  192.                          WS_VISIBLE,
  193.                          (PULONG)&ctlData,
  194.                          (PSZ)szAppName,
  195.                          (PSZ)NULL,
  196.                          WS_VISIBLE,
  197.                          (HMODULE)NULL,
  198.                          IDR_MAIN,
  199.                          (PHWND)&vhwndClient);
  200.    if (!vhwndFrame)
  201.       return FALSE;
  202.  
  203.    /*
  204.     * for the time being detach the scrollbars from the main
  205.     * window - but remember their handles for later
  206.     */
  207.    vhwndVScroll = WinWindowFromID(vhwndFrame, FID_VERTSCROLL);
  208.    vhwndHScroll = WinWindowFromID(vhwndFrame, FID_HORZSCROLL);
  209.    WinSetParent(vhwndVScroll, HWND_OBJECT, FALSE);
  210.    WinSetParent(vhwndHScroll, HWND_OBJECT, FALSE);
  211.    WinSendMsg(vhwndFrame, WM_UPDATEFRAME,
  212.               MPFROMLONG(FCF_VERTSCROLL | FCF_HORZSCROLL), (MPARAM)NULL);
  213.  
  214.    /* save menubar handle */
  215.    vhwndMenu = WinWindowFromID(vhwndFrame, FID_MENU);
  216.  
  217.    /*
  218.     * the frame window procedure is subclassed, so that frame-sizing
  219.     * restrictions can be implemented.
  220.     */
  221.    if (!WinRegisterClass(vhab, "SUBFRAME", (PFNWP)FrameWndProc, 0L, 0))
  222.       return FALSE;
  223.  
  224.    vpfnwpFrame = WinSubclassWindow(vhwndFrame, (PFNWP)FrameWndProc);
  225.  
  226.    return TRUE;
  227. } /* End of InitMainWindow() */
  228.  
  229. /**************************************************************************
  230.  *
  231.  *  Name       : InitClientArea()
  232.  *
  233.  *  Description: Prepares the client area to accept the images
  234.  *
  235.  *  Concepts   : Called once by the Init() routine
  236.  *               - obtain a window device context
  237.  *               - define the image presentation space
  238.  *               - associate the two
  239.  *               - set foreground/background colours &
  240.  *                 background mix for the presentation space
  241.  *
  242.  *  API's      :  WinOpenWindowDC
  243.  *                GpiCreatePS
  244.  *                GpiSetColor
  245.  *                GpiSetBackColor
  246.  *                GpiSetBackMix
  247.  *
  248.  *  Parameters :  hwnd = client window handle
  249.  *
  250.  *  Return     :  TRUE - client area successfully set up
  251.  *                FALSE - client area setup failed
  252.  *
  253.  *************************************************************************/
  254. BOOL InitClientArea(HWND hwnd)
  255. {
  256.    SIZEL  sizl;
  257.  
  258.    sizl.cx = 0L;                /* set size to default for device    */
  259.    sizl.cy = 0L;                /*  (full screen)                    */
  260.  
  261.    vhdc = WinOpenWindowDC(hwnd);
  262.    if (!vhdc)
  263.        return FALSE;
  264.  
  265.    vhps = GpiCreatePS(vhab,
  266.                       vhdc,
  267.                       &sizl,
  268.                       (ULONG)PU_PELS | GPIT_NORMAL | GPIA_ASSOC
  269.                       );
  270.    if (!vhps)
  271.        return FALSE;
  272.  
  273.    GpiSetColor(vhps, vlForeClr);
  274.    GpiSetBackColor(vhps, vlBackClr);
  275.    GpiSetBackMix(vhps, BM_OVERPAINT);
  276.  
  277.    return TRUE;
  278. }   /* End of InitClientArea */
  279.  
  280. /**************************************************************************
  281.  *
  282.  *  Name       : InitGlobalVars()
  283.  *
  284.  *  Description: Performs initialization of the application  s
  285.  *               global variables
  286.  *
  287.  *  Concepts   : Called once by the Init() routine
  288.  *
  289.  *  API's      :  WinQuerySysValue
  290.  *                WinQuerySysPointer
  291.  *
  292.  *  Parameters :  [none]
  293.  *
  294.  *  Return     :  TRUE - initialization is successful
  295.  *                FALSE - initialization failed
  296.  *
  297.  *************************************************************************/
  298. BOOL InitGlobalVars(VOID)
  299. {
  300.    /* load system sizes */
  301.    vlXScreen = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  302.    vlYScreen = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  303.    vlcxVScroll = WinQuerySysValue(HWND_DESKTOP, SV_CXVSCROLL);
  304.    vlcyHScroll = WinQuerySysValue(HWND_DESKTOP, SV_CYHSCROLL);
  305.    vlcyTitle = WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR);
  306.    vlcyMenu = WinQuerySysValue(HWND_DESKTOP, SV_CYMENU);
  307.    vlcxBorder = WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER);
  308.    vlcyBorder = WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER);
  309.  
  310.    /* load system pointers */
  311.    vhptrArrow = WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE);
  312.    vhptrWait = WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT, FALSE);
  313.    return TRUE;
  314. } /* End of InitGlobalVars  */
  315. /***************************  End of img_init.c  *************************/
  316.