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

  1. /*static char *SCCSID = "@(#)vmm_dlg.c    6.12 92/03/18";*/
  2. /*==============================================================*\
  3.  *  VMM_DLG.C - window procedures for the dialog boxes as well  *
  4.  *              as utility procedures used by them              *
  5.  *      (C) Copyright IBM Corporation 1992.                     *
  6.  *--------------------------------------------------------------*
  7.  *                                                              *
  8.  *  This module contains the Dialog Procedures for the user     *
  9.  *  defined dialogs as well as any support code they need       *
  10.  *                                                              *
  11.  *--------------------------------------------------------------*
  12.  *                                                              *
  13.  *  This source file contains the following functions:          *
  14.  *                                                              *
  15.  *           AllocMemDlgProc(hwnd, msg, mp1, mp2)               *
  16.  *           SetMem1DlgProc( hwnd, msg, mp1, mp2)               *
  17.  *           SetMem2DlgProc( hwnd, msg, mp1, mp2)               *
  18.  *           ReadMemDlgProc( hwnd, msg, mp1, mp2)               *
  19.  *           WriteMemDlgProc(hwnd, msg, mp1, mp2)               *
  20.  *           FreeMemDlgProc( hwnd, msg, mp1, mp2)               *
  21.  *                                                              *
  22. \*==============================================================*/
  23.  
  24. /*--------------------------------------------------------------*\
  25.  *  Include files, macros, defined constants, and externs       *
  26. \*--------------------------------------------------------------*/
  27. #include "vmm.h"
  28.  
  29. /****************************************************************\
  30.  *  Dialog procedure for the Allocate Memory dialog             *
  31.  *--------------------------------------------------------------*
  32.  *                                                              *
  33.  *  Name:    AllocMemDlgProc(hwnd, msg, mp1, mp2)               *
  34.  *                                                              *
  35.  *  Purpose: Processes all messages sent to the AllocMem dialog *
  36.  *                                                              *
  37.  *  Usage:   Called for each message sent to the dialog box.    *
  38.  *                                                              *
  39.  *  Method:  a switch statement branches to the routines to be  *
  40.  *           performed for each message processed. Any messages *
  41.  *           not specifically processed are passed to the       *
  42.  *           default window procedure WinDefDlgProc()           *
  43.  *                                                              *
  44.  *  Returns: Dependent upon message sent                        *
  45.  *                                                              *
  46. \****************************************************************/
  47. MRESULT EXPENTRY AllocMemDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  48. {
  49.     static POBJSTRUCT pObj;
  50.     MRESULT sRC;
  51.  
  52.     switch (msg) {
  53.         case WM_INITDLG:
  54.  
  55.             pObj = PVOIDFROMMP(mp2);
  56.             FixSysMenu(hwnd);
  57.  
  58.             _ltoa(
  59.                    (pObj->ulSize) ,(CHAR *) szBuffer, 10);  /* radix=10 */
  60.  
  61.             WinSetDlgItemText(hwnd, IDD_EDITSIZE, szBuffer);
  62.  
  63.             WinSendDlgItemMsg(hwnd, IDD_READ, BM_SETCHECK,
  64.                    MPFROMSHORT((pObj->ulAttr & PAG_READ) ? 1 : 0), (MPARAM)0L);
  65.  
  66.             WinSendDlgItemMsg(hwnd, IDD_EXECUTE, BM_SETCHECK,
  67.                  MPFROMSHORT((pObj->ulAttr & PAG_EXECUTE) ? 1 : 0),(MPARAM)0L);
  68.  
  69.             WinSendDlgItemMsg(hwnd, IDD_WRITE, BM_SETCHECK,
  70.                  MPFROMSHORT((pObj->ulAttr & PAG_WRITE) ? 1 : 0),(MPARAM)0L);
  71.  
  72.             WinSendDlgItemMsg(hwnd, IDD_GUARD, BM_SETCHECK,
  73.                  MPFROMSHORT((pObj->ulAttr & PAG_GUARD) ? 1 : 0),(MPARAM)0L);
  74.  
  75.             WinSendDlgItemMsg(hwnd, IDD_COMMIT, BM_SETCHECK,
  76.                  MPFROMSHORT((pObj->ulAttr & PAG_COMMIT) ? 1 : 0),(MPARAM)0L);
  77.  
  78.             WinSendDlgItemMsg(hwnd, IDD_TILE, BM_SETCHECK,
  79.                  MPFROMSHORT((pObj->ulAttr & OBJ_TILE) ? 1 : 0),(MPARAM)0L);
  80.  
  81.             return((MRESULT)FALSE);
  82.                            /* Let the focus go to where the system puts it */
  83.  
  84.         case WM_COMMAND:
  85.             switch (SHORT1FROMMP(mp1)) {
  86.                 case DID_OK:
  87.                     WinQueryDlgItemText(hwnd, IDD_EDITSIZE, MAX_EDIT_BUFF,
  88.                                           szBuffer);    /* Get user's size */
  89.                     pObj->ulSize = atol(szBuffer);
  90.                     pObj->ulSize *= 1000L;
  91.                     pObj->ulAttr =
  92.                   ((WinSendDlgItemMsg(hwnd,IDD_READ,BM_QUERYCHECK,(MPARAM)0L,
  93.                        (MPARAM)0L) == (MRESULT)1L) ? (ULONG)PAG_READ : 0L)    |
  94.                   ((WinSendDlgItemMsg(hwnd,IDD_EXECUTE,BM_QUERYCHECK,(MPARAM)0L,
  95.                        (MPARAM)0L) == (MRESULT)1L) ? (ULONG)PAG_EXECUTE : 0L) |
  96.                   ((WinSendDlgItemMsg(hwnd,IDD_WRITE,BM_QUERYCHECK,(MPARAM)0L,
  97.                        (MPARAM)0L) == (MRESULT)1L) ? (ULONG)PAG_WRITE : 0L)   |
  98.                   ((WinSendDlgItemMsg(hwnd,IDD_GUARD,BM_QUERYCHECK,(MPARAM)0L,
  99.                        (MPARAM)0L) == (MRESULT)1L) ? (ULONG)PAG_GUARD : 0L)   |
  100.                   ((WinSendDlgItemMsg(hwnd,IDD_COMMIT,BM_QUERYCHECK,(MPARAM)0L,
  101.                        (MPARAM)0L) == (MRESULT)1L) ? (ULONG)PAG_COMMIT : 0L)  |
  102.                   ((WinSendDlgItemMsg(hwnd,IDD_TILE,BM_QUERYCHECK,(MPARAM)0L,
  103.                        (MPARAM)0L) == (MRESULT)1L) ? (ULONG)OBJ_TILE : 0L);
  104.  
  105.                     if (((pObj->ulAttr & PAG_READ) == 0L)  /* Disable READ */
  106.                          && ((pObj->ulAttr & PAG_EXECUTE) != 0L))
  107.                     {
  108.                        MessageBox(hwnd, IDMSG_UNSETREADERROR, "Error !",
  109.                                     MB_OK | MB_INFORMATION, TRUE);
  110.                        pObj->ulAttr = pObj->ulAttr | PAG_READ;
  111.                     }
  112.                     if (((pObj->ulAttr & PAG_READ) == 0L)  /* Disable READ */
  113.                          && ((pObj->ulAttr & PAG_WRITE) != 0L))
  114.                     {
  115.                        MessageBox(hwnd, IDMSG_UNSETREADERROR2, "Error !",
  116.                                     MB_OK | MB_INFORMATION, TRUE);
  117.                        pObj->ulAttr = pObj->ulAttr | PAG_READ;
  118.                     }
  119.                     WinDismissDlg(hwnd, TRUE);
  120.                     return((MRESULT)0L);
  121.  
  122.                 case DID_CANCEL:
  123.                     WinDismissDlg(hwnd, FALSE);
  124.                     return((MRESULT)0L);
  125.  
  126.                 default:
  127.                     sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  128.                     return sRC;
  129.                 }
  130.             break;
  131.  
  132.         case WM_CLOSE:
  133.            WinDismissDlg(hwnd, FALSE);
  134.            return((MRESULT)0L);
  135.  
  136.         default:
  137.             sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  138.             return sRC;
  139.     }
  140.     return((MRESULT)0L);
  141. }
  142.  
  143. /****************************************************************\
  144.  *  Dialog procedure for the Set Memory dialog                  *
  145.  *--------------------------------------------------------------*
  146.  *                                                              *
  147.  *  Name:    SetMem1DlgProc(hwnd, msg, mp1, mp2)                *
  148.  *                                                              *
  149.  *  Purpose: Processes all messages sent to the SetMem1 dialog  *
  150.  *                                                              *
  151.  *  Usage:   Called for each message sent to the dialog box.    *
  152.  *                                                              *
  153.  *  Method:  a switch statement branches to the routines to be  *
  154.  *           performed for each message processed.  Any messages*
  155.  *           not specifically processed are passed to the       *
  156.  *           default window procedure WinDefDlgProc()           *
  157.  *                                                              *
  158.  *  Returns: Dependent upon message sent                        *
  159.  *                                                              *
  160. \****************************************************************/
  161. MRESULT EXPENTRY SetMem1DlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  162. {
  163.    static POBJSTRUCT pObj;
  164.    ULONG  ulIndexLow;
  165.    MRESULT sRC;
  166.  
  167.    switch (msg) {
  168.        case WM_INITDLG:  /* address of buffer pointed to by pCreateParams */
  169.            pObj = PVOIDFROMMP(mp2);
  170.            FixSysMenu(hwnd);
  171.  
  172.            WinSetDlgItemText(hwnd, IDD_EDITSIZE, SZDEFAULT_SIZE);
  173.  
  174.            return((MRESULT)FALSE);
  175.                          /* Let the focus go to where the system puts it */
  176.  
  177.        case WM_COMMAND:
  178.            switch (SHORT1FROMMP(mp1)) {
  179.                case DID_OK:
  180.                    WinQueryDlgItemText(hwnd, IDD_ADDRESS, MAX_EDIT_BUFF,
  181.                                               szBuffer);
  182.                    sscanf(szBuffer,"%p",&(pObj->pvAddress));
  183.  
  184.                    WinQueryDlgItemText(hwnd, IDD_EDITSIZE, MAX_EDIT_BUFF,
  185.                                               szBuffer);
  186.                    sscanf(szBuffer,"%p",&(pObj->ulSize));
  187.  
  188.                    ulIndexLow = 0;
  189.                                             /* Look for the pointed page */
  190.                    while((apgentry[ulIndexLow].pvAddress != pObj->pvAddress)
  191.                                       && (ulIndexLow < ulFreePage))
  192.                        ulIndexLow++;
  193.                    if(ulIndexLow == ulFreePage)       /* Illeage address */
  194.                    {
  195.                       MessageBox(hwnd, IDMSG_ERRORADDRESS, "Error !",
  196.                                        MB_OK | MB_MOVEABLE, TRUE);
  197.                       return (MRESULT)0L;
  198.                    }
  199.                    WinDismissDlg(hwnd, TRUE);
  200.                    return((MRESULT)0L);
  201.  
  202.                case DID_CANCEL:
  203.                    WinDismissDlg(hwnd, FALSE);
  204.                    return((MRESULT)0L);
  205.  
  206.                default:
  207.                    sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  208.                    return sRC;
  209.            }
  210.            break;
  211.  
  212.         case WM_CLOSE:
  213.            WinDismissDlg(hwnd, FALSE);
  214.            return((MRESULT)0L);
  215.  
  216.        default:
  217.            sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  218.            return sRC;
  219.        }
  220.        return((MRESULT)0L);
  221. }
  222.  
  223. /****************************************************************\
  224.  *  Dialog procedure for the Set Memory dialog                  *
  225.  *--------------------------------------------------------------*
  226.  *                                                              *
  227.  *  Name:    SetMem2DlgProc(hwnd, msg, mp1, mp2)                *
  228.  *                                                              *
  229.  *  Purpose: Processes all messages sent to the SetMem2 dialog. *
  230.  *                                                              *
  231.  *  Usage:   Called for each message sent to the dialog box.    *
  232.  *                                                              *
  233.  *  Method:  a switch statement branches to the routines to be  *
  234.  *           performed for each message processed.  Any messages*
  235.  *           not specifically processed are passed to the       *
  236.  *           default window procedure WinDefDlgProc()           *
  237.  *                                                              *
  238.  *  Returns: Dependent upon message sent                        *
  239.  *                                                              *
  240. \****************************************************************/
  241. MRESULT EXPENTRY SetMem2DlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  242. {
  243.    static POBJSTRUCT pObj;
  244.    ULONG ulRegionSize, ulFlags=0L;
  245.    ULONG rc;
  246.    MRESULT sRC;
  247.  
  248.    switch (msg) {
  249.        case WM_INITDLG:
  250.            pObj = PVOIDFROMMP(mp2);
  251.            FixSysMenu(hwnd);
  252.  
  253.            rc = DosQueryMem(pObj->pvAddress, &ulRegionSize, &ulFlags);
  254.            if (rc)                                      /* Query is fail */
  255.            {
  256.                VMM_Error("DosQueryMem()", rc);
  257.                WinDismissDlg(hwnd, FALSE);
  258.                return((MRESULT)FALSE);
  259.            }
  260.            memset(szBuffer,0,sizeof(szBuffer) );
  261.            sprintf(szBuffer, "Address of memory =0x%p",pObj->pvAddress);
  262.            WinSetDlgItemText(hwnd, IDD_ADDRESS, szBuffer);
  263.  
  264.            WinSendDlgItemMsg(hwnd, IDD_READ, BM_SETCHECK,
  265.                  MPFROMSHORT((ulFlags & PAG_READ) ? 1 : 0),(MPARAM)0L);
  266.            WinSendDlgItemMsg(hwnd, IDD_EXECUTE, BM_SETCHECK,
  267.                  MPFROMSHORT((ulFlags & PAG_EXECUTE) ? 1 : 0),(MPARAM)0L);
  268.            WinSendDlgItemMsg(hwnd, IDD_WRITE, BM_SETCHECK,
  269.                  MPFROMSHORT((ulFlags & PAG_WRITE) ? 1 : 0),(MPARAM)0L);
  270.            WinSendDlgItemMsg(hwnd, IDD_GUARD, BM_SETCHECK,
  271.                  MPFROMSHORT((ulFlags & PAG_GUARD) ? 1 : 0),(MPARAM)0L);
  272.            WinSendDlgItemMsg(hwnd, IDD_DEFAULT, BM_SETCHECK,
  273.                  MPFROMSHORT(1), (MPARAM)0L);
  274.  
  275.            return((MRESULT)FALSE);
  276.                            /* Let the focus go to where the system puts it */
  277.        case WM_CONTROL:
  278.            switch (SHORT1FROMMP(mp1)) {
  279.                case IDD_DECOMMIT:
  280.                             /* Can't change attributes when de-committing */
  281.                    if (SHORT2FROMMP(mp1) == BN_CLICKED)
  282.                    {
  283.                     if((WinSendDlgItemMsg(hwnd,IDD_DECOMMIT,BM_QUERYCHECK,
  284.                         (MPARAM)0L,(MPARAM)0L) == (MRESULT)1L) ? TRUE : FALSE)
  285.                     {
  286.             /* If we are decommitting memory, don't change any attributes */
  287.         WinSendDlgItemMsg(hwnd, IDD_READ, BM_SETCHECK,(MPARAM)0L,(MPARAM)0L);
  288.         WinSendDlgItemMsg(hwnd, IDD_EXECUTE, BM_SETCHECK,(MPARAM)0L,(MPARAM)0L);
  289.         WinSendDlgItemMsg(hwnd, IDD_WRITE, BM_SETCHECK,(MPARAM)0L,(MPARAM)0L);
  290.         WinSendDlgItemMsg(hwnd, IDD_GUARD, BM_SETCHECK,(MPARAM)0L,(MPARAM)0L);
  291.                     }
  292.                    }             /* tell it we didn't process the message */
  293.                    return((MRESULT)TRUE);
  294.  
  295.                case IDD_DEFAULT:
  296.                    if (SHORT2FROMMP(mp1) == BN_CLICKED)
  297.                    {
  298.                     if ((WinSendDlgItemMsg(hwnd,IDD_DEFAULT,BM_QUERYCHECK,
  299.                           (MPARAM)0L,(MPARAM)0L) == (MRESULT)1L) ?
  300.                           TRUE : FALSE)
  301.                     {               /* Reset attributes to initial values */
  302.                      WinSendDlgItemMsg(hwnd, IDD_READ, BM_SETCHECK,
  303.                                             MPFROMLONG(1L),(MPARAM)0L);
  304.                      WinSendDlgItemMsg(hwnd, IDD_EXECUTE, BM_SETCHECK,
  305.                                             MPFROMLONG(1L),(MPARAM)0L);
  306.                      WinSendDlgItemMsg(hwnd, IDD_WRITE, BM_SETCHECK,
  307.                                             MPFROMLONG(1L),(MPARAM)0L);
  308.                      WinSendDlgItemMsg(hwnd, IDD_GUARD, BM_SETCHECK,
  309.                                             (MPARAM)0L,(MPARAM)0L);
  310.                     }
  311.                    }             /* tell it we didn't process the message */
  312.                    return((MRESULT)TRUE);
  313.  
  314.                case IDD_COMMIT:
  315.                    /* For these cases, put the attributes back the way
  316.                       they were, this is for whenthe user clicks on de-commit,
  317.                       then, clicks back on default or commit since we cleared
  318.                       the attribute flags when they clicked on decommit */
  319.  
  320.                    if (SHORT2FROMMP(mp1) == BN_CLICKED)
  321.                    {
  322.                       rc=DosQueryMem(pObj->pvAddress, &ulRegionSize, &ulFlags);
  323.                       if (rc)
  324.                       {
  325.                           VMM_Error("DosQueryMem()", rc);
  326.  
  327.                           WinDismissDlg(hwnd, FALSE);
  328.                           return((MRESULT)FALSE);
  329.                       }
  330.                      WinSendDlgItemMsg(hwnd, IDD_READ, BM_SETCHECK,
  331.                       MPFROMSHORT((ulFlags & PAG_READ) ? 1 : 0),(MPARAM)0L);
  332.                      WinSendDlgItemMsg(hwnd, IDD_EXECUTE, BM_SETCHECK,
  333.                       MPFROMSHORT((ulFlags & PAG_EXECUTE) ? 1 : 0),(MPARAM)0L);
  334.                      WinSendDlgItemMsg(hwnd, IDD_WRITE, BM_SETCHECK,
  335.                       MPFROMSHORT((ulFlags & PAG_WRITE) ? 1 : 0),(MPARAM)0L);
  336.                      WinSendDlgItemMsg(hwnd, IDD_GUARD, BM_SETCHECK,
  337.                       MPFROMSHORT((ulFlags & PAG_GUARD) ? 1 : 0),(MPARAM)0L);
  338.                    }
  339.                    return((MRESULT)TRUE);
  340.                                 /* tell it we didn't process the message */
  341.                default:
  342.                    return((MRESULT)TRUE);
  343.            }
  344.            break;
  345.  
  346.        case WM_COMMAND:
  347.            switch (SHORT1FROMMP(mp1)) {
  348.                case DID_OK:
  349.                    pObj->ulAttr =
  350.                  ( (WinSendDlgItemMsg(hwnd,IDD_READ,BM_QUERYCHECK,(MPARAM)0L,
  351.                     (MPARAM)0L) == (MRESULT) 1L) ? (ULONG)PAG_READ : 0L ) |
  352.                  ( (WinSendDlgItemMsg(hwnd,IDD_EXECUTE,BM_QUERYCHECK,(MPARAM)0L,
  353.                     (MPARAM)0L) == (MRESULT) 1L) ? (ULONG)PAG_EXECUTE : 0L ) |
  354.                  ( (WinSendDlgItemMsg(hwnd,IDD_WRITE,BM_QUERYCHECK,(MPARAM)0L,
  355.                     (MPARAM)0L) == (MRESULT) 1L) ? (ULONG)PAG_WRITE : 0L ) |
  356.                  ( (WinSendDlgItemMsg(hwnd,IDD_GUARD,BM_QUERYCHECK,(MPARAM)0L,
  357.                     (MPARAM)0L) == (MRESULT) 1L) ? (ULONG)PAG_GUARD : 0L ) |
  358.                  ( (WinSendDlgItemMsg(hwnd,IDD_COMMIT,BM_QUERYCHECK,(MPARAM)0L,
  359.                     (MPARAM)0L) == (MRESULT) 1L) ? (ULONG)PAG_COMMIT : 0L ) |
  360.                  ( (WinSendDlgItemMsg(hwnd,IDD_DECOMMIT,BM_QUERYCHECK,(MPARAM)0L,
  361.                     (MPARAM)0L) == (MRESULT) 1L) ? (ULONG)PAG_DECOMMIT : 0L );
  362.  
  363.                   if (((pObj->ulAttr & PAG_READ) == 0L)  /* Disable READ */
  364.                        && ((pObj->ulAttr & PAG_EXECUTE) != 0L))
  365.                   {
  366.                      MessageBox(hwnd, IDMSG_UNSETREADERROR, "Error !",
  367.                                   MB_OK | MB_INFORMATION, TRUE);
  368.                      pObj->ulAttr = pObj->ulAttr | PAG_READ;
  369.                   }
  370.                   if (((pObj->ulAttr & PAG_READ) == 0L)  /* Disable READ */
  371.                        && ((pObj->ulAttr & PAG_WRITE) != 0L))
  372.                   {
  373.                      MessageBox(hwnd, IDMSG_UNSETREADERROR2, "Error !",
  374.                                   MB_OK | MB_INFORMATION, TRUE);
  375.                      pObj->ulAttr = pObj->ulAttr | PAG_READ;
  376.                   }
  377.                 /**************************************************************
  378.                  *if ((pObj->ulAttr & PAG_EXECUTE) == 0L)  //Disable EXECUTE//*
  379.                  *{                                                           *
  380.                  *  NOTE :                                                    *
  381.                  *  When user disables the EXECUTE and call DosSetMem() to    *
  382.                  *  change attribute, this program doesn't return error       *
  383.                  *  and still attach the EXECUTE attribute on it.             *
  384.                  *  That is because there are a bug in Intel-80386 chip, it   *
  385.                  *  makes the DosSetMem() not work normally.                  *
  386.                  *}                                                           *
  387.                  **************************************************************/
  388.  
  389.                   WinDismissDlg(hwnd, TRUE);
  390.                   return((MRESULT)FALSE);
  391.                                    /* tell system we did process the message */
  392.  
  393.                case DID_CANCEL:
  394.                   WinDismissDlg(hwnd, FALSE);
  395.                   return((MRESULT)FALSE);
  396.                                 /* tell system we did process the message */
  397.                default:         /* tell it we didn't process the message */
  398.                   sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  399.                   return sRC;
  400.            }
  401.            break;
  402.  
  403.        case WM_CLOSE:
  404.           WinDismissDlg(hwnd, FALSE);
  405.           return((MRESULT)0L);
  406.  
  407.        default:
  408.            sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  409.            return sRC;
  410.        }
  411.    return((MRESULT)TRUE);
  412. }
  413.  
  414. /****************************************************************\
  415.  *  Dialog procedure for the Read Memory dialog                 *
  416.  *--------------------------------------------------------------*
  417.  *                                                              *
  418.  *  Name:    ReadMemDlgProc(hwnd, msg, mp1, mp2)                *
  419.  *                                                              *
  420.  *  Purpose: Processes all messages sent to the Read Memory     *
  421.  *            dialog                                            *
  422.  *                                                              *
  423.  *  Usage:   Called for each message sent to the dialog box.    *
  424.  *                                                              *
  425.  *  Method:  a switch statement branches to the routines to be  *
  426.  *           performed for each message processed.  Any messages*
  427.  *           not specifically processed are passed to the       *
  428.  *           default window procedure WinDefDlgProc()           *
  429.  *                                                              *
  430.  *  Returns: Dependent upon message sent                        *
  431.  *                                                              *
  432. \****************************************************************/
  433. MRESULT EXPENTRY ReadMemDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  434. {
  435.    static POBJSTRUCT pObj;
  436.    ULONG  ulIndexLow;
  437.    MRESULT sRC;
  438.  
  439.    switch (msg) {
  440.        case WM_INITDLG:
  441.            pObj = PVOIDFROMMP(mp2);
  442.            FixSysMenu(hwnd);
  443.  
  444.            return((MRESULT)FALSE);
  445.                            /* Let the focus go to where the system puts it */
  446.  
  447.        case WM_COMMAND:
  448.            switch (SHORT1FROMMP(mp1)) {
  449.                case DID_OK:
  450.                    WinQueryDlgItemText(hwnd, IDD_ADDRESS, MAX_EDIT_BUFF,
  451.                                            szBuffer);
  452.                    sscanf(szBuffer,"%p",&(pObj->pvAddress));
  453.  
  454.                    ulIndexLow = 0;
  455.                                             /* Look for the pointed page */
  456.                    while((apgentry[ulIndexLow].pvAddress != pObj->pvAddress)
  457.                                     && (ulIndexLow < ulFreePage))
  458.                        ulIndexLow++;
  459.                    if(ulIndexLow == ulFreePage)       /* Illeage address */
  460.                    {
  461.                       MessageBox(hwnd, IDMSG_ERRORADDRESS, "Error !",
  462.                                        MB_OK | MB_MOVEABLE, TRUE);
  463.                       return (MRESULT)0L;
  464.                    }
  465.  
  466.                    WinDismissDlg(hwnd, TRUE);
  467.                    return((MRESULT)TRUE);
  468.  
  469.                case DID_CANCEL:
  470.                    WinDismissDlg(hwnd, FALSE);
  471.                    return((MRESULT)TRUE);
  472.  
  473.                default:
  474.                    sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  475.                    return sRC;
  476.                }
  477.            break;
  478.  
  479.        case WM_CLOSE:
  480.           WinDismissDlg(hwnd, FALSE);
  481.           return((MRESULT)0L);
  482.  
  483.        default:
  484.            sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  485.            return sRC;
  486.        }
  487.    return (MRESULT)0L;
  488. }
  489.  
  490. /****************************************************************\
  491.  *  Dialog procedure for the Write Memory dialog                *
  492.  *--------------------------------------------------------------*
  493.  *                                                              *
  494.  *  Name:    WriteMemDlgProc(hwnd, msg, mp1, mp2)               *
  495.  *                                                              *
  496.  *  Purpose: Processes all messages sent to the WriteMem dialog.*
  497.  *                                                              *
  498.  *  Usage:   Called for each message sent to the dialog box.    *
  499.  *                                                              *
  500.  *  Method:  a switch statement branches to the routines to be  *
  501.  *           performed for each message processed.  Any messages*
  502.  *           not specifically processed are passed to the       *
  503.  *           default window procedure WinDefDlgProc()           *
  504.  *                                                              *
  505.  *  Returns: Dependent upon message sent                        *
  506.  *                                                              *
  507. \****************************************************************/
  508. MRESULT EXPENTRY WriteMemDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  509. {
  510.    PVOID   pvMemAddress=0;
  511.    ULONG   ulIndexLow;
  512.    MRESULT sRC;
  513.  
  514.    switch (msg) {
  515.        case WM_INITDLG:
  516.            FixSysMenu(hwnd);
  517.            return((MRESULT)FALSE);
  518.                        /* Let the the focus go to where the system puts it */
  519.        case WM_COMMAND:
  520.            switch (SHORT1FROMMP(mp1)) {
  521.                case DID_OK:
  522.                    WinQueryDlgItemText(hwnd, IDD_ADDRESS, MAX_EDIT_BUFF,
  523.                                            szBuffer);
  524.                    sscanf(szBuffer,"%p",&pvMemAddress);
  525.  
  526.                    ulIndexLow = 0;
  527.                                             /* Look for the pointed page */
  528.                    while((apgentry[ulIndexLow].pvAddress != pvMemAddress)
  529.                                     && (ulIndexLow < ulFreePage))
  530.                        ulIndexLow++;
  531.                    if(ulIndexLow == ulFreePage)       /* Illeage address */
  532.                    {
  533.                       MessageBox(hwnd, IDMSG_ERRORADDRESS, "Error !",
  534.                                        MB_OK | MB_MOVEABLE, TRUE);
  535.                       return (MRESULT)0L;
  536.                    }
  537.                    memset(szBuffer,0,sizeof(szBuffer) );
  538.                    WinQueryDlgItemText(hwnd, IDD_DATA, MAX_EDIT_BUFF, szBuffer);
  539.                    strcpy(pvMemAddress, szBuffer);  /* let 'em go for it.
  540.                                                  it may cause a GP fault */
  541.                    WinDismissDlg(hwnd, TRUE);
  542.                    return((MRESULT)TRUE);
  543.  
  544.                case DID_CANCEL:
  545.                    WinDismissDlg(hwnd, FALSE);
  546.                    return((MRESULT)TRUE);
  547.  
  548.                default:
  549.                    sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  550.                    return sRC;
  551.                }
  552.            break;
  553.  
  554.        case WM_CLOSE:
  555.           WinDismissDlg(hwnd, FALSE);
  556.           return((MRESULT)0L);
  557.  
  558.        default:
  559.            sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  560.            return sRC;
  561.        }
  562.    return (MRESULT)0L;
  563.  
  564. }
  565.  
  566. /****************************************************************\
  567.  *  Dialog procedure for the Free Memory dialog                 *
  568.  *--------------------------------------------------------------*
  569.  *                                                              *
  570.  *  Name:    FreeMemDlgProc(hwnd, msg, mp1, mp2)                *
  571.  *                                                              *
  572.  *  Purpose: Processes all messages sent to the FreeMem dialog  *
  573.  *                                                              *
  574.  *  Usage:   Called for each message sent to the Free Memory    *
  575.  *           dialog box.                                        *
  576.  *                                                              *
  577.  *  Method:  a switch statement branches to the routines to be  *
  578.  *           performed for each message processed.  Any messages*
  579.  *           not specifically processed are passed to the       *
  580.  *           default window procedure WinDefDlgProc()           *
  581.  *                                                              *
  582.  *  Returns: Dependent upon message sent                        *
  583.  *                                                              *
  584. \****************************************************************/
  585. MRESULT EXPENTRY FreeMemDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  586. {
  587.    static POBJSTRUCT pObj;
  588.    MRESULT sRC;
  589.    ULONG  ulIndexLow;
  590.  
  591.    switch (msg) {
  592.        case WM_INITDLG:
  593.            pObj = PVOIDFROMMP(mp2);
  594.            FixSysMenu(hwnd);
  595.            return((MRESULT)FALSE);
  596.                      /* Let the the focus go to where the system puts it */
  597.  
  598.        case WM_COMMAND:
  599.            switch (SHORT1FROMMP(mp1)) {
  600.                case DID_OK:
  601.                    WinQueryDlgItemText(hwnd, IDD_ADDRESS, MAX_EDIT_BUFF,
  602.                                               szBuffer);
  603.                    sscanf(szBuffer,"%p",&(pObj->pvAddress));
  604.  
  605.                    ulIndexLow = 0;
  606.                                             /* Look for the pointed page */
  607.                    while((apgentry[ulIndexLow].pvAddress != pObj->pvAddress)
  608.                                     && (ulIndexLow < ulFreePage))
  609.                        ulIndexLow++;
  610.                    if(ulIndexLow == ulFreePage)       /* Illeage address */
  611.                    {
  612.                       MessageBox(hwnd, IDMSG_ERRORADDRESS, "Error !",
  613.                                        MB_OK | MB_MOVEABLE, TRUE);
  614.                       return (MRESULT)0L;
  615.                    }
  616.                    WinDismissDlg(hwnd, TRUE);
  617.                    break;
  618.  
  619.                case DID_CANCEL:
  620.                    WinDismissDlg(hwnd, FALSE);
  621.                    break;
  622.                }
  623.            break;
  624.  
  625.        case WM_CLOSE:
  626.           WinDismissDlg(hwnd, FALSE);
  627.           return((MRESULT)0L);
  628.  
  629.        default:
  630.            sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  631.            return sRC;
  632.        }
  633.    return (MRESULT)0L;
  634. }
  635.