File:  [OS/2 SDKs] / os232sdk / toolkt20 / c / samples / vmm / vmm_dlg.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 12:26:30 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: os2sdk-1990, HEAD
Microsoft OS/2 SDK 2.0 05-30-1990

/*==============================================================*\
 *  Vmm_dlg.c - window procedures for the dialog boxes as well	*
 *		as utility procedures used by them		*
 *	Created 1990, Microsoft, IBM Corp.        	      		*
 *--------------------------------------------------------------*
 *								*
 *  This module contains the Dialog Procedures for the user	*
 *  defined dialogs as well as any support code they need	*
 *								*
 *--------------------------------------------------------------*
 *								*
 *  This source file contains the following functions:		*
 *								*
 *	     AboutBoxWndProc(hwnd, msg, mp1, mp2)		*
 *           AllocMemDlgProc(hwnd, msg, mp1, mp2)               *
 *           SetMem1DlgProc( hwnd, msg, mp1, mp2)               *
 *           SetMem2DlgProc( hwnd, msg, mp1, mp2)               *
 *           ReadMemDlgProc( hwnd, msg, mp1, mp2)               *
 *           WriteMemDlgProc(hwnd, msg, mp1, mp2)               *
 *           FreeMemDlgProc( hwnd, msg, mp1, mp2)               *
 *                                                              *
 *           CheckBox( hwnd, ulMask, idBox)                     *
 *           QueryCheckBox(hwnd, ulMask, idBox)                 *
 *                                                              *
\*==============================================================*/

/*--------------------------------------------------------------*\
 *  Include files, macros, defined constants, and externs	*
\*--------------------------------------------------------------*/

#define  LINT_ARGS

#define  INCL_WIN
#define  INCL_GPI
#define  INCL_DOSPROCESS
#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "vmm_main.h"
#include "vmm_dlg.h"
#include "vmm_xtrn.h"

#define MAX_EDIT_BUFF 10   /* length of string to query from edit controls */

#define SZDEFAULT_SIZE "1"  /* default number of bytes to set attributes for
                               when setting attributes of a block,
                               this will cause the attributes to be set for
                               one page */

extern CHAR szWindowText[];

/*--------------------------------------------------------------*\
 *  Global variables						*
\*--------------------------------------------------------------*/

extern char szBuffer[];

extern ULONG ulFreePage;              /* First free page entry in array */

extern PAGEENTRY apgentry[MAXPAGES];  /* Application page table         */


/*--------------------------------------------------------------*\
 *  Entry point declarations					*
\*--------------------------------------------------------------*/

MRESULT EXPENTRY AboutBoxWndProc(HWND hwnd, USHORT msg,
				  MPARAM mp1, MPARAM mp2);

VOID CheckBox(HWND hwnd, ULONG ulMask, USHORT idBox);
ULONG QueryCheckBox(HWND hwnd, ULONG ulMask, USHORT idBox);

extern VOID VMM_Error(PSZ pszFunction, ULONG ulErrorCode);

/****************************************************************\
 *  Routine to set the state of a checkbox                      *
 *--------------------------------------------------------------*
 *								*
 *  Name:   CheckBox(hwnd, ulMask, idBox)                       *
 *								*
 * Purpose:  Sets the state of a checkbox or radio button       *
 *                                                              *
 *  Usage:   If ulMask is true it checks the button, otherwise  *
 *           it unchecks the button.                            *
 *                                                              *
 *  Method:  Send a BM_SETCHECK message to the appropriate      *
 *           button                                             *
 *                                                              *
 *  Returns: None.                                              *
 *								*
\****************************************************************/


VOID CheckBox(HWND hwnd, ULONG ulMask, USHORT idBox)
{
    WinSendDlgItemMsg(hwnd,
                    idBox,
                    BM_SETCHECK,
                    MPFROMSHORT( ulMask ? 1 : 0),
                    0L);
}

/****************************************************************\
 *  Routine to query the state of a checkbox                    *
 *--------------------------------------------------------------*
 *								*
 *  Name:   QueryCheckBox(hwnd, ulMask, idBox)                  *
 *								*
 * Purpose: This routine makes querying the                     *
 *          state of a checkbox or radio button cleaner by      *
 *          hiding the details of sending the message to        *
 *          the button and checking the return value.           *
 *                                                              *
 *  Usage:                                                      *
 *								*
 *  Method:  Send a BM_QUERYCHECK to the control and checks     *
 *           the return value.                                  *
 *								*
 *  Returns: The value passed in ulMask if the button is        *
 *           checked                                            *
 *								*
\****************************************************************/


