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

  1. /**************************************************************************
  2.  *  File name  :  img_main.c
  3.  *
  4.  *  Description:  This application serves as an example of porting a 16-bit
  5.  *                application to 32-bit.  It modifies a 16-bit application
  6.  *                which was built using the headers/libraries/tools
  7.  *                from the OS/2 1.3 toolkit and produces a pure 32-bit
  8.  *                application.
  9.  *
  10.  *                This source file contains the following functions:
  11.  *
  12.  *                main()
  13.  *                MainWndProc(hwnd, msg, mp1, mp2)
  14.  *                FrameWndProc(hwnd, msg, mp1, mp2)
  15.  *                MessageBox(hwnd idMsg, fsStyle, fBeep)
  16.  *                MainCommand(mp1, mp2)
  17.  *                ExitProc(usTermCode)
  18.  *
  19.  *  Concepts   :  porting
  20.  *
  21.  *  API's      :  WinInitialize
  22.  *                DosBeep
  23.  *                WinCreateMsgQueue
  24.  *                WinGetMsg
  25.  *                WinTerminate
  26.  *                WinDispatchMsg
  27.  *                WinBeginPaint
  28.  *                WinFillRect
  29.  *                WinEndPaint
  30.  *                WinInvalidateRect
  31.  *                GpiAssociate
  32.  *                GpiDestroyPS
  33.  *                GpiSetBitmap
  34.  *                GpiDeleteBitmap
  35.  *                GpiDestroyPS
  36.  *                DevCloseDC
  37.  *                WinIsChild
  38.  *                WinSetParent
  39.  *                WinPostMsg
  40.  *                WinQueryWindowRect
  41.  *                GpiQueryCurrentPosition
  42.  *                WinMapWindowPoints
  43.  *                WinCalcFrameRect
  44.  *                WinLoadMessage
  45.  *                WinAlarm
  46.  *                WinIsWindow
  47.  *                WinDestroyWindow
  48.  *                WinDestroyMsgQueue
  49.  *                DosExitList
  50.  *
  51.  *  Required
  52.  *    Files    :  OS2.H, STRING.H, STDIO.H, IMG_MAIN.H, IMG_XTRN.H,
  53.  *                IMG_HELP.H
  54.  *
  55.  *  Copyright (C) 1991 IBM Corporation
  56.  *
  57.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  58.  *      sample code created by IBM Corporation. This sample code is not
  59.  *      part of any standard or IBM product and is provided to you solely
  60.  *      for  the purpose of assisting you in the development of your
  61.  *      applications.  The code is provided "AS IS", without
  62.  *      warranty of any kind.  IBM shall not be liable for any damages
  63.  *      arising out of your use of the sample code, even if they have been
  64.  *      advised of the possibility of such damages.                                                    *
  65.  *************************************************************************/
  66. /*
  67.  *  Include files, macros, defined constants, and externs
  68.  */
  69. #define INCL_DOSPROCESS
  70. #define INCL_WINWINDOWMGR
  71. #define INCL_WINFRAMEMGR
  72. #define INCL_WINSYS
  73. #define INCL_WINTRACKRECT
  74. #define INCL_WINHELP
  75. #define INCL_WINSTDFILE
  76. #define INCL_GPIPRIMITIVES
  77. #define INCL_GPIBITMAPS
  78.  
  79. /*
  80.  *  Include files, macros, defined constants, and externs
  81.  */
  82. #include <os2.h>
  83. #include <string.h>
  84. #include <stdio.h>
  85.  
  86. #include "img_main.h"
  87. #include "img_xtrn.h"
  88. #include "img_help.h"
  89.  
  90. /*
  91.  *  error defines
  92.  */
  93. #define RETURN_SUCCESS       0  /* successful return in DosExit */
  94. #define RETURN_ERROR         1  /* error return in DosExit      */
  95. #define BEEP_WARN_FREQ      60  /* frequency of warning beep    */
  96. #define BEEP_WARN_DUR      100  /* duration of warning beep     */
  97.  
  98. /*
  99.  *  Entry point declarations
  100.  */
  101. VOID MainCommand(MPARAM mp1, MPARAM mp2);
  102.  
  103. /*
  104.  *  Static variables
  105.  */
  106. HMQ    hmq;           /* application queue handle */
  107.  
  108. /**************************************************************************
  109.  *
  110.  *  Name       : main()
  111.  *
  112.  *  Description: Initializes the PM environment, calls the
  113.  *               initialization routine, creates the main
  114.  *               window,  and polls the message queue
  115.  *
  116.  *  Concepts   : - obtains anchor block handle and creates message
  117.  *                   queue
  118.  *               - calls the initialization routine
  119.  *               - creates the main frame window which creates the
  120.  *                   main client window
  121.  *               - polls the message queue via Get/Dispatch Msg loop
  122.  *               - upon exiting the loop, exits
  123.  *
  124.  *  API's      :  WinInitialize
  125.  *                DosBeep
  126.  *                WinCreateMsgQueue
  127.  *                WinGetMsg
  128.  *                WinTerminate
  129.  *                WinDispatchMsg
  130.  *
  131.  *  Parameters :  [none]
  132.  *
  133.  *  Return     :  1 - if successful execution completed
  134.  *                0 - if error
  135.  *
  136.  *************************************************************************/
  137. int main(void)
  138. {
  139.    QMSG   qmsg;          /* message structure */
  140. #ifdef PORT_16
  141.    USHORT rc;
  142. #endif
  143. #ifdef PORT_32
  144.    ULONG  rc;
  145. #endif
  146.  
  147.    vhab = WinInitialize(0);
  148.    if(!vhab)
  149.    {
  150.        DosBeep(BEEP_WARN_FREQ, BEEP_WARN_DUR);
  151.        return RETURN_ERROR;
  152.    }
  153.  
  154.    /* find a define for this v */
  155.    hmq = WinCreateMsgQueue(vhab, 0);
  156.    if(!hmq)
  157.    {
  158.        DosBeep(BEEP_WARN_FREQ, BEEP_WARN_DUR);
  159.        WinTerminate(vhab);
  160.        return RETURN_ERROR;
  161.    }
  162.  
  163.    if(rc = Init())
  164.    {
  165.        MessageBox(HWND_DESKTOP, rc, 0, MB_OK | MB_ERROR, TRUE);
  166.    }
  167.    else
  168.    {
  169.        /* get/dispatch message loop */
  170.        while (WinGetMsg(vhab, &qmsg, (HWND)NULL, 0, 0))
  171.           WinDispatchMsg(vhab, &qmsg);
  172.    }
  173.  
  174.   /*
  175.    * release any allocated resource - no need to check return codes
  176.    */
  177. #ifdef HELP_MANAGER_ENABLED
  178.     /* destroy the help instance */
  179.    HelpDestroyInstance();
  180. #endif
  181.    return RETURN_SUCCESS;
  182. }   /* End of main */
  183.  
  184. /**************************************************************************
  185.  *
  186.  *  Name       : MainWndProc(hwnd, msg, mp1, mp2)
  187.  *
  188.  *  Description: Processes the messages sent to the main client
  189.  *               window.  This routine processes the basic
  190.  *               messages all client windows should process
  191.  *               and passes all others onto UserWndProc where
  192.  *               the developer can process any others.
  193.  *
  194.  *  Concepts   : Called for each message placed in the main
  195.  *               window's message queue
  196.  *
  197.  *               A switch statement branches to the routines to be
  198.  *               performed for each message processed.  Any messages
  199.  *               not specifically process are passed to the user's
  200.  *               message processing procedure UserWndProc().
  201.  *
  202.  *  API's      :  WinBeginPaint
  203.  *                WinFillRect
  204.  *                WinEndPaint
  205.  *                WinInvalidateRect
  206.  *                GpiQueryCurrentPosition
  207.  *                WinQueryWindowRect
  208.  *                GpiAssociate
  209.  *                GpiDestroyPS
  210.  *                GpiSetBitmap
  211.  *                GpiDeleteBitmap
  212.  *                GpiAssociate
  213.  *                GpiDestroyPS
  214.  *                DevCloseDC
  215.  *                WinIsChild
  216.  *                WinSetParent
  217.  *                WinPostMsg
  218.  *
  219.  *  Parameters :  hwnd = window handle
  220.  *                msg  = message code
  221.  *                mp1  = first message parameter
  222.  *                mp2  = second message parameter
  223.  *
  224.  *  Return     :  values are determined by each message
  225.  *
  226.  *************************************************************************/
  227. MRESULT EXPENTRY MainWndProc(
  228.              HWND hwnd,      /* handle of window */
  229. #ifdef PORT_16
  230.              USHORT  msg,     /* id of message */
  231. #endif
  232. #ifdef PORT_32
  233.              ULONG  msg,     /* id of message */
  234. #endif
  235.              MPARAM mp1,     /* first message parameter */
  236.              MPARAM mp2)     /* second message parameter */
  237. {
  238.    PSWP    pswp;
  239.    BOOL    fHScroll;
  240.    RECTL   rcl;
  241.    POINTL  ptl;
  242.  
  243.    switch (msg)
  244.    {
  245.        case WM_CREATE:
  246.           /*
  247.            * set application title to 'Untitled'
  248.            */
  249.            UtilUpdateTitleText(vhab,
  250.                                ((PCREATESTRUCT)PVOIDFROMMP(mp2))->hwndParent,
  251.                                "");
  252.  
  253.            /* return FALSE to continue window creation, TRUE to abort it */
  254.            return (MRESULT)FALSE;
  255.            break;
  256.  
  257.        case WM_INITMENU:
  258.  
  259.           /*
  260.            * disable/enable menu items as appropriate
  261.            */
  262.            MenuInit(mp1, mp2);
  263.            break;
  264.  
  265.        case WM_ERASEBACKGROUND:
  266.  
  267.           /*
  268.            * The client window is cleared to SYSCLR_WINDOW
  269.            */
  270.            return (MRESULT)TRUE;
  271.            break;
  272.  
  273.        case WM_MINMAXFRAME:
  274.  
  275.           /*
  276.            * the window can be maximized by double clicking on the
  277.            * title bar, clicking on the maximize icon, or by
  278.            * selecting the maximize option in the System Menu.
  279.            * The SizeCalculateMaxWindow() function is invoked to set the
  280.            * window to a size that is no larger than the loaded image.
  281.            */
  282.            pswp = (PSWP)mp1;
  283. #if (defined(PORT_S132) || defined(PORT_32))
  284.            if (pswp->fl & SWP_MAXIMIZE) {
  285. #else
  286.            if (pswp->fs & SWP_MAXIMIZE) {
  287. #endif
  288.  
  289.               /*
  290.                * disable options which aren't valid when
  291.                * the window is maximized
  292.                */
  293.                vfMaximized = TRUE;
  294.  
  295.                if (vfDetail)
  296.                {
  297.                    SizeCalculateMaxWindow(&rcl);
  298.                    pswp->cy = (SHORT)(rcl.yTop - rcl.yBottom);
  299.                    pswp->cx = (SHORT)(rcl.xRight - rcl.xLeft);
  300.                    pswp->y  = (SHORT)rcl.yBottom;
  301.                    pswp->x  = (SHORT)rcl.xLeft;
  302.                }
  303.            }
  304.            else
  305.  
  306.               /*
  307.                * re-enable options which were invalid when
  308.                * the window was maximized
  309.                */
  310.                vfMaximized = FALSE;
  311.            break;
  312.  
  313.        case WM_PAINT:
  314.  
  315.            WinBeginPaint(hwnd, vhps, (PRECTL)&rcl);
  316.            if (vfImgLoaded && vfDetail)
  317.  
  318.               /*
  319.                * If an image has been loaded and the user has selected
  320.                * the 'Detail' view, the PaintUnSizedImage() function is
  321.                * invoked to draw the image data in the client window.
  322.                * The image is drawn unscaled, and clipped if necessary.
  323.                */
  324.                PaintUnSizedImage();
  325.  
  326.            else if (vfImgLoaded && !vfDetail)
  327.  
  328.               /*
  329.                * If an image has been loaded and the user has selected
  330.                * the 'Non-detailed' view, the PaintSizedImage() function is
  331.                * invoked to size the image and draw it.
  332.                * The image is drawn scaled to fit the window.
  333.                */
  334.                PaintSizedImage();
  335.  
  336.            else
  337.               /*
  338.                * If no image data has been loaded, clear the window to
  339.                * the default system color.
  340.                */
  341.                WinFillRect(vhps, &rcl, SYSCLR_WINDOW);
  342.  
  343.            WinEndPaint(vhps);
  344.            break;
  345.  
  346.        case WM_SIZE:
  347.  
  348.           /*
  349.            * If the window size is altered and the image is being
  350.            * viewed in detail, the WndSize function is invoked to restrict
  351.            * the new window size and scroll-bar range to image limits.
  352.            * If the 'Non-detailed' view has been selected and the window
  353.            * size is altered, the image has to be redrawn to fit the window.
  354.            */
  355.            if (vfImgLoaded && vfDetail)
  356.                SizePositionImage(mp2);
  357.  
  358.            WinInvalidateRect(hwnd, (PRECTL)NULL, FALSE);
  359.            break;
  360.  
  361.        case WM_HSCROLL:
  362.        case WM_VSCROLL:
  363.  
  364.           /*
  365.            * scrolling is implemented only if an image has been
  366.            * loaded, the 'Detail' view has been selected, and there is
  367.            * image data still lying outside window limits.
  368.            */
  369.            fHScroll = (BOOL)(msg == WM_HSCROLL);
  370.            if (vfImgLoaded && vfDetail &&
  371.                (fHScroll ? vulScrollXMax > 0 : vulScrollYMax > 0))
  372.            {
  373.               GpiQueryCurrentPosition(vhps, &ptl);
  374.               WinQueryWindowRect(hwnd, &rcl);
  375.  
  376.                /* call the appropriate scroll routine */
  377.               (fHScroll ? SizeHScroll(mp2, rcl, ptl) :
  378.                           SizeVScroll(mp2, rcl, ptl));
  379.            }
  380.            break;
  381.  
  382.        case WM_DESTROY:
  383.  
  384.           /*
  385.            * delete the image graphics presentation space
  386.            */
  387.            GpiAssociate(vhps, (HDC)NULL);
  388.            GpiDestroyPS(vhps);
  389.  
  390.            if (vfImgLoaded)
  391.            {
  392.               /*
  393.                * Free any allocated memory
  394.                */
  395. #if (defined(PORT_16) || defined(PORT_S132))
  396.                UtilMemoryFree(SELECTOROF(vpbImgBuf));
  397. #else
  398.                UtilMemoryFree(vpbImgBuf);
  399. #endif
  400.  
  401.               /*
  402.                * Release all bit-map resources and close the memory
  403.                * device context
  404.                */
  405.                GpiSetBitmap(vhpsMem, (HBITMAP)NULL);
  406.                GpiDeleteBitmap(vhbm);
  407.                GpiAssociate(vhpsMem, (HDC)NULL);
  408.                GpiDestroyPS(vhpsMem);
  409.                DevCloseDC(vhdcMem);
  410.            }
  411.  
  412.           /*
  413.            * ensure that the scroll bars are child windows of the
  414.            * frame, so that they will be destroyed automatically.
  415.            */
  416.            if (!WinIsChild(vhwndHScroll, vhwndFrame))
  417.            {
  418.                WinSetParent(vhwndVScroll, vhwndFrame, FALSE);
  419.                WinSetParent(vhwndHScroll, vhwndFrame, FALSE);
  420.            }
  421.            break;
  422.  
  423.        case WM_CLOSE:
  424.            WinPostMsg(hwnd, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
  425.            break;
  426.  
  427.        case WM_COMMAND:
  428.  
  429.           /*
  430.            * processing of menu options is required
  431.            */
  432.            MainCommand(mp1, mp2);
  433.            break;
  434.  
  435. #ifdef HELP_MANAGER_ENABLED
  436.  
  437.        case HM_ERROR:
  438.           /*
  439.            * an error has occurred while using IPF help - report
  440.            * the error and destroy the help instance
  441.            */
  442.            MessageBox(vhwndFrame, IDMSG_HELPMANAGERERROR, 0,
  443.                       MB_OK | MB_ERROR, TRUE);
  444.            vfHelpEnabled = FALSE;
  445.            break;
  446. #endif
  447.        default:
  448.  
  449.            /*
  450.             * default must call WinDefWindowProc()
  451.             */
  452.           return WinDefWindowProc(hwnd, msg, mp1, mp2);
  453.           break;
  454.    }
  455.    return (MRESULT)NULL; /* window procedures should return 0 as a default */
  456. }   /* End of MainWndProc */
  457.  
  458. /**************************************************************************
  459.  *
  460.  *  Name       : FrameWndProc(hwnd, msg, mp1, mp2)
  461.  *
  462.  *  Description: The purpose of the frame-window subclass procedure
  463.  *               is to restrict frame-window sizing so that it is
  464.  *               in step with the size of the client-window
  465.  *               presentation space.  The size of the image
  466.  *               determines the size of the maximized window.
  467.  *               Messages intended for the frame-window procedure
  468.  *               are sent here first.
  469.  *
  470.  *  Concepts   :  Called for each message placed in the main
  471.  *                window's message queue
  472.  *
  473.  *               A switch statement branches to the routines to be
  474.  *               performed for each message processed.  Any messages
  475.  *               not specifically processed are passed to the user's
  476.  *               message processing procedure MainWndProc(). The
  477.  *               message trapped by this wndproc() are
  478.  *               WM_QUERYTRACKINFO & WM_ADJUSTWINDOWPOS which are
  479.  *               both posted to the frame procedure initially to
  480.  *               set up the default values.
  481.  *
  482.  *  API's      :  WinQueryWindowRect(vhwn
  483.  *                GpiQueryCurrentPosition
  484.  *                WinMapWindowPoints
  485.  *                WinCalcFrameRect
  486.  *
  487.  *  Parameters :  hwnd = window handle
  488.  *                msg  = message code
  489.  *                mp1  = first message parameter
  490.  *                mp2  = second message parameter
  491.  *
  492.  *  Return     :  values are determined by each message
  493.  *
  494.  *************************************************************************/
  495. MRESULT EXPENTRY FrameWndProc(
  496.              HWND hwnd,      /* handle of window */
  497. #ifdef PORT_16
  498.              USHORT msg,     /* id of message (16-bit)  */
  499. #endif
  500. #ifdef PORT_32
  501.              ULONG  msg,     /* id of message (32-bit)   */
  502. #endif
  503.              MPARAM mp1,     /* first message parameter */
  504.              MPARAM mp2)     /* second message parameter */
  505. {
  506.    SWP        swp;
  507.    PSWP       pswp;
  508.    RECTL      rcl;
  509.    ULONG      rc;
  510.    POINTL     ptl;
  511.    PTRACKINFO ptrack;
  512.  
  513.    switch(msg)
  514.    {
  515.        case WM_ADJUSTWINDOWPOS:
  516.  
  517.           /*
  518.            * restrict the size of the window so that it never exceeds
  519.            * the maximum size of the image - only handle explicitly
  520.            * for the 'Detail' mode
  521.            */
  522.            if (vfImgLoaded && vfDetail)
  523.            {
  524.                rc = (ULONG)(*vpfnwpFrame)(hwnd, msg, mp1, mp2);
  525.                pswp = (PSWP)mp1;
  526.                swp = *pswp;
  527.  
  528.               /*
  529.                * Find the maximum allowed size, and ensure that
  530.                * the window size never exceeds this.
  531.                */
  532.                SizeCalculateMaxWindow(&rcl);
  533.                if (swp.cx > (SHORT)rcl.xRight)
  534.                    swp.cx = (SHORT)rcl.xRight;
  535.                if (swp.cy > (SHORT)rcl.yTop)
  536.                    swp.cy = (SHORT)rcl.yTop;
  537.                *pswp = swp;
  538.                return (MRESULT)rc;
  539.            }
  540.            else
  541.  
  542.                /* let the system handle the message */
  543.                return (*vpfnwpFrame)(hwnd, msg, mp1, mp2);
  544.  
  545.            break;
  546.  
  547.        case WM_QUERYTRACKINFO:
  548.  
  549.           /*
  550.            * Invoke the normal frame-window procedure first in order
  551.            * to update the tracking rectangle to the new position.
  552.            */
  553.            (*vpfnwpFrame)(hwnd, msg, mp1, mp2);
  554.            ptrack = (PTRACKINFO)mp2;
  555.  
  556.            if (vfImgLoaded && vfDetail)
  557.            {
  558.               /*
  559.                * Limit the size of the bounding rectangle only if the
  560.                * window is being sized.
  561.                * fs and rclBoundary are tracking information structure
  562.                * elements.
  563.                */
  564.                if (((ptrack->fs & TF_MOVE) != TF_MOVE) &&
  565.                    ((ptrack->fs & TF_MOVE)             ||
  566.                     (ptrack->fs & TF_SETPOINTERPOS  )))
  567.                {
  568.                    WinQueryWindowRect(vhwndClient, &rcl);
  569.                    GpiQueryCurrentPosition(vhps, &ptl);
  570.  
  571.                    ptrack->rclBoundary.yTop    = rcl.yBottom + ptl.y;
  572.                    ptrack->rclBoundary.yBottom = rcl.yBottom + ptl.y -
  573.                                                  vsizlImg.cy;
  574.                    ptrack->rclBoundary.xLeft   = rcl.xLeft + ptl.x;
  575.                    ptrack->rclBoundary.xRight  = rcl.xLeft + ptl.x +
  576.                                                  vsizlImg.cx;
  577.  
  578.                   /*
  579.                    * Convert client boundary coordinates to screen
  580.                    * coordinates.
  581.                    */
  582.                    WinMapWindowPoints(vhwndClient,
  583.                                       HWND_DESKTOP,
  584.                                       (PPOINTL)&ptrack->rclBoundary,
  585.                                       sizeof(RECTL)/sizeof(POINTL));
  586.  
  587.                   /*
  588.                    * Calculate equivalent frame boundary from client
  589.                    * boundary data.
  590.                    */
  591.                    WinCalcFrameRect(vhwndFrame,
  592.                                     (PRECTL)&ptrack->rclBoundary,
  593.                                     FALSE);
  594.  
  595.                    ptrack->fs |= TF_ALLINBOUNDARY;
  596.                }
  597.            }
  598.            return (MRESULT)TRUE;
  599.        break;
  600.  
  601.    default:
  602.  
  603.       /*
  604.        * return using the normal frame window procedure
  605.        */
  606.        return (*vpfnwpFrame)(hwnd, msg, mp1, mp2);
  607.        break;
  608.  
  609.    }
  610.    return (MRESULT)NULL; /* window procedures should return 0 as a default */
  611. }   /* End of FrameWndProc */
  612.  
  613. /**************************************************************************
  614.  *
  615.  *  Name       : MessageBox(hwndOwner, idMsg, idCaption, fsStyle, fBeep)
  616.  *
  617.  *  Description: Displays the message box with the message
  618.  *               given in idMsg retrived from the message table
  619.  *               and using the style flags in fsStyle
  620.  *
  621.  *  Concepts   : Called whenever a MessageBox is to be displayed
  622.  *               - Message string is loaded from the process'
  623.  *                   message table
  624.  *               - Alarm beep is sounded if desired
  625.  *               - Message box with the message is displayed
  626.  *               - WinMessageBox return value is returned
  627.  *
  628.  *  API's      :  WinLoadMessage
  629.  *                WinAlarm
  630.  *                WinMessageBox
  631.  *
  632.  *  Parameters :  hwnd      =  handle of the owner of the message box
  633.  *                idMsg     =  i.d. of the message in the message table
  634.  *                idCaption =  i.d. of the caption in the message table
  635.  *                fsStyle   =  style of the message box
  636.  *                fBeep     =  whether to beep before displaying the box
  637.  *
  638.  *  Return     :  the values from WinMessageBox()
  639.  *
  640.  *************************************************************************/
  641. ULONG MessageBox(
  642.          HWND hwndOwner,     /* handle of the message box's owner */
  643. #ifdef PORT_16
  644.          USHORT idMsg,        /* id of the message in the message table */
  645.          USHORT idCaption,    /* id of the caption in the message table */
  646.          USHORT fsStyle,      /* style of the message box */
  647. #endif
  648. #ifdef PORT_32
  649.          ULONG idMsg,        /* id of the message in the message table */
  650.          ULONG idCaption,    /* id of the caption in the message table */
  651.          ULONG fsStyle,      /* style of the message box */
  652. #endif
  653.          BOOL fBeep)         /* if TRUE, beep before message box is displayed */
  654. {
  655.    CHAR szText[MESSAGELEN];
  656.    CHAR szCaption[MESSAGELEN];
  657.  
  658.    if (!WinLoadMessage(vhab,
  659.                        (HMODULE)NULL,
  660.                        idMsg,
  661.                        MESSAGELEN,
  662.                        (PSZ)szText))
  663.    {
  664.        WinAlarm(HWND_DESKTOP, WA_ERROR);
  665.        return MBID_ERROR;
  666.    }
  667.  
  668.   /*
  669.    * if idCaption specified load string else use default
  670.    * caption 'Error!'
  671.    */
  672.    if (idCaption)
  673.    {
  674.        if (!WinLoadMessage(vhab,
  675.                            (HMODULE)NULL,
  676.                            idCaption,
  677.                            MESSAGELEN,
  678.                           (PSZ)szCaption))
  679.        {
  680.            WinAlarm(HWND_DESKTOP, WA_ERROR);
  681.            return MBID_ERROR;
  682.        }
  683.    }
  684.  
  685.    if (fBeep)
  686.        WinAlarm(HWND_DESKTOP, WA_ERROR);
  687.  
  688.    return WinMessageBox(HWND_DESKTOP,
  689.                         hwndOwner,
  690.                         szText,
  691.                         (idCaption ? szCaption : (PSZ)NULL),
  692.                         MSGBOXID,
  693.                         fsStyle);
  694. }   /* End of MessageBox */
  695.  
  696. /**************************************************************************
  697.  *
  698.  *  Name       : MainCommand(mp1, mp2)
  699.  *
  700.  *  Description: Calls the appropriate procedures that deal with
  701.  *               the selected menu item.
  702.  *
  703.  *  Concepts   : Routine is called whenever a WM_COMMAND message
  704.  *               is posted to the main window.
  705.  *
  706.  *               A switch statement branches on the id of the
  707.  *               menu item that posted the message and the
  708.  *               appropriate action for that item is taken.  Any
  709.  *               menu ids that are not part of the standard menu
  710.  *               set are passed onto the user defined WM_COMMAND
  711.  *               processing procedure.
  712.  *
  713.  *  API's      :  [none]
  714.  *
  715.  *  Parameters :  mp1       =  first message parameter
  716.  *                mp2       =  second message parameter
  717.  *
  718.  *  Return     :  [none]
  719.  *
  720.  *************************************************************************/
  721. VOID MainCommand(MPARAM mp1, MPARAM mp2)
  722. {
  723.    switch (SHORT1FROMMP(mp1))
  724.    {
  725.        case IDM_FILEOPEN:
  726.  
  727.           /*
  728.            * Open file and load/draw the selected image
  729.            */
  730.            FileOpen(mp2);
  731.            break;
  732.  
  733.        case IDM_VIEWDETAIL:
  734.  
  735.           /*
  736.            * toggle between Detail and Non-Detail mode
  737.            */
  738.            ViewSwitchMode();
  739.            break;
  740.  
  741.        case IDM_VIEWSAVEPOSITION:
  742.  
  743.           /*
  744.            * save the current image position
  745.            */
  746.            ViewSavePosition();
  747.            break;
  748.  
  749.        case IDM_VIEWRESTOREPOSITION:
  750.  
  751.           /*
  752.            * save the current image position
  753.            */
  754.            ViewRestorePosition();
  755.            break;
  756.  
  757.        case IDM_VIEWFORECOLORBLACK:
  758.        case IDM_VIEWFORECOLORWHITE:
  759.        case IDM_VIEWFORECOLORBLUE:
  760.        case IDM_VIEWFORECOLORGREEN:
  761.        case IDM_VIEWFORECOLORYELLOW:
  762.        case IDM_VIEWFORECOLORRED:
  763.        case IDM_VIEWBACKCOLORBLACK:
  764.        case IDM_VIEWBACKCOLORWHITE:
  765.        case IDM_VIEWBACKCOLORBLUE:
  766.        case IDM_VIEWBACKCOLORGREEN:
  767.        case IDM_VIEWBACKCOLORYELLOW:
  768.        case IDM_VIEWBACKCOLORRED:
  769.            ViewChangeColor(SHORT1FROMMP(mp1));
  770.            break;
  771.  
  772. #ifdef HELP_MANAGER_ENABLED
  773.        case IDM_HELPUSINGHELP:
  774.            HelpUsingHelp();
  775.            break;
  776.  
  777.        case IDM_HELPGENERAL:
  778.            HelpGeneral();
  779.            break;
  780.  
  781.        case IDM_HELPINDEX:
  782.            HelpIndex();
  783.            break;
  784. #endif
  785.        case IDM_HELPPRODUCTINFO:
  786.            HelpProductInfo();
  787.            break;
  788.     }
  789. }   /* End of MainCommand */
  790.  
  791. /**************************************************************************
  792.  *
  793.  *  Name       : ExitProc(usTermCode)
  794.  *
  795.  *  Description: Cleans up certain resources when the application ends
  796.  *
  797.  *  Concepts   : Routine is called by DosExitList when the
  798.  *               application exits
  799.  *
  800.  *               Global resources, such as the main window and
  801.  *               message queue, are destroyed and any system
  802.  *               resources used are freed.
  803.  *
  804.  *  API's      : WinIsWindow
  805.  *               WinDestroyWindow
  806.  *               WinDestroyMsgQueue
  807.  *               WinTerminate
  808.  *               DosExitList
  809.  *
  810.  *  Parameters : usTermCode = the termination code
  811.  *
  812.  *  Return     : EXLST_EXIT to the DosExitList handler
  813.  *
  814.  *************************************************************************/
  815. VOID  ExitProc(USHORT usTermCode)
  816. {
  817.    /* destroy the main window if it exists */
  818.    if (WinIsWindow(vhab, vhwndFrame))
  819.        WinDestroyWindow(vhwndFrame);
  820.  
  821.    WinDestroyMsgQueue(hmq);
  822.    WinTerminate(vhab);
  823.  
  824.    DosExitList(EXLST_EXIT, (PFNEXITLIST)NULL);   /* termination complete */
  825.  
  826.    /* This routine currently doesn't use the usTermCode parameter so
  827.     *  it is referenced here to prevent an 'Unreferenced Parameter'
  828.     *  warning at compile time
  829.     */
  830.    usTermCode;
  831.  
  832. }   /* End of ExitProc */
  833. /***************************  End of img_main.c  *************************/
  834.