home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / os2 / vmm / vmm_main.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  27KB  |  627 lines

  1. /*static char *SCCSID = "@(#)vmm_main.c    6.19 92/02/18";*/
  2. /*==============================================================*\
  3.  *  VMM_MAIN.C - Sample PM application                          *
  4.  *                                                              *
  5.  *      (C) Copyright IBM Corporation 1992                      *
  6.  *                                                              *
  7.  *   DISCLAIMER OF WARRANTIES.  The following [enclosed] code is*
  8.  *   sample code created by IBM Corporation. This sample code is*
  9.  *   not part of any standard IBM product and is provided to you*
  10.  *   solely forthe purpose of assisting you in the development  *
  11.  *   of your applications.  The code is provided "AS IS",       *
  12.  *   without warranty of any kind. No IBM shall be liable for   *
  13.  *   any damages arising out of your use of the sample code,    *
  14.  *   even if they have been advised of the possibility of       *
  15.  *   such damages.                                              *
  16.  *                                                              *
  17.  *--------------------------------------------------------------*
  18.  *                                                              *
  19.  *  This application serves two distinct purposes. First, it    *
  20.  *  demonstrates the standard menus and dialogs that most PM    *
  21.  *  applications will contain.  The Demo menu calls dialog      *
  22.  *  boxes that demonstrate all of the controls available for    *
  23.  *  use in a dialog box.  There is also a dialog box which      *
  24.  *  demonstrates the setting and removing of control            *
  25.  *  Presentation Parameters.  Finally, the demo menu also has   *
  26.  *  menu items that demonstrate the various types of message    *
  27.  *  boxes that the system supports.                             *
  28.  *                                                              *
  29.  *  This application also serves as a template that can be      *
  30.  *  easily modified by an application developer.  The source    *
  31.  *  files are organized so that the overhead code that should   *
  32.  *  be in all applications is located in the same files so      *
  33.  *  that these files do not need to be modified.  The routines  *
  34.  *  that deal with application specific code are also located   *
  35.  *  in their own modules.  An application developer need only   *
  36.  *  change these files in order to modify this template for     *
  37.  *  his application.                                            *
  38.  *                                                              *
  39.  *--------------------------------------------------------------*
  40.  *                                                              *
  41.  *  This source file contains the following functions:          *
  42.  *                                                              *
  43.  *      main() - main routine                                   *
  44.  *      MainWndProc(hwnd, msg, mp1, mp2) - main window procedure*
  45.  *      MainCommand(mp1, mp2) - WM_COMMAND processing of Main   *
  46.  *      MessageBox(hwnd nId, pszMsg, fsStyle, bBeep)            *
  47.  *      DisplayPage(hps, pptl, ulPageIndex)                     *
  48.  *      EnableMenuItem(hwnd, sMenuItem, fEnable)                *
  49.  *                                                              *
  50. \*==============================================================*/
  51. /*--------------------------------------------------------------*\
  52.  *  Include files, macros, defined constants, and externs       *
  53. \*--------------------------------------------------------------*/
  54. #include "vmm.h"
  55.  
  56. /****************************************************************\
  57.  *  Main routine                                                *
  58.  *--------------------------------------------------------------*
  59.  *                                                              *
  60.  *  Name:    main()                                             *
  61.  *                                                              *
  62.  *  Purpose: Initializes the PM environment, calls the          *
  63.  *              initialization routine, creates the main        *
  64.  *              window,  and polls the message queue            *
  65.  *                                                              *
  66.  *  Usage:                                                      *
  67.  *                                                              *
  68.  *  Method:  -obtains anchor block handle and creates message   *
  69.  *              queue                                           *
  70.  *           -calls the initialization routine                  *
  71.  *           -creates the main frame window which creates the   *
  72.  *              main client window                              *
  73.  *           -polls the message queue via Get/Dispatch Msg loop *
  74.  *           -upon exiting the loop, exits                      *
  75.  *                                                              *
  76.  *  Returns: 1 - if sucessful execution completed               *
  77.  *           0 - if error                                       *
  78. \****************************************************************/
  79. INT  main(VOID)
  80. {
  81.     QMSG qmsg;                                      /* message structure */
  82.     ULONG ctlData;                                 /* frame control data */
  83.     EXCEPTIONREGISTRATIONRECORD ExceptionStruct;
  84.  
  85.     ulFreePage = 0L;
  86.     strcpy(szWindowText,"VMM Sample");
  87.     hab = WinInitialize(0);
  88.     if(!hab)
  89.     {
  90.         DosBeep(BEEP_WARN_FREQ, BEEP_WARN_DUR);
  91.         DosExit(EXIT_PROCESS, RETURN_ERROR);
  92.     }
  93.                                              /* find a define for this v */
  94.     hmq = WinCreateMsgQueue(hab, 0);
  95.     if(!hmq)
  96.     {
  97.         DosBeep(BEEP_WARN_FREQ, BEEP_WARN_DUR);
  98.         WinTerminate(hab);
  99.         DosExit(EXIT_PROCESS, RETURN_ERROR);
  100.     }
  101.     if(!Init())
  102.     {
  103.         MessageBox(HWND_DESKTOP, IDMSG_INITFAILED, "Error !",
  104.                             MB_OK | MB_ERROR | MB_MOVEABLE, TRUE);
  105.         DosExit(EXIT_PROCESS, RETURN_ERROR);
  106.     }
  107.                                                /* create the main window */
  108.     ctlData = FCF_STANDARD | FCF_VERTSCROLL;
  109.     hwndMainFrame = WinCreateStdWindow(HWND_DESKTOP,
  110.                                        WS_VISIBLE,
  111.                                        (PVOID)&ctlData,
  112.                                        (PSZ)szAppName,
  113.                                        (PSZ)NULL,
  114.                                        WS_VISIBLE,
  115.                                        (HMODULE)NULL,
  116.                                        IDR_RESOURCE,
  117.                                        (PHWND)&hwndMain);
  118.     if(!hwndMainFrame)
  119.     {
  120.         MessageBox(HWND_DESKTOP, IDMSG_MAINWINCREATEFAILED, "Error !",
  121.                             MB_OK | MB_ERROR | MB_MOVEABLE, TRUE);
  122.         DosExit(EXIT_PROCESS, RETURN_ERROR);
  123.     }
  124.    InitHelp();
  125.                          /* Invoke exception management, and direction user
  126.                              exception handling function to GPFHandler() */
  127.    ExceptionStruct.ExceptionHandler = (_ERR *)&GPFHandler;
  128.    DosSetExceptionHandler(&ExceptionStruct) ;
  129.  
  130.                                             /* Get/Dispatch Message loop */
  131.    while(WinGetMsg(hab, (PQMSG)&qmsg, 0L, 0L, 0L))
  132.        WinDispatchMsg(hab, (PQMSG)&qmsg);
  133.  
  134.                                         /* Release exception managerment */
  135.    DosUnsetExceptionHandler(&ExceptionStruct) ;
  136.  
  137.    DestroyHelpInstance();                   /* destroy the help instance */
  138. #ifdef VER630
  139.                                      /* will normally be put in ExitProc */
  140.     WinDestroyWindow(hwndMainFrame);
  141.  
  142.     /*--------------------------------------------------*\
  143.      *      Any other system resources used             *
  144.      *      (e.g. memory or files) should be freed here *
  145.     \*--------------------------------------------------*/
  146.     WinDestroyMsgQueue(hmq);
  147.     WinTerminate(hab);
  148.  
  149. #endif
  150.  
  151.     DosExit(EXIT_PROCESS, RETURN_SUCCESS);
  152.     return 0L;
  153. }                                                              /* main() */
  154.  
  155. /****************************************************************\
  156.  *  Main client window procedure                                *
  157.  *--------------------------------------------------------------*
  158.  *                                                              *
  159.  *  Name:    MainWndProc(hwnd, msg, mp1, mp2)                   *
  160.  *                                                              *
  161.  *  Purpose: Processes the messages sent to the main client     *
  162.  *           window. This routine processes the basic messages  *
  163.  *           all client windows should process and passes all   *
  164.  *           others onto UserWndProc where the developer can    *
  165.  *           process any others.                                *
  166.  *                                                              *
  167.  *  Usage:   Called for each message placed in the main         *
  168.  *           window's message queue                             *
  169.  *                                                              *
  170.  *  Method:  a switch statement branches to the routines to be  *
  171.  *           performed for each message processed. Any messages *
  172.  *           not specifically process are passed to the user's  *
  173.  *           message processing procedure UserWndProc().        *
  174.  *                                                              *
  175.  *  Returns: Return values are determined by each message       *
  176.  *                                                              *
  177. \****************************************************************/
  178. MRESULT EXPENTRY MainWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  179. {
  180.    static LONG sVscrollMax;
  181.    MRESULT sRC;
  182.  
  183.    switch(msg)
  184.    {
  185.        case WM_CREATE:
  186.  
  187.            sVscrollMax =  MAXPAGES*(BOX_HEIGHT+VERT_SPACING);
  188.  
  189.            hwndVscroll = WinWindowFromID(
  190.                               WinQueryWindow(hwnd, QW_PARENT),
  191.                               FID_VERTSCROLL);
  192.            WinSendMsg(hwndVscroll, SBM_SETSCROLLBAR,
  193.                                   MPFROM2SHORT(sVscrollPos, 0),
  194.                                   MPFROM2SHORT(0, sVscrollMax) );
  195.            break;
  196.  
  197.        case WM_VSCROLL:
  198.            switch (SHORT2FROMMP(mp2))
  199.            {
  200.                case SB_LINEUP:
  201.                    sVscrollPos -= SMALL_BOX_HEIGHT;
  202.                    break;
  203.  
  204.                case SB_LINEDOWN:
  205.                    sVscrollPos += SMALL_BOX_HEIGHT;
  206.                    break;
  207.  
  208.                case SB_PAGEUP:
  209.                    sVscrollPos -= BOX_HEIGHT+VERT_SPACING;
  210.                    break;
  211.  
  212.                case SB_PAGEDOWN:
  213.                    sVscrollPos += BOX_HEIGHT+VERT_SPACING;
  214.                    break;
  215.  
  216.                case SB_SLIDERTRACK:
  217.                case SB_SLIDERPOSITION:
  218.                    sVscrollPos = SHORT1FROMMP(mp2);
  219.                    break;
  220.            }
  221.            sVscrollPos = max(0, min(sVscrollPos, sVscrollMax) );
  222.  
  223.            if(sVscrollPos != SHORT1FROMMR(WinSendMsg(hwndVscroll,
  224.                                      SBM_QUERYPOS, (MPARAM)NULL, (MPARAM)NULL)))
  225.            {
  226.               WinSendMsg(hwndVscroll, SBM_SETPOS,
  227.                                MPFROMSHORT(sVscrollPos), NULL);
  228.               WinInvalidateRect(hwnd, NULL, FALSE);
  229.            }
  230.            break;
  231.  
  232.        case WM_CHAR:
  233.            switch (SHORT2FROMMP(mp2))
  234.            {
  235.                case VK_LEFT:
  236.                case VK_UP:
  237.                    sVscrollPos -= SMALL_BOX_HEIGHT;
  238.                    break;
  239.  
  240.                case VK_DOWN:
  241.                case VK_RIGHT:
  242.                    sVscrollPos += SMALL_BOX_HEIGHT;
  243.                    break;
  244.  
  245.                case VK_PAGEUP:
  246.                    sVscrollPos -= BOX_HEIGHT+VERT_SPACING;
  247.                    break;
  248.  
  249.                case VK_PAGEDOWN:
  250.                    sVscrollPos += BOX_HEIGHT+VERT_SPACING;
  251.                    break;
  252.            }
  253.            sVscrollPos = max(0, min(sVscrollPos, sVscrollMax) );
  254.  
  255.            if(sVscrollPos != SHORT1FROMMR(WinSendMsg(hwndVscroll,
  256.                                      SBM_QUERYPOS, (MPARAM)NULL, (MPARAM)NULL)))
  257.            {
  258.               WinSendMsg(hwndVscroll, SBM_SETPOS,
  259.                                MPFROMSHORT(sVscrollPos), NULL);
  260.               WinInvalidateRect(hwnd, NULL, FALSE);
  261.            }
  262.            break;
  263.  
  264.        case WM_PAINT:
  265.            MainPaint(hwnd);
  266.            break;
  267.  
  268.        case WM_COMMAND:
  269.            MainCommand(mp1, mp2);
  270.            break;
  271.  
  272.    /*--------------------------------------------------*\
  273.     *      Any messages not processed are passed on    *
  274.     *      to the user's window proc.  It is           *
  275.     *      responsible for passing any messages it     *
  276.     *      doesn't handle onto WinDefWindowProc()      *
  277.    \*--------------------------------------------------*/
  278.        case HM_QUERY_KEYS_HELP:
  279.            return ((MRESULT)PANEL_KEYSHELP);
  280.  
  281.        default:
  282.            sRC = WinDefWindowProc(hwnd, msg, mp1, mp2);
  283.            return sRC;
  284.    }
  285.    return ((MRESULT)0L);  /* window procedures should return 0 as a default */
  286. }                                                        /* MainWndProc() */
  287.  
  288. /****************************************************************\
  289.  *  Main client painting routine                                *
  290.  *--------------------------------------------------------------*
  291.  *                                                              *
  292.  *  Name:    MainPaint(hwnd)                                    *
  293.  *                                                              *
  294.  *  Purpose: Paints the main client window.                     *
  295.  *                                                              *
  296.  *  Usage:   Routine is called whenver the client window        *
  297.  *           procedure receives a WM_PAINT message              *
  298.  *                                                              *
  299.  *  Method:  -begins painting by calling WinBeginPaint          *
  300.  *              and retriving the HPS for the window            *
  301.  *           -paint page info boxes                             *
  302.  *                                                              *
  303.  *           -ends painting by calling WinEndPaint              *
  304.  *                                                              *
  305.  *  Returns: VOID                                               *
  306.  *                                                              *
  307. \****************************************************************/
  308. VOID MainPaint(HWND hwnd)
  309. {
  310.     HPS    hps;
  311.     USHORT i;
  312.     POINTL ptl;
  313.     RECTL  rect;
  314.     SIZEL  sizl;
  315.     char   szBuff[BUFF_SIZE];
  316.  
  317.     sizl.cx = 0L;
  318.     sizl.cy = 0L;
  319.  
  320.     hps = WinBeginPaint(hwnd, 0L, 0L);
  321.     GpiSetPS(hps, &sizl, PU_LOMETRIC);
  322.  
  323.     WinQueryWindowRect(hwnd, &rect);
  324.     WinFillRect(hps, (PRECTL)&rect, CLR_BACKGROUND);
  325.  
  326.     /* convert the coords of the window to world coords */
  327.     GpiConvert(hps, CVTC_DEVICE, CVTC_WORLD, 2L, (PPOINTL) &rect);
  328.  
  329.     ptl.x = HORZ_INDENT*3;
  330.     ptl.y = rect.yTop - (BOX_HEIGHT+VERT_SPACING) + sVscrollPos;
  331.     GpiMove(hps, &ptl);
  332.  
  333.     ptl.x += BOX_WIDTH;
  334.     ptl.y += BOX_HEIGHT;
  335.     GpiSetColor(hps, CLR_GREEN);
  336.     GpiBox(hps, DRO_OUTLINE, &ptl, 0L, 0L);
  337.  
  338.     ptl.x = HORZ_INDENT*3 + HORZ_SPACING*3 + BOX_WIDTH;
  339.     ptl.y = rect.yTop - (BOX_HEIGHT+VERT_SPACING) + sVscrollPos;
  340.     GpiMove(hps, &ptl);
  341.  
  342.     ptl.x += BOX_WIDTH;
  343.     ptl.y += BOX_HEIGHT;
  344.     GpiSetColor(hps, CLR_RED);
  345.     GpiBox(hps, DRO_OUTLINE, &ptl, 0L, 0L);
  346.  
  347.     GpiSetColor(hps, CLR_BLACK);
  348.  
  349.     ptl.x = HORZ_INDENT*3+30;
  350.     ptl.y = rect.yTop - (VERT_SPACING+SMALL_BOX_HEIGHT) + 30 + sVscrollPos;
  351.     strcpy(szBuff,"Committed");
  352.     GpiCharStringAt(hps, &ptl, (LONG) strlen(szBuff), szBuff);
  353.  
  354.     ptl.y -= SMALL_BOX_HEIGHT;
  355.     strcpy(szBuff,"page");
  356.     GpiCharStringAt(hps, &ptl, (LONG) strlen(szBuff), szBuff);
  357.  
  358.  
  359.     ptl.x = HORZ_INDENT*3+30 + HORZ_SPACING*3 + BOX_WIDTH ;
  360.     ptl.y = rect.yTop - (VERT_SPACING+SMALL_BOX_HEIGHT) + 30 + sVscrollPos;
  361.     strcpy(szBuff,"Non-Committed");
  362.     GpiCharStringAt(hps, &ptl, (LONG) strlen(szBuff), szBuff);
  363.  
  364.     ptl.y -= SMALL_BOX_HEIGHT;
  365.     strcpy(szBuff,"page");
  366.     GpiCharStringAt(hps, &ptl, (LONG) strlen(szBuff), szBuff);
  367.  
  368.     ptl.x = HORZ_INDENT;                           /* 1'st page location */
  369.     ptl.y = rect.yTop - 2*(BOX_HEIGHT+VERT_SPACING) + sVscrollPos;
  370.  
  371.     for (i=0;((ULONG) i)<ulFreePage; i++)
  372.     {
  373.         DisplayPage(hps, &ptl, i);             /* Redisplay alloc status */
  374.         ptl.x += BOX_WIDTH+HORZ_SPACING;
  375.  
  376.         if (ptl.x+BOX_WIDTH > rect.xRight)
  377.         {                 /* If next page over window, move to next line */
  378.            ptl.x = HORZ_INDENT+BOX_WIDTH+HORZ_SPACING;
  379.            ptl.y -= (BOX_HEIGHT+VERT_SPACING);
  380.         }
  381.     /* If the next page is a base page, display it on a new line for clarity */
  382.  
  383.         if (apgentry[i+1].fBaseAddr)
  384.         {
  385.             ptl.x = HORZ_INDENT;
  386.             ptl.y -= (BOX_HEIGHT+VERT_SPACING);
  387.         }
  388.     }
  389.     WinEndPaint(hps);
  390.     return;
  391. }                                                   /* MainPaint() */
  392.  
  393. /****************************************************************\
  394.  *  Main window WM_COMMAND processing procedure                 *
  395.  *--------------------------------------------------------------*
  396.  *                                                              *
  397.  *  Name:   MainCommand(mp1, mp2)                               *
  398.  *                                                              *
  399.  *  Purpose:Calls the appropriate procedures that deal with     *
  400.  *           the selected menu item.                            *
  401.  *                                                              *
  402.  *  Usage:  Routine is called whenever a WM_COMMAND message     *
  403.  *          is posted to the main window.                       *
  404.  *                                                              *
  405.  *  Method: a switch statement branches on the id of the        *
  406.  *          menu item that posted the message and the           *
  407.  *          appropriate action for that item is taken.  Any     *
  408.  *          menu ids that are not part of the standard menu     *
  409.  *          set are passed onto the user defined WM_COMMAND     *
  410.  *          processing procedure.                               *
  411.  *                                                              *
  412.  *  Returns:                                                    *
  413.  *                                                              *
  414. \****************************************************************/
  415. VOID MainCommand(MPARAM mp1, MPARAM mp2)
  416. {
  417.     switch(SHORT1FROMMP(mp1))
  418.     {
  419.         case IDM_GENERALHELP:
  420.            HelpExtended(mp2);
  421.            return;
  422.  
  423.         case IDM_USINGHELP:
  424.            HelpHelpForHelp(mp2);
  425.            return;
  426.  
  427.         case IDM_TUTORIAL:
  428.            HelpKeys(mp2);
  429.            return;
  430.  
  431.         case IDM_HELPINDEX:
  432.            HelpIndex(mp2);
  433.            return;
  434.  
  435.         case IDM_HELPPRODUCTINFO:
  436.            HelpAbout(mp2);
  437.            return;
  438.  
  439.     /*--------------------------------------------------*\
  440.      *      User command processing routine is called   *
  441.      *      here so any ids not procecessed here can be *
  442.      *      processed                                   *
  443.     \*--------------------------------------------------*/
  444.         default:
  445.             UserCommand(mp1, mp2);
  446.             break;
  447.     }
  448.     return;
  449. }                                                /* MainCommand() */
  450.  
  451. /****************************************************************\
  452.  *  Exit routine                                                *
  453.  *--------------------------------------------------------------*
  454.  *                                                              *
  455.  *  Name:    DisplayPage(hps, pptl, ulPageIndex)                *
  456.  *                                                              *
  457.  *  Purpose: Processes the VMM menu's Exit item.                *
  458.  *                                                              *
  459.  *  Usage:   called whenever Exit from the VMM menu is          *
  460.  *           selected                                           *
  461.  *                                                              *
  462.  *  Method:  Routine posts a WM_CLOSE message to the main       *
  463.  *           application window.                                *
  464.  *                                                              *
  465.  *  Returns: VOID                                               *
  466.  *                                                              *
  467. \****************************************************************/
  468. VOID DisplayPage(HPS hps, PPOINTL pptl, ULONG ulPageIndex)
  469. {
  470.     POINTL ptl;
  471.     MATRIXLF matrix;
  472.     ULONG ulAccess=0;
  473.     ULONG ulRegionSize;
  474.     PVOID pMem;
  475.     char szBuff[BUFF_SIZE];
  476.  
  477.     pMem = apgentry[ulPageIndex].pvAddress;
  478.  
  479.     /* We don't check the return code here since we assume that the array
  480.        contains good addresses since we verified them when we put them in
  481.        the array.  */                     /* Get memory size & attributes */
  482.     DosQueryMem(pMem, &ulRegionSize, &ulAccess);
  483.  
  484.     matrix.fxM11 = MAKEFIXED(1,0);
  485.     matrix.fxM12 = 0L;
  486.     matrix.lM13  = 0L;
  487.     matrix.fxM21 = 0L;
  488.     matrix.fxM22 = MAKEFIXED(1,0);
  489.     matrix.lM23  = 0L;
  490.     matrix.lM31  = pptl->x;                             /* x translation */
  491.     matrix.lM32  = pptl->y;                             /* y translation */
  492.     matrix.lM33  = 1L;
  493.  
  494.     GpiSetDefaultViewMatrix(hps, 9L, &matrix,TRANSFORM_REPLACE);
  495.  
  496.     ptl.x = 0L;
  497.     ptl.y = 0L;
  498.     GpiMove(hps, &ptl);
  499.  
  500.     ptl.x = BOX_WIDTH;
  501.     ptl.y = BOX_HEIGHT;
  502.  
  503.     /* set outline color to CLR_RED for uncommitted, CLR_GREEN for committed */
  504.     if (ulAccess & PAG_COMMIT)
  505.     {
  506.         GpiSetColor(hps, CLR_GREEN);
  507.     }
  508.     else
  509.         GpiSetColor(hps, CLR_RED);
  510.  
  511.     GpiBox(hps, DRO_OUTLINE, &ptl, 0L, 0L);
  512.  
  513.     /* should query sys values in case the default is not black ? */
  514.     GpiSetColor(hps, CLR_BLACK);
  515.  
  516.     szBuff[0]='\000';
  517.     if (ulAccess & PAG_READ)
  518.         strcat(szBuff, "R");
  519.  
  520.     if (ulAccess & PAG_WRITE)
  521.         strcat(szBuff, "W");
  522.  
  523.     if (ulAccess & PAG_EXECUTE)
  524.         strcat(szBuff, "E");
  525.  
  526.     if (ulAccess & PAG_GUARD)
  527.         strcat(szBuff, "G");
  528.  
  529.     if (ulAccess & PAG_DEFAULT)
  530.         strcat(szBuff, "Def");
  531.  
  532.     if (ulAccess & PAG_BASE)
  533.         strcat(szBuff, "Base");
  534.  
  535.     ptl.x = HORZ_INDENT;
  536.     ptl.y = VERT_INDENT;
  537.     GpiCharStringAt(hps, &ptl, (LONG) strlen(szBuff), szBuff);
  538.  
  539.     ptl.x = 0;
  540.     ptl.y = SMALL_BOX_HEIGHT;
  541.  
  542.     GpiMove(hps, &ptl);
  543.  
  544.     ptl.x = BOX_WIDTH;
  545.     ptl.y = SMALL_BOX_HEIGHT;
  546.     GpiLine(hps, &ptl);
  547.  
  548.     /* Get base address of current page */
  549.     sprintf(szBuff, "0x%p", pMem);
  550.  
  551.     ptl.x = HORZ_INDENT;
  552.     ptl.y = SMALL_BOX_HEIGHT+VERT_INDENT;
  553.     GpiCharStringAt(hps, &ptl, (LONG) strlen(szBuff), szBuff);
  554.     return;
  555. }
  556.  
  557. /****************************************************************\
  558.  *  Message Box procedure                                       *
  559.  *--------------------------------------------------------------*
  560.  *                                                              *
  561.  *  Name:    MessageBox(hwndOwner, nIdMsg,pszMsg,fsStyle, bBeep)*
  562.  *                                                              *
  563.  *  Purpose: Displays the warning message box with the message  *
  564.  *              given in nIdMsg retrived from the message table *
  565.  *                                                              *
  566.  *  Usage:   Called whever an error occurs and a message wishes *
  567.  *           to be displayed to the user                        *
  568.  *                                                              *
  569.  *  Method:  - Message string is loaded from the process'       *
  570.  *              message table                                   *
  571.  *           - Alarm beep is sounded if desired                 *
  572.  *           - Message box with the message is displayed        *
  573.  *                                                              *
  574.  *  Returns:                                                    *
  575.  *                                                              *
  576. \****************************************************************/
  577. VOID MessageBox(HWND hwndOwner, LONG nIdMsg, PSZ pszMsg, LONG fsStyle,
  578.                      BOOL bBeep)
  579. {
  580.     CHAR szText[MESSAGELEN];
  581.  
  582.     if(!WinLoadMessage(hab, (HMODULE)NULL, nIdMsg, MESSAGELEN, (PSZ)szText))
  583.     {
  584.         WinAlarm(HWND_DESKTOP, WA_ERROR);
  585.         return;
  586.     }
  587.     if(bBeep)
  588.         WinAlarm(HWND_DESKTOP, WA_ERROR);
  589.  
  590.     WinMessageBox(HWND_DESKTOP,
  591.                   hwndOwner,
  592.                   szText,
  593.                   (PSZ)pszMsg,
  594.                   IDM_MSGBOX,
  595.                   fsStyle);
  596.     return;
  597. }                                                   /* MessageBox() */
  598.  
  599. /****************************************************************\
  600.  *  EnableMenuItem procedure                                    *
  601.  *--------------------------------------------------------------*
  602.  *                                                              *
  603.  * Name:    EnableMenuItem(hwnd, sMenuItem, fEnable)            *
  604.  *                                                              *
  605.  * Purpose: This routine handles enabling/disabling of menu     *
  606.  *          items. This is done by getting Parent and Menu hwnd *
  607.  *          handles then sending the appropriate message.       *                     *
  608.  *                                                              *
  609.  * Usage:   Routine is called when enable or disable one item   *
  610.  *          from menu.                                          *
  611.  *                                                              *
  612.  * Method:                                                      *
  613.  *                                                              *
  614.  * Returns: VOID                                                *
  615.  *                                                              *
  616. \****************************************************************/
  617. VOID EnableMenuItem(HWND hwnd, LONG sMenuItem, BOOL fEnable)
  618. {
  619.    HWND hwndParent = WinQueryWindow(hwnd, QW_PARENT);
  620.    HWND hwndMenu   = WinWindowFromID(hwndParent,FID_MENU);
  621.  
  622.    WinSendMsg(hwndMenu, MM_SETITEMATTR,
  623.               MPFROM2SHORT(sMenuItem, TRUE),
  624.               MPFROM2SHORT(MIA_DISABLED, fEnable ? 0 : MIA_DISABLED));
  625.    return;
  626. }
  627.