ULONG QueryCheckBox(HWND hwnd, ULONG ulMask, USHORT idBox)
{
    return( (WinSendDlgItemMsg(hwnd,
                                idBox,
                                BM_QUERYCHECK,
                                0L,
                                0L) == (MRESULT) 1L) ? ulMask : 0L);
}


/****************************************************************\
 *  Dialog procedure for the About dialog box			*
 *--------------------------------------------------------------*
 *								*
 *  Name:   AboutBoxWndProc(hwnd, msg, mp1, mp2)		*
 *								*
 *  Purpose: Processes all messages sent to the About Box	*
 *								*
 *  Usage:  Called for each message sent to the About Box	*
 *	    dialog box.
 *								*
 *  Method: the about box only has a button control so this	*
 *	    routine only processes WM_COMMAND messages.  Any	*
 *	    WM_COMMAND posted must have come from the Ok	*
 *	    button so we dismiss the dialog upon receiving it.	*
 *								*
 *  Returns: Dependent upon message sent			*
 *								*
\****************************************************************/

MRESULT EXPENTRY AboutBoxWndProc(hwnd, msg, mp1, mp2)
HWND hwnd;	/* handle of window */
USHORT msg;	/* id of message */
MPARAM mp1;	/* first message parameter */
MPARAM mp2;	/* second message parameter */
{
    switch(msg)  {
	case WM_COMMAND:
	    /* no matter what the command, close the dialog */
	    WinDismissDlg(hwnd, TRUE);
	    break;

	default:
	    return(WinDefDlgProc(hwnd, msg, mp1, mp2));
	    break;
    }

    return 0L;

}   /* AboutBoxWndProc() */


/****************************************************************\
 *  Dialog procedure for the Allocate Memory dialog             *
 *--------------------------------------------------------------*
 *								*
 *  Name:   AllocMemDlgProc(hwnd, msg, mp1, mp2)                *
 *								*
 *  Purpose: Processes all messages sent to the AllocMem        *
 *	      dialog						*
 *								*
 *  Usage:  Called for each message sent to the                 *
 *	    dialog box. 					*
 *								*
 *  Method: a switch statement branches to the routines to be	*
 *	    performed for each message processed.  Any messages *
 *	    not specifically processed are passed to the	*
 *	    default window procedure WinDefDlgProc()		*
 *								*
 *  Returns: Dependent upon message sent			*
 *								*
\****************************************************************/

MRESULT EXPENTRY AllocMemDlgProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
{
static POBJSTRUCT pObj;

switch (msg) {
    case WM_INITDLG:

        pObj = PVOIDFROMMP(mp2);

        ltoa( (pObj->ulSize) ,(char *) szBuffer, 10);  /* radix=10 */

        WinSetDlgItemText(hwnd, IDD_EDITSIZE, szBuffer);

        CheckBox(hwnd, pObj->ulAttr & PAG_READ, IDD_READ);
        CheckBox(hwnd, pObj->ulAttr & PAG_EXECUTE, IDD_EXECUTE);
        CheckBox(hwnd, pObj->ulAttr & PAG_WRITE, IDD_WRITE);
        CheckBox(hwnd, pObj->ulAttr & PAG_GUARD, IDD_GUARD);

        CheckBox(hwnd, pObj->ulAttr & PAG_COMMIT, IDD_COMMIT);
        CheckBox(hwnd, pObj->ulAttr & OBJ_TILE, IDD_TILE);

        return(FALSE); /* Let the focus go to where the system puts it */

        break;

    case WM_COMMAND:
        switch ((USHORT) SHORT1FROMMP(mp1)) {
            case IDD_OK:
                WinQueryDlgItemText(hwnd, IDD_EDITSIZE,MAX_EDIT_BUFF, szBuffer);

                pObj->ulSize=atol(szBuffer);

                pObj->ulAttr = QueryCheckBox(hwnd,PAG_READ, IDD_READ) |
                               QueryCheckBox(hwnd,PAG_EXECUTE, IDD_EXECUTE) |
                               QueryCheckBox(hwnd,PAG_WRITE, IDD_WRITE) |
                               QueryCheckBox(hwnd,PAG_GUARD, IDD_GUARD) |

                               QueryCheckBox(hwnd,PAG_COMMIT, IDD_COMMIT) |
			       QueryCheckBox(hwnd,OBJ_TILE, IDD_TILE);

                WinDismissDlg(hwnd, TRUE);

                break;

            case IDD_CANCEL:
                WinDismissDlg(hwnd, FALSE);
                break;
            default:
                break;
            }

        break;

    default:
        return (WinDefDlgProc(hwnd, msg, mp1, mp2));
    }
}



/****************************************************************\
 *  Dialog procedure for the Set Memory dialog                  *
 *--------------------------------------------------------------*
 *								*
 *  Name:   SetMem1DlgProc(hwnd, msg, mp1, mp2)                 *
 *								*
 *  Purpose: Processes all messages sent to the SetMem1         *
 *	      dialog						*
 *								*
 *  Usage:  Called for each message sent to the                 *
 *	    dialog box. 					*
 *								*
 *  Method: a switch statement branches to the routines to be	*
 *	    performed for each message processed.  Any messages *
 *	    not specifically processed are passed to the	*
 *	    default window procedure WinDefDlgProc()		*
 *								*
 *  Returns: Dependent upon message sent			*
 *								*
\****************************************************************/

MRESULT EXPENTRY SetMem1DlgProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
{
static POBJSTRUCT pObj;
USHORT i;

switch (msg) {
    case WM_INITDLG:
        pObj = PVOIDFROMMP(mp2); /* address of buffer pointed to by pCreateParams */

        for (i=0; i<ulFreePage; i++)
        {
            sprintf(szBuffer, "%p",apgentry[i].pvAddress);

            WinSendDlgItemMsg(hwnd,
                                IDD_ADDRESS,
                                LM_INSERTITEM,
                                MPFROMSHORT(LIT_END),
                                MPFROMP(szBuffer));
        }

        WinSetDlgItemText(hwnd, IDD_EDITSIZE, SZDEFAULT_SIZE);

        return(FALSE); /* Let the focus go to where the system puts it */
        break;

    case WM_COMMAND:
        switch ((USHORT) SHORT1FROMMP(mp1)) {
            case IDD_OK:
                WinQueryDlgItemText(hwnd, IDD_ADDRESS, MAX_EDIT_BUFF, szBuffer);

		sscanf(szBuffer,"%p",&(pObj->pvAddress));

                WinQueryDlgItemText(hwnd, IDD_EDITSIZE, MAX_EDIT_BUFF, szBuffer);

		sscanf(szBuffer,"%lu",&(pObj->ulSize));

                WinDismissDlg(hwnd, TRUE);

                break;

            case IDD_CANCEL:
                WinDismissDlg(hwnd, FALSE);
                break;

            default:
                break;
            }

        break;

    default:
        return (WinDefDlgProc(hwnd, msg, mp1, mp2));
    }
}



/****************************************************************\
 *  Dialog procedure for the Set Memory dialog                  *
 *--------------------------------------------------------------*
 *								*
 *  Name:   SetMem2DlgProc(hwnd, msg, mp1, mp2)                 *
 *								*
 *  Purpose: Processes all messages sent to the SetMem2         *
 *	      dialog						*
 *								*
 *  Usage:  Called for each message sent to the                 *
 *	    dialog box. 					*
 *								*
 *  Method: a switch statement branches to the routines to be	*
 *	    performed for each message processed.  Any messages *
 *	    not specifically processed are passed to the	*
 *	    default window procedure WinDefDlgProc()		*
 *								*
 *  Returns: Dependent upon message sent			*
 *								*
\****************************************************************/

MRESULT EXPENTRY SetMem2DlgProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
{
static POBJSTRUCT pObj;
ULONG ulRegionSize,ulFlags;
ULONG rc;

switch (msg) {
    case WM_INITDLG:
        pObj = PVOIDFROMMP(mp2);

        rc=DosQueryMem(pObj->pvAddress, &ulRegionSize, &ulFlags);
        if (rc)
        {
            VMM_Error("DosQueryMem()", rc);

            WinDismissDlg(hwnd, FALSE);
            return(FALSE);
        }

        sprintf(szBuffer, "Address of memory =0x%p",pObj->pvAddress);
        WinSetDlgItemText(hwnd, IDD_ADDRESS, szBuffer);


	CheckBox(hwnd, ulFlags & PAG_READ, IDD_READ);
	CheckBox(hwnd, ulFlags & PAG_EXECUTE, IDD_EXECUTE);
	CheckBox(hwnd, ulFlags & PAG_WRITE, IDD_WRITE);
	CheckBox(hwnd, ulFlags & PAG_GUARD, IDD_GUARD);

        CheckBox(hwnd, 1L, IDD_DEFAULT);

        return(FALSE); /* Let the focus go to where the system puts it */
        break;

    case WM_CONTROL:

        switch ((USHORT) SHORT1FROMMP(mp1)) {

            case IDD_DECOMMIT:    /* Can't change attributes when de-committing */
                if ((USHORT) SHORT2FROMMP(mp1) == BN_CLICKED)
                {
                    if (QueryCheckBox(hwnd, TRUE, IDD_DECOMMIT))
                        {
                            /* If we are decommitting memory, don't change
                               any attributes */
                            CheckBox(hwnd, 0L, IDD_READ);
                            CheckBox(hwnd, 0L, IDD_EXECUTE);
                            CheckBox(hwnd, 0L, IDD_WRITE);
                            CheckBox(hwnd, 0L, IDD_GUARD);
                        }

                    return(TRUE);   /* tell it we didn't process the message */
                }

                return(TRUE);       /* tell it we didn't process the message */

                break;


            case IDD_DEFAULT:
            case IDD_COMMIT:

                /* For these cases, put the attributes back the way
                   they were, this is for whenthe user clicks on de-commit,
                   then, clicks back on default or commit since we cleared
                   the attribute flags when they clicked on decommit */

                if ((USHORT) SHORT2FROMMP(mp1) == BN_CLICKED)
                {

                    rc=DosQueryMem(pObj->pvAddress, &ulRegionSize, &ulFlags);
                    if (rc)
                    {
                        VMM_Error("DosQueryMem()", rc);

                        WinDismissDlg(hwnd, FALSE);
                        return(FALSE);
                    }

                    CheckBox(hwnd, ulFlags & PAG_READ, IDD_READ);
                    CheckBox(hwnd, ulFlags & PAG_EXECUTE, IDD_EXECUTE);
                    CheckBox(hwnd, ulFlags & PAG_WRITE, IDD_WRITE);
                    CheckBox(hwnd, ulFlags & PAG_GUARD, IDD_GUARD);
                }

                return(TRUE);   /* tell it we didn't process the message */
                break;

            default:
                break;
            }

    case WM_COMMAND:
        switch ((USHORT) SHORT1FROMMP(mp1)) {
            case IDD_OK:

                pObj->ulAttr = QueryCheckBox(hwnd,PAG_READ, IDD_READ) |
                               QueryCheckBox(hwnd,PAG_EXECUTE, IDD_EXECUTE) |
                               QueryCheckBox(hwnd,PAG_WRITE, IDD_WRITE) |
                               QueryCheckBox(hwnd,PAG_GUARD, IDD_GUARD) |

                               QueryCheckBox(hwnd,PAG_COMMIT, IDD_COMMIT) |
                               QueryCheckBox(hwnd,PAG_DECOMMIT, IDD_DECOMMIT);

                WinDismissDlg(hwnd, TRUE);
                return(FALSE);   /* tell system we did process the message */
                break;

            case IDD_CANCEL:
                WinDismissDlg(hwnd, FALSE);
                return(FALSE);   /* tell system we did process the message */
                break;

            default:
                return(TRUE);   /* tell it we didn't process the message */
                break;
            }

        break;

    default:
        return (WinDefDlgProc(hwnd, msg, mp1, mp2));
    }
}


/****************************************************************\
 *  Dialog procedure for the Read Memory dialog                 *
 *--------------------------------------------------------------*
 *								*
 *  Name:   ReadMemDlgProc(hwnd, msg, mp1, mp2)                 *
 *								*
 *  Purpose: Processes all messages sent to the Read Memory     *
 *	      dialog						*
 *								*
 *  Usage:  Called for each message sent to the                 *
 *	    dialog box. 					*
 *								*
 *  Method: a switch statement branches to the routines to be	*
 *	    performed for each message processed.  Any messages *
 *	    not specifically processed are passed to the	*
 *	    default window procedure WinDefDlgProc()		*
 *								*
 *  Returns: Dependent upon message sent			*
 *								*
\****************************************************************/

MRESULT EXPENTRY ReadMemDlgProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
{
static POBJSTRUCT pObj;

switch (msg) {
    case WM_INITDLG:
        pObj = PVOIDFROMMP(mp2);

        return(FALSE); /* Let the focus go to where the system puts it */

        break;

    case WM_COMMAND:
        switch ((USHORT) SHORT1FROMMP(mp1)) {
            case IDD_OK:
                WinQueryDlgItemText(hwnd, IDD_ADDRESS, MAX_EDIT_BUFF, szBuffer);

		sscanf(szBuffer,"%p",&(pObj->pvAddress));

                WinDismissDlg(hwnd, TRUE);
                break;

            case IDD_CANCEL:
                WinDismissDlg(hwnd, FALSE);
                break;

            default:
                break;
            }

        break;

    default:
        return (WinDefDlgProc(hwnd, msg, mp1, mp2));
    }
}




/****************************************************************\
 *  Dialog procedure for the Write Memory dialog                *
 *--------------------------------------------------------------*
 *								*
 *  Name:   WriteMemDlgProc(hwnd, msg, mp1, mp2)                *
 *								*
 *  Purpose: Processes all messages sent to the WriteMem        *
 *	      dialog						*
 *								*
 *  Usage:  Called for each message sent to the                 *
 *	    dialog box. 					*
 *								*
 *  Method: a switch statement branches to the routines to be	*
 *	    performed for each message processed.  Any messages *
 *	    not specifically processed are passed to the	*
 *	    default window procedure WinDefDlgProc()		*
 *								*
 *  Returns: Dependent upon message sent			*
 *								*
\****************************************************************/

MRESULT EXPENTRY WriteMemDlgProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
{
PVOID	pvMemAddress;

switch (msg) {
    case WM_INITDLG:
        return(FALSE); /* Let the the focus go to where the system puts it */
        break;

    case WM_COMMAND:
        switch ((USHORT) SHORT1FROMMP(mp1)) {
            case IDD_OK:
                WinQueryDlgItemText(hwnd, IDD_ADDRESS, MAX_EDIT_BUFF, szBuffer);

                sscanf(szBuffer,"%p",&pvMemAddress);

                WinQueryDlgItemText(hwnd, IDD_DATA, MAX_EDIT_BUFF, szBuffer);

                strcpy(pvMemAddress, szBuffer);  /* let 'em go for it.
                                                    it may cause a GP fault */

                WinDismissDlg(hwnd, TRUE);

                break;

            case IDD_CANCEL:
                WinDismissDlg(hwnd, FALSE);
                break;

            default:
                break;
            }

        break;

    default:
        return (WinDefDlgProc(hwnd, msg, mp1, mp2));
    }
}


/****************************************************************\
 *  Dialog procedure for the Free Memory dialog 		*
 *--------------------------------------------------------------*
 *								*
 *  Name:   FreeMemDlgProc(hwnd, msg, mp1, mp2) 		*
 *								*
 *  Purpose: Processes all messages sent to the FreeMem 	*
 *	      dialog						*
 *								*
 *  Usage:  Called for each message sent to the Free Memory     *
 *	    dialog box. 					*
 *								*
 *  Method: a switch statement branches to the routines to be	*
 *	    performed for each message processed.  Any messages *
 *	    not specifically processed are passed to the	*
 *	    default window procedure WinDefDlgProc()		*
 *								*
 *  Returns: Dependent upon message sent			*
 *								*
\****************************************************************/
MRESULT EXPENTRY FreeMemDlgProc(HWND hwnd, USHORT msg,
                                    MPARAM mp1, MPARAM mp2)
{
static POBJSTRUCT pObj;

switch (msg) {
    case WM_INITDLG:
        pObj = PVOIDFROMMP(mp2);

        return(FALSE); /* Let the the focus go to where the system puts it */
        break;

    case WM_COMMAND:
        switch ((USHORT) SHORT1FROMMP(mp1)) {
            case IDD_OK:
                WinQueryDlgItemText(hwnd, IDD_ADDRESS, MAX_EDIT_BUFF, szBuffer);

		sscanf(szBuffer,"%p",&(pObj->pvAddress));

                WinDismissDlg(hwnd, TRUE);

                break;

            case IDD_CANCEL:
                WinDismissDlg(hwnd, FALSE);
                break;

            default:
                break;
            }

        break;

    default:
        return (WinDefDlgProc(hwnd, msg, mp1, mp2));
    }
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